M1-M5 are in fact regular keys - they just need to be specifically enabled before pressing them will generate a scancode. tux_mark_5 developed a small Haskell program which sends the correct SET_REPORT message to Razer keyboards to enable these keys, and ex-parrot ported the same code to Python.
On Arch Linux systems the Python port has been packaged and is available from https://aur.archlinux.org/packages.php?ID=60518.
On Debian or Ubuntu systems setting up the Python port of the code is relatively easy. You need to install PyUSB and libusb (as root):
aptitude install python-usb
Then grab the blackwidow_enable.py
file from http://finch.am/projects/blackwidow/ and execute it (also as root):
chmod +x blackwidow_enable.py
./blackwidow_enable.py
This will enable the keys until the keyboard is unplugged or the machine is rebooted. To make this permanent call the script from whatever style of startup script you most prefer. For instructions on how to set this up in Debian have a look at the Debian documentation.
To use tux_mark_5's Haskell code you'll need to install Haskell and compile the code yourself. These instructions are for a Debian-like system (including Ubuntu).
Install GHC, libusb-1.0-0-dev and cabal (as root):
aptitude install ghc libusb-1.0-0-dev cabal-install git pkg-config
Fetch the list of packages:
cabal update
Install USB bindings for Haskell (no need for root):
cabal install usb
Download the utility:
git clone git://github.com/tuxmark5/EnableRazer.git
Build the utility:
cabal configure
cabal build
Run the utility (also as root):
./dist/build/EnableRazer/EnableRazer
After this you can copy EnableRazer binary anywhere you want and run it at startup.
Immediately after execution, X server should see M1 as XF86Tools, M2 as XF86Launch5, M3 as XF86Launch6, M4 as XF86Launch7 and M5 as XF86Launch8. Events for FN are emitted as well.
These keys can be bound within xbindkeys or KDE's system settings to arbitrary actions.
Since your keyboard might be different, you might need to change the product ID in Main.hs line 64:
withDevice 0x1532 0x<HERE GOES YOUR KEYBOARD's PRODUCT ID> $ \dev -> do
Best Answer
Fn is not a normal keyboard key, such as the modifiers Ctrl, Shift and AltGr. For a standard modifier key, the microcontroller inside the keyboard sends a scancode for the modifier itself, which is then interpreted by the operating system and combined with other simultaneous key-presses. The Fn key is a form of meta-modifier key, in that it causes the operating system to see altered scancodes when other keys on the keyboard are pressed. This allows the keyboard to directly emulate a full-sized keyboard, so the operating system can use standard keymaps designed for a full-sized keyboard. However, because the operating system has no notion of the Fn key, the key can not normally be remapped in software, unlike all other standard keyboard keys.
While it is most common for the Fn key processing to happen directly in the keyboard micro-controller, offering no knowledge to the main computer of whether the Fn key was pressed, at least one manufacturer, Lenovo, performs this mapping in BIOS running on the main CPU. This allows remapping the Fn key by modifying the BIOS interrupt handler.
Source: http://en.wikipedia.org/wiki/Fn_key#Technical_details
Answer to the question: Remapping not possible via operating system but only via BIOS (in some cases).