Ubuntu – Shutting down the system using a virtual console

command linerebootshutdownvirtual-console

My computer is freezing from time to time. It's because I make few mistakes and I ruined my system. I don't have any time to reinstall the system now.
While my PC is frozen, it still works when I press Ctrl+Alt+F1. Is there any way to reboot system using it?

Best Answer

Pressing Ctrl+Alt+F1 brought you from X11 (the GUI) to a virtual console. You can certainly reboot from here.

  • The easiest way to reboot from a virtual console is to just press Ctrl+Alt+Delete. You don't even need to log in first, though it would not be a problem if you did. Unlike on the old DOS systems, pressing Ctrl+Alt+Delete in a GNU/Linux system like Ubuntu actually performs a proper shutdown and clean reboot.

    This doesn't work in the GUI (unless you've set it up to, or you're running a really old distro). But it does work in any virtual console that doesn't have X11 running in it (unless you've set it up not to, which is rare).

  • Another way is to log in and run sudo reboot. You'll be asked for your password to log in on the virtual console, and you'll be asked for it again for sudo. It's the same password both times, and you won't see any placeholder characters (like *) appear as you're typing it. Type it in and press Enter.

However, instead of rebooting, you might consider:

  • Restarting just the GUI. Your desktop environment and all running programs will swiftly quit (so you must usually be as careful with this as with a reboot), the GUI will be restarted, and the graphical login screen will come back up, when you run:

    sudo service lightdm restart
    

    This works by stopping and starting the display manager. That particular command actually only works if your display manager is LightDM, which it is by default on most Ubuntu systems. The main exception is if you are running Ubuntu GNOME, which uses GDM:

    sudo service gdm restart
    
  • Attempting to close just the offending program. Though no program should cause the whole GUI to freeze, it can occasionally happen. You can log in (see above) and run top see the currently running processes, sorted by CPU usage. (Press Q to quit top itself.) A program that's causing the GUI to freeze is not necessarily using lots of CPU, but this is a place to start.

    You can also use the ps command to find the process ID or name of a program you know you want to try to quit, and the kill or killall command to quit it by number or name, respectively. As suggested by its name, killall attempts to kill all processes that have the name you give it. (The name of a process is not necessarily the same as the name shown to you in its launcher icon or title bar.)

Be careful when rebooting, no matter how you do it:

  • If you have programs with unsaved documents, your documents will be lost. If you need to attempt to save data first, then don't rush to reboot.
  • And this applies to restarting the display manager, too, except for documents open in other virtual consoles (but including those open in terminals accessed through terminal windows on your graphical desktop).

See also What should I do when Ubuntu freezes?