Linux Rebooting Refresh

by Ostatic Staff - Aug. 12, 2013

When I was first cutting my teeth on Unix, it was a big deal to reboot a server. Rebooting a Solaris machine could be a particularly harrowing experience. The command to do so was something like sync sync sync; init 6. The "sync" command was meant to flush any unwritten filesystem changes in memory to disk before they were lost. More recently, I'm not sure when the last time I used any command other than "reboot" on a modern Linux server. The reboot command properly runs through the init scripts and alerts other users that the server is going down. However, depending on how far back your nix experience goes, you might remember a time when reboot was absolutely not the right thing to do.

In older Unix systems, reboot was an executable that passed instructions to a system call. The reboot command completely ignored any of the startup or shutdown scripts and went straight to rebooting. Modern Linux systems are much more forgiving. The "reboot" command is roughly equivalent to "shutdown -r now". Any discussion about rebooting Linux eventually leads to runlevels, which as a sysadmin I felt I had a good understanding of. That is until I checked Wikipedia and found that the core Linux distributions have been deciding on their own runlevels.

Runlevels are a way of defining acceptable levels of functionality for a system. To boot a system you must always load the kernel into memory, but what the kernel turns on, what scripts are run, and what daemons are started is controlled by the runlevels. The Linux Standard Base defines the more traditional runlevel set:

  • 0 - Halt
  • 1 - Single User Mode
  • 2 - Multi-user, no networking
  • 3 - Multi-user, networking enabled (best for servers)
  • 4 - Not used
  • 5 - Multi-user, with networking, and X11 (junk for servers)
  • 6 - Reboot

RedHat and SLES seem to follow this pattern, but Debian groups runlevels 2-5 together and runs everything at runlevel 2. Perhaps because X11 is just another daemon to run, and they see no reason to have a multi-user environment without networking. I can see their point.

CentOS:

  • runlevel 0 is System halt (Do not use this for initdefault!)
  • runlevel 1 is Single user mode
  • runlevel 2 is Local multiuser without remote network (e.g. NFS)
  • runlevel 3 is Full multiuser with network
  • runlevel 4 is Not used
  • runlevel 5 is Full multiuser with network and xdm
  • runlevel 6 is System reboot (Do not use this for initdefault!)

Debian:

  • Runlevel 0 is halt.
  • Runlevel 1 is single-user.
  • Runlevels 2-5 are multi-user.
  • Runlevel 6 is reboot.

I have to imagine that there was a heated IRC debate on modifying the runlevels. A user with administrative privileges can change to a different run level using the "init" command. So, you could skip straight to single-user mode by entering init 1 from the console. However, this might not be the best idea, since there may still be processes that did not stop that are running, holding onto memory or resources that you need to have control of. The best way to get into single user mode is by appending "-s" to the end of the kernel boot parameters in Grub.

For the everyday desktop Linux user, details about runlevels should never need to be known, but for a sysadmin or anyone that deals with Linux professionally, an understanding of how the runlevels are defined and how they can be used is essential. Even if you are a seasoned pro, it is always good to revisit some of the basics of how and why the Linux system works.