How do I restart Linux (Ubuntu) from the command-line?

50

6

Because of my problem with mouse-clicks being ignored in Ubuntu, I want to restart from the command-line. (I have an open Terminal, and the keyboard is not ignored.)

How do I restart a computer running Linux (or more specifically Ubuntu) from the command-line?

Daryl Spitzer

Posted 2009-12-09T18:57:08.453

Reputation: 7 505

Answers

80

There's a few ways:

sudo reboot
sudo init 6
sudo shutdown -r now

John T

Posted 2009-12-09T18:57:08.453

Reputation: 149 037

What about if you're not sudo? When clicking, you don't have to be sudo... – Atcold – 2016-02-17T14:50:21.350

10Be careful with init. If the inittab has been changed, init 6 may be mapped to some other runlevel. I've seen a number of places that had the default runlevel after reboot set to single-user mode. – Satanicpuppy – 2009-12-09T19:24:44.797

9

If you've got freedesktop-compliant session manager, you can use DBus to invoke restart from inside the X session. The command goes:

dbus-send --system --dest=org.freedesktop.Hal --type=method_call \
    --print-reply /org/freedesktop/Hal/devices/computer \
    org.freedesktop.Hal.Device.SystemPowerManagement.Reboot int32:0

(this is probably more than necessary; works for me). I use this in a shell script. You don't need to run this from root, but you need to run it from inside an X session (f.e. in a terminal). You can find more on this topic at https://wiki.ubuntu.com/DebuggingGNOMEPowerManager

liori

Posted 2009-12-09T18:57:08.453

Reputation: 3 044

What is the advantage of this over sudo reboot? – Daryl Spitzer – 2009-12-11T13:40:55.410

3It will notify your session manager that you're about to reboot, and f.e. save your session status (apps opened). I'm not sure whether reboot or shutdown does that. Also, as I wrote in the answer, you don't need sudo or su (you need to be allowed to do that by session manager, but this is usually true in most desktop distros). – liori – 2009-12-11T15:03:52.917

2

Occasionally, the usual (and preferred) reboot and shutdown commands don't work. I've seen this on a system with problems (which is why it needed rebooting).

You can trigger the "Magic SysRq" mechanism from the commandline:

echo b >/proc/sysrq-trigger

This is equivalent to alt-SysRq+b and will reboot the machine.

You may want to try "s" and "u" first to sync discs and unmount filesystems respectively.

Draemon

Posted 2009-12-09T18:57:08.453

Reputation: 738

0

If you are working in Virtual Environment It will put hard disk on Standby Mode: sudo /sbin/shutdown -h now.

Swapnil Gangrade

Posted 2009-12-09T18:57:08.453

Reputation: 101

0

I found this page on computerhope.com:

The command is reboot. There is also halt, poweroff & shutdown.

Daryl Spitzer

Posted 2009-12-09T18:57:08.453

Reputation: 7 505

1halt & poweroff actually turn the machine off completely, shutdown will only reboot the machine with the correct switches provided. – John T – 2009-12-09T19:04:03.510

0

nothing wrong with any of the above, but you can also install gnome-do and enable the session management plugin, which lets you easily shutdown,reboot,suspend from gnome-do

user23307

Posted 2009-12-09T18:57:08.453

Reputation: 5 915