Human Readable  

 

     
   
     

Adding a Shutdown Command to inittab

© Copyright Darrell Anderson.

The K Desktop Environment (KDE) login manager (KDM — K Display Manager) provides the means to shutdown a computer. The command line provides no such direct mechanism unless a user is logged in as root or has been provided shutdown abilities through sudo. With most standard GNU/Linux distros, from the command line a user can reboot a computer but cannot shutdown or power down the computer. There is a way to remedy this shortcoming. The solution is to add a keyboard sequence that will perform the shutdown or halt command.

In most if not all GNU/Linux distros, the standard keyboard sequence to reboot a box is Ctrl-Alt-Del. Of course, in critical situations where rebooting is not desired, such as with a dedicated server, this keyboard sequence is disabled. Bear in mind then that the following solution is not recommended for such environments. In this mini How-To we will add the Ctrl-Alt-End keyboard sequence as the means to shutdown a computer from the command line.

Let us first modify the /etc/inittab configuration file to recognize a keyboard shutdown request. Within that file most users should find a line looking something like this:

# "Three Finger Salute" for reboot
ca::ctrlaltdel:/sbin/shutdown -t1 -r now

Just below that line modify the file by adding the following:

# "Three Finger Salute" for poweroff (ctrl-alt-end)
ce::kbrequest:/sbin/shutdown -t1 -h now

As far as I know the two-letter symbol used at the beginning of the line can be anything as long as the symbol is unique within the inittab file. The next portion of the line must be typed exactly as shown. The time delay represented by -t1 (1 second delay) may be modified to suit personal tastes.

The next step is to modify your keyboard layout map.

  1. Look in /etc/rc.d to see if you have an rc.keymap script. If not, then you are using the Slackware default qwerty us.map keymap.
  2. If you have an rc.keymap script, then open the file to discover the keymap you are using.
  3. Now find your way to the /usr/share/kbd/keymaps/i386/qwerty directory.
  4. Find the keymap file you are using. All keymap files are compressed gzip files. If you are using the default keymap then the file name is us.map.gz.
  5. From the compressed gzip file, extract the keymap file to a temporary directory.
  6. Rename the extracted file to something such as us-with-sd.map.
  7. Open the renamed file with a text editor.
  8. At or near the end of the file add the following text: keycode 97 = Control
    control alt keycode 107 = KeyboardSignal
  9. The keycode 107 represents the End key.
  10. Save and exit the file.
  11. Create a new compressed gzip file and ensure you name the gzip file the same as you named the new keymap file. For example, us-with-sd.map.gz.
  12. Move the new gzip file to the /usr/share/kbd/keymaps/i386/qwerty directory.
  13. Standard file permissions for the gzip file are chmod 644.
  14. If you do not have an rc.keymap file, then open a text editor to create one or simply copy the one included with this How-To and edit as necessary for your new keymap.

You must reboot your computer or reinitialize the init command to read the new inittab file. To perform the latter without rebooting, at the command line type init q.

You now can run the rc.keymap script manually and the keyboard shutdown request should work the same as the keyboard reboot request. Whether or not logged in at the console, press Ctrl-Alt-End and the computer will shutdown. If you have power management abilities then the box will power off as well.

If you use the files included in this How-To, bear in mind the files include modifications to map the Right Alt key to function the same as the Left Alt key when in console mode. If you do not want those modifications then edit your keymap files on your own box accordingly.

us-two-alt.map

/usr/share/kbd/keymaps/i386/qwerty/us-two-alt.map.gz

/etc/rc.d/rc.keymap

/etc/shell-colors

Finis.

Table of Contents