103

When I issue the following:

sudo shutdown now

..my newly commissioned Ubuntu 14.04 server doesn't shut down. It stops with the following message:

* Stopping System V runlevel compatibility
Give root password for maintenance:
(or type Control-D to continue):

If I type in the root password, the machine simply sits there at the shell prompt.

mklement0
  • 257
  • 2
  • 7
Jon Cage
  • 1,133
  • 2
  • 8
  • 7

5 Answers5

159

Traditionally, the command sudo shutdown now will take you to the runlevel 1 (recovery mode); this will happen for both Upstart and SysV init. To get what you want, i.e., to shut down the computer properly, you need to give the -h switch to shutdown.

One thing to note here is that halt will close all the processes, turn off the CPUs and return the control to a ROM monitor of the mainboard needing the user to press the power button to get the power supply turned off, whereas poweroff after turning off the CPUs will simply turn off the power supply resulting in a proper shutdown.

The -h switch of shutdown will either halt or poweroff the computer, the decision will be taken by the system although in Ubuntu I have seen that it would normally poweroff the machine. To be sure of that, you can use the -P switch with shutdown to poweroff the computer.

To summarize, here are the commands available to poweroff (not halt) a computer:

sudo shutdown -h now
sudo shutdown -P now
sudo poweroff
sudo halt -p
sudo init 0

The poweroff and halt commands basically invoke shutdown (except for the poweroff -f). sudo poweroff and sudo halt -p are exactly like sudo shutdown -P now. The command sudo init 0 will take you to the runlevel 0 (shutdown).

Now what if you want to shut down forcefully, i.e., you don't want to wait for processes to close normally? In that case you can use:

sudo poweroff -f

This will not use shutdown. Rather, it will invoke the reboot(2) system call (used for reboot, poweroff & halt) to power off the computer instantly.

mklement0
  • 257
  • 2
  • 7
heemayl
  • 91,753
  • 3
    Or, combine shutdown 'now' with 'poweroff': sudo shutdown -P now – david6 Jan 27 '15 at 00:06
  • 3
    What do you mean by "shutdown forcefully"? According to a man page, -f option just skips fsck on reboot. And according to Ubuntu's man page, there's no such option at all. – Ruslan Jan 27 '15 at 04:55
  • 1
    @Ruslan: Perhaps confusing it with halt -f / poweroff -f, which bypasses init and tells the kernel directly to cut power. That is forceful. – user1686 Jan 27 '15 at 07:37
  • @Ruslan: I have modified my answer. – heemayl Jan 27 '15 at 13:15
  • 1
    My laptop thanks you! I was actually hung up on this one and just always using the power button, but now I know! The halt was keeping my system powered on, but the poweroff actually powers it off. Many thanks! :-) – Terrance Jun 13 '15 at 03:42
  • @Terrance Glad i could help :) – heemayl Jun 13 '15 at 22:45
  • @Terrance What happen if I always shutdown the pc with this command ? – Nullpointer Dec 27 '16 at 05:32
  • 1
    @RGG I would recommend that you run sync before this command, as this command bypasses anything that might still be in cache. sync will force cached writes to the disk, then you can power it off. – Terrance Dec 27 '16 at 05:39
  • @Terrance Technically, that's buffer, not cache. – heemayl Dec 27 '16 at 05:41
  • @Terrance my ubuntu machine not shutdown many times, Can i use sync and sudo shutdown -h now on rc0.d/K01script ?, Is this method is harmful ? – Nullpointer Dec 27 '16 at 05:46
  • @RGG The command sudo poweroff -f bypasses all shutdown procedures and can be dangerous to data. – Terrance Dec 27 '16 at 05:50
  • 1
    @RGG sync flushes the FS buffers, so that all the buffered data are written to the FS (disk in turn). – heemayl Dec 27 '16 at 05:50
  • @Terrance ok it is dangerous but none of solution works for multiple machine ! really I've bed exp. with ubuntu :( – Nullpointer Dec 27 '16 at 05:54
  • @RGG This isn't even my answer. I just commented on it. This is heemayl's answer. It helped out a laptop I was having problems with. – Terrance Dec 27 '16 at 05:57
  • @Terrance Is there alternative or unique solution ? – Nullpointer Dec 27 '16 at 06:05
  • 1
    @RGG This is getting out of hand. Please ask this as a new question. – heemayl Dec 27 '16 at 06:06
18

I'm pretty sure the correct command needs to contain the "-h" option (halt). Try this:

sudo shutdown -h now
pille1842
  • 536
  • 2
  • 8
6

It's a legacy from the days when the physical machine couldn't power off by itself. For example, the halt command sudo halt terminates all programs and unloads almost everything from RAM, ready to be powered off. However, if you run sudo halt -p, it will do all that, then signal the system to power off, or in the case of the shutdown command, you need the -a option, I believe, though I personally use halt.

Jens Erat
  • 5,051
  • 7
  • 31
  • 37
John Cave
  • 221
  • 1
  • 3
4
systemctl poweroff -i 

use this for all linux.

swon
  • 41
1

I've always used the following

sudo shutdown -a now

or to reboot immediately after shutdown

sudo shutdown -r now

Looking at the shutdown help option it doesn't list -a as a proper command, but I could have sworn a long time ago -a was abort or something like that. Anyways I've kept using that and it it has worked all these years, but it looks like shutdown -h now is the correct option.

NPIC
  • 119
  • 1
  • 7
  • 2
    Maybe you're thinking of the Windows command shutdown /a, which aborts a shutdown (equivalent to shutdown -c in Ubuntu). – deltab Jan 27 '15 at 05:23
  • @deltab Yeah that must be what I'm thinking of then. Strange that shutdown -a works for me though. – NPIC Jan 27 '15 at 23:51