I have a Lenovo G570 laptop with a little key called onekey recovery next to the power button, and since coming to Linux it has became useless.
Is there a way to make this key into a reset button for example? Or to add an entry in Grub to make it load recovery options?
I've seen similar posts in here but I don't have windows or a dual boot, my disk is a single disk partition with Ubuntu Gnome installed, I don't even have SWAP space.
I do not have an idea how to use this button with GRUB, but there are at least two approaches how to make it usable within Ubuntu. For example if you want to bind the reboot command to that button you could: (1) create acpi event or (2) create custom shortcut.
Create
acpi event
and bind the reboot command to itFirst you need to use
acpi_listen
and catch the event when the button is pressed. Just execute the commandacpi_listen
and press the button:button/prog1 PROG1 00000080 00000000 K
is the event on my system when I press the discussed button.Then you should crate a file that will handle this event. The file must be located in the directory
/etc/acpi/events/
. Call it for examplereboot
. The content of/etc/acpi/events/reboot
should be similar as:Save the file and restart the acpi daemon:
IMO this is the most simple method. This should work also when the user is not logged in. Here are few references where you can find additional information and examples:
Create
acpi event
and bind a script to itWe can add an insurance in case you press the button accidentally. Here we will create a script that will use a
tmp
file as flag and counter as it is described here. Thus the system reboot will be performed when you press the button three times.Modify
/etc/acpi/events/reboot
in this way:Restart the acpi daemon:
Create the script
/etc/acpi/reboot.sh
and put the following lines as its content:Make it executable:
Now the
systemctl reboot
command will be performed when you press the button three times, within 30 secconds.Create
custom shortcut
and bind a script to itCrate a script
/usr/local/bin/my_rbt
(it could be named and located whenever you want) and make it executable. Here is a single command line that does that:The problem is (within this approach) we must use
sudo
to execute the script and should allow the users to do that without password - here are provided more details about this step: How do I run specific sudo commands without a password? So we must crate a file located in/etc/sudoers.d/
, called for examplemy_rbt
. For this purposes we should use the commandvisudo -f
:The content of the file should be:
Go to System Settings → Keyboard → Shortcuts (tab) → Custom Shortcuts (section) → Add new +.
In the Custom shortcut window type:
Name:
reboot
sudo /usr/local/bin/my_rbt
Click on
Disabled
in the right column and press the discussed button.That's it.
It appears that for Lenovo laptops (at least my G575) the OneKey Recovery key is another key.
Using the
xev
command, you can find out the scancode.xev
will open a window with a black square, move your mouse inside it and then press the OKR key.You can see the keycode as
keycode
156
.After finding the keycode, all you need to look up is how to map a keycode to a specific action. Here's some helpful questions: