LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Keyboard Power Button to shutdown my computer (http://www.linuxquestions.org/questions/linux-software-2/keyboard-power-button-to-shutdown-my-computer-738578/)

stringZ 07-08-2009 07:42 AM

Keyboard Power Button to shutdown my computer
 
Dear Linuxofrum users!

I have a Genius K627 Keyboard with Power, Sleep and Wake buttons. ACPI is unsupported on my computer, but it can turn off its power supply when the system halts (PM is ok). I would like to bind the Power key on the keyboard to execute the /sbin/halt command. What I already know is that I can specify an event in inittab (kbrequest) that would execute a command. What I don't know how I can make my system receive pressing Power button as a kbrequest. The scancodes of Power button on the keyboard (by showkey): 0x74 0xf4

This is the line I was talking about in my inittab:
Code:

ce:12345:kbrequest:/sbin/halt
I think I should edit /etc/console/boottime.kmap.gz but don't know how I could insert this scancode into it.

Anyone who could help me?

Thanks in advance
stringZ

stress_junkie 07-08-2009 08:29 AM

First, I recommend that you bind the key(s) to the proper shutdown command, /sbin/shutdown, rather than /sbin/halt. The halt command is the software equivalent of pulling the power cord out of your computer. It could eventually lead to data corruption including corruption of the partition tables On the disk.

alan_ri 07-08-2009 09:30 AM

You didn't say what's your distro,but wherever you have to look for the file to edit and it could be for example in;

/etc/kbd/default.map.gz or in /etc/console-tools

try to add these lines;

Code:

keycode 74 = Shutdown
keycode 74 = KeyboardSignal

and in /etc/inittab:
Code:


kb:12345:kbrequest:/sbin/shutdown -t1 -h now


stringZ 08-01-2009 04:28 AM

Quote:

Originally Posted by alan_ri (Post 3600924)
You didn't say what's your distro,but wherever you have to look for the file to edit and it could be for example in;

I have Debian Sarge.

Quote:

Originally Posted by alan_ri (Post 3600924)

/etc/kbd/default.map.gz or in /etc/console-tools

try to add these lines;

Code:

keycode 74 = Shutdown
keycode 74 = KeyboardSignal


Tried this one, but had to replace 74 to 116, because 74(hex) = 116(dec) and boottime.kmap.gz stores keycodes decimally. I didn't even need keycode 74 = Shutdown. Anyway, I have successfully bound the power key to the shutdown command (using keycode 116 = Shutdown and the inittab line). Thanks for your help, alan_ri!

By the way, I found some lines that were already referred to keycode 116, I commented them:
Code:

#keycode 116 = Do
#      altgr  control keycode 116 = VoidSymbol
#      altgr  alt    keycode 116 = VoidSymbol

What is this?

alan_ri 08-03-2009 05:45 AM

Well, void means zero, nada, so that means that that key wasn't set, just like by default it isn't in Linux.

jdkaye 08-03-2009 05:50 AM

Quote:

Originally Posted by stringZ (Post 3627419)
I have Debian Sarge.

Any reason why you're still running Sarge? It's a bit long in the tooth now.
jdk

stringZ 10-11-2009 12:12 PM

Quote:

Originally Posted by jdkaye (Post 3629340)
Any reason why you're still running Sarge? It's a bit long in the tooth now.
jdk

You're damn right, but nowadays linux (all of them not just debian) works by a principle: the newer distro the slower code. I tried etch and sid on my Pentium I 233MHz but they were slower, moreover Sarge is slightly slower than its ancestor, Woody. I don't know why this kind of era is good. I'm supposing some background-agreement with hardware-manufacturers. They bring a huge support to Linux, but developers (including kernel developers) must write inefficient code to make system administrators keep buying new hardware devices over and over again even if they don't need them. I don't need more than my Pentium I server is capable of: watching streaming TV (mplayer), ftp server, bittorrent, samba, listening to radio and music from the disk, router etc.

Regards
stringZ

Shadow_7 10-12-2009 10:49 AM

It's called layering. mknod replaced by udev, supplimented by dbus, yadda yadda yadda. You can turn off most of those layers and still have a functional system though. i.e. mknod still works just fine. (as long as udev is put to bed). If your ps output is longer than 24 lines, you've got too much running IMO.

And yet you're asking about a layer to hotkey a shutdown. If you're system was acpi, you could rig up some acpi events. Those might still work on an APM system(ancient). I've got one setup on my laptop to power down when the red button is pushed. Some of my desktops have the same. X locks up, well that power button still triggers a proper shutdown. i.e. no fsck at reboot. Which on a 1TB allocation takes a while.

Basically you might be able to run acpid, and setup some scripts in /etc/acpi/ even though your system doesn't have acpi. apt-get install acpid (powerbtn.sh comes with it on my system) It might require some customization to use the keyboard power button in addition to (or instead of) the computers power button. But the basic functionality is already in place.

stringZ 10-16-2009 06:23 AM

Quote:

Originally Posted by Shadow_7 (Post 3716486)
It's called layering. mknod replaced by udev, supplimented by dbus, yadda yadda yadda.

I'm talking about the binaries getting slower and slower, not just the layers. Unfortunately my motherboard doesn't support ACPI at all, already tried acpid for the purpose, no success. But acpid is also a process and uses memory, but this way there's no daemon, only the halt command runs when I press the power off button on the keyboard.


All times are GMT -5. The time now is 07:21 PM.