Shutting down your Debian machine cleanly

Posted by Steve on Fri 11 Feb 2005 at 13:33

Rather than simply removing power from your Debian machine you should shut it down cleanly, this means that the filesystem will not get confused or messed up and all your files will be intact.

There are several ways to shut down your Debian machine cleanly, with the most simple probably being from the GUI environment you are using (if you have one).

For the GNOME desktop enviornment there is the option to shutdown the machine which is immediately available when you click "Logout". Choosing this should log you out of the desktop and also shut the machine down.

From the console, either a remote SSH session or from in front of the machine you also have access to the following commands:

shutdown
poweroff

The second command will take no arguments and immediately begin shutting down the machine, simply run as root :

poweroff

If your machine supports "poweroff" then it will be shutdown and the power turned off, this usually requires that you've setup power management - this can be as simple as running:

modprobe apm

or it might be more complex.

The shutdown command is more configurable, it allows you to specify whether you wish to reboot or shutdown, and will also allow you to schedule the action for later. Generally the usage is:

shutdown -r now

Here "-r" means to reboot, and "now" is the time to carry that activity out. If you wished to shutdown your machine at 8pm you could instead run:

shutdown 20:00

This will pause until 8pm and then shutdown - pressing Ctrl + C will cancel the shutdown, as will running another copy of shutdown with the "cancel" flag:

shutdown -c

Debian machines are typically setup so that if you press the three-fingered-salute "Ctrl + Alt + Delete" they will reboot. This is specified by the following line in the file "/etc/inittab".

# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

This command can be changed to anything else you desire such as:

# Poweroff on Ctrl + Alt + Del
ca:12345:ctrlaltdel:/sbin/poweroff
# Ignore it completley
ca:12345:ctrlaltdel:/bin/echo "Three Finger Salute Ignored"

 

 


Posted by Serge (194.78.xx.xx) on Fri 11 Feb 2005 at 14:26
[ View Serge's Scratchpad | View Weblogs ]
How do you know that
shutdown 8:00

happens at 8pm and not 8am?
I guess it depends what's the closes in the future.

--

Serge van Ginderachter

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Fri 11 Feb 2005 at 14:29
[ View Steve's Scratchpad | View Weblogs ]

D'oh - that would be 8AM as you noted.

I've updated the text to use 20:00 instead.

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by chris (217.8.xx.xx) on Fri 11 Feb 2005 at 14:45
[ View Weblogs ]
This is friday's really really picky comment ;-)

Don't you mean

all your files will be intact.

I can't believe I really made the effort to post this :-)

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Fri 11 Feb 2005 at 14:47
[ View Steve's Scratchpad | View Weblogs ]

If that is the pickiest comment I get today I'll be happy! I will update the text with your correction, thanks.

Sometimes I think that I shouldn't write at all .. it is so difficult!

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by chris (217.8.xx.xx) on Fri 11 Feb 2005 at 14:48
[ View Weblogs ]
I wouldn't worry - I'm not sure it's possible to be pickier

[ Parent | Reply to this comment ]

Posted by gna (212.40.xx.xx) on Fri 11 Feb 2005 at 16:06
[ View Weblogs ]
I have on my Sarge XFCE...
Actually i lost my dialog for shutting down, so i use

"gksudo halt" in a shortcut or terminal

quick and it seems clean :)

cheers

[ Parent | Reply to this comment ]

Posted by Anonymous (203.122.xx.xx) on Thu 12 May 2005 at 09:13
Actually i lost my dialog for shutting down, so i use "gksudo halt" in a shortcut or terminal

Roll your own dialog:

  1. apt-get install xdialog
  2. Then add this poweroff script to the menu:
    #!/bin/sh
    DIALOG=Xdialog
    
    $DIALOG --title "Power Off" --default-no --yesno "power off?" 0 0
    
    case $? in
      0)
        sudo /sbin/shutdown -h now;;
      1)
        ;;
      255)
        say "staying up";;
    #handles the click on the x in the corner widget case
    esac
    

    OK, the say "staying up" (say is from rsynth - the small text to speech utility) is a bit excessively geeky.

[ Parent | Reply to this comment ]

Posted by sbaturzio (82.105.xx.xx) on Fri 11 Feb 2005 at 22:35
If ACPI is present, you can use the power button to shutdown cleanly the server using the acpid.

Just add the ACPI module 'button' to your kernel and install the 'acpid' package. The acpid daemon listen for ACPI events and check the events with the description in /etc/acpi/events/* files.

Pressing the button now will execute:
# /sbin/shutdown -h now
command.

Very useful for small server managed from customers. ;-)
Un Ciao in DO Maggiore -=) Sbaturzio (=-

[ Parent | Reply to this comment ]

Posted by Anonymous (88.74.xx.xx) on Wed 1 Jun 2011 at 14:14
Thanks for that exact mini-howto!
It seems to be up-to-date right now (6 years later).

[ Parent | Reply to this comment ]

Posted by Anonymous (192.88.xx.xx) on Mon 14 Feb 2005 at 18:41
I've used the three-finger salute method to shutdown my Debian machines for years (~7) now - one of the first things I do after a fresh install is change the "-r" in the shutdown line in /etc/inittab to a "-h".

I find myself often in an environment where I want anyone with physical access to be able to shut down the machine, possibly to then restart it in a different operating system. The three-finger salute works well for this purpose. Also, on my home machine it's easy to shut the machine down as I'm on the way out the door with a simple Ctrl-Alt-F1 Ctrl-Alt-Del. Much faster (since my keyboard is such that both combinations require only one hand) than unlocking the screen and finding the appropriate shut-down icon with the mouse.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Mon 14 Feb 2005 at 19:10
[ View Steve's Scratchpad | View Weblogs ]

Actually one of the first things I do is remove that line completely - because I have a bunch of machines all hooked up to a KVMs, some are Debian, some are SCO, and some are Windows.

Whenever there is a mixture of Windows machines and Debian machines on the same KVM you can cause real problems by pressing Ctrl+Alt+Del when the keyboard is connnected to a different machine than you expect!

Its a lesson that I only want to learn once..

Steve
-- Steve.org.uk

[ Parent | Reply to this comment ]

Posted by Anonymous (202.180.xx.xx) on Mon 6 Mar 2006 at 10:13
I was somewhat disappointed by the modprobe apm or it might be more complicated... how does that help those who have figured out we fit into the "more complicated" category???

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 468 votes ~ 5 comments )