I'm using the Apple slim aluminum keyboard, which doesn't have the SysRq key:
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
This answer also posted here.
After 3 or 4 hrs of hard searching, reading, and trial and error, here's a more thorough and generic answer which should work for any Apple/Mac laptop or keyboard, not just the "Apple slim aluminum keyboard." In my particular case, however, I'm using this solution for a 2008 MacBook white running Xubuntu 16.04 LTS.
Many thanks to Bengt Olsson for his excellent instructions here which gave me the necessary start to figure out the missing details.
This solution is done in the user space, and does NOT require recompiling the kernel like some suggestions.
Download source for keyfuzz, and extract it (I can right-click it and go to "Extract Here" to extract it in my GUI file manager, for instance). To read more about keyfuzz, see here. It is released under the GNU GPL 2.0 or later open source license (yaaay open source!).
./configurecommand below will fail.
Install dependencies, or else running
./configure below may spit out some errors:
sudo apt-get update sudo apt-get install lynx xmltoman gengetopt
Compile and install keyfuzz with the usual commands:
./configure make sudo make install
/dev/input/by-id and find your Apple keyboard that ends in
cd /dev/input/by-id ls
For me it's
Add the following line to your
/etc/rc.local file, to cause this command to run each time your computer boots up and loads this user. Notice we are using the Apple keyboard entry we just found above. This command uses keyfuzz to map F12 or F13 on your Apple keyboard or laptop to the system "Magic SysRq key", for soft reboots.
458821 99. Many thanks to "pjjjv" for figuring that out here!
Since my MacBook 2008 does not have F13, I am using the F12 option above. Also remember to use your proper keyboard entry we found above. The command I added to
rc.local for my case is:
echo "458821 99" | keyfuzz -s -d /dev/input/by-id/usb-Apple_Computer_Apple_Internal_Keyboard___Trackpad-event-kbd
Here is my entire
/etc/rc.local file, with the appropriate entry:
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. echo "458821 99" | keyfuzz -s -d /dev/input/by-id/usb-Apple_Computer_Apple_Internal_Keyboard___Trackpad-event-kbd exit 0
Now I can press Alt+F12 (or you can use Alt+F13 as described above) and issue REISUB to soft-reboot your computer. Works perfectly on my MacBook 2008 laptop running Xubuntu 16.04 LTS.
Note that you can see the results returned by issuing REISUB as you press each key by first jumping to an alternate session with Ctrl+Alt+F1 (F1 through F6 work actually) before issuing the command. To get back to your main X Window session use Ctrl+Alt+F7.
If you get a result that says
This sysrq operation is disabled
that's normal for several of the commands, as they pose a potential security risk. The Boot one should still work, however, allowing you to soft-reboot your computer. Here is some more information on this, from mniess here:
Starting with Ubuntu 12.10 a more fine-grained control of which Magic- SysRq features are enabled is possible. Just edit the file /etc/sysctl.d/10-magic-sysrq.conf.
The file is well documented and tells you exactly how to enable which features. The current default was picked for security purposes and should only be changed if you know why you need to (for security implications see bug #194676).
What a pain in the butt. :) Cheers.
Just did this. If you don't want to recompile the kernel like suggested in the first link of the first answer, there is a simpler way. It's kind of outlined in the second link of the first answer, but here is the actual procedure:
Compile and install with the usual commands
./configure make sudo make install
Add the following line to your /etc/rc.local file:
echo "458856 99" | sudo /usr/local/sbin/keyfuzz -s -d /dev/input/by-id/usb-Apple__Inc_Apple_Keyboard-event-kbd
Now it should be possible to press Alt+F13 and issue REISUB. Worked on my Xubuntu 15.10.