Summary

Although Linux distributions are designed to boot painlessly and reliably once installed, understanding the boot process will help you overcome problems and maintain your system. Most Linux systems employ a boot loader known as GRUB (either GRUB Legacy or GRUB 2). These programs both fit themselves into the standard BIOS boot system, enabling the computer to load the Linux kernel. GRUB 2, and some patched versions of GRUB Legacy, also work on EFI-based computers. The kernel then runs the init program, which in turn reads various configuration files to boot all the services that make a running Linux system.

Modifying your GRUB configuration enables you to boot different Linux kernels or non-Linux OSs. You can also pass new boot options to Linux. Once the system is booted, you can use the dmesg command or log files to study the boot process in order to verify that it went correctly or to find clues as to why it didn’t.

You can use the Vi editor to edit your GRUB configuration file, your system initialization scripts and configuration files, or any other plain-text file on your computer. Although Vi is old-fashioned in many ways, it’s small and fits on emergency disk systems. Every administrator should be familiar with Vi, even if it’s not your editor of choice for day to day operations.

FAQ

How GRUB Legacy is configured and used?

GRUB Legacy uses the menu.lst or grub.conf configuration file in /boot/grub. This file contains global and per-image options. Use the grub-install program to install the boot loader. When GRUB boots, it presents a menu of OS options that you select using the keyboard arrow keys.

How GRUB 2 is configured and used?

GRUB 2 uses the /boot/grub/grub.cfg configuration file; however, system administrators are discouraged from editing it directly. Instead, they should rely on automatic configuration scripts and set system-specific defaults in /etc/defaults/grub and the files in /etc/grub.d . As with GRUB Legacy, you can install GRUB 2 using the grub-install program.

How does boot process work?

The CPU runs the firmware, the firmware loads and runs a boot loader, the boot loader loads and runs secondary boot loaders (if needed) and the Linux kernel, the Linux kernel loads and runs the initial system program , and init starts the rest of the system services via startup scripts that are specific to the startup system (SysV, Upstart, SystemD, or something more exotic). BIOS-based computers look for boot loaders in various boot sectors, including the MBR of a hard drive or the boot sector of a disk partition or floppy disk. EFI-based computers look for boot loaders in files on the ESP.

Where is boot-time log information stored?

The dmesg command prints out logs from the kernel ring buffer, which holds boot-time and other kernel messages. Other useful log information can be found in /var/log/messages and other files in /var/log.

What is the role of /sbin/init?

The init program is responsible for starting many programs and services on your Linux operating system. This is done by running processes that are listed in /etc/inittab , including an rc script that runs the SysV initialization scripts.

How runlevels are configured?

The default runlevel is specified with a line like id:2:initdefault: in the /etc/inittab file. Use commands such as chkconfig , update-rc.d , ntsysv , and systemctl to change which services are started when switching to specific runlevels. Runlevels 0, 1, and 6 are reserved for shutdown, single-user mode, and rebooting, respectively. Runlevels 3, 4, and 5 are the common user runlevels on Red Hat and most other distributions, and runlevel 2 is the usual user runlevel on Debian systems.

How does runlevels changes?

The programs init and telinit can be used to change to other runlevels. shutdown, halt, poweroff, and reboot are also useful when shutting down, rebooting, or switching to single-user mode.

What are Vi’s three editing modes?

You enter text using insert mode, which supports text entry and deletion. The command and ex modes are used to perform more complex commands or to run outside programs to operate on the text entered or changed in insert mode.