Updated: 2012-11-21 05:08 EST

1 Topics and ReadingsIndexup to index

1.1 Fedora TextbooksIndexup to index

1.2 The InternetIndexup to index

2 Definitions: boot and boot loaderIndexup to index

3 What happens at power onIndexup to index

4 The Linux /boot directoryIndexup to index

5 The Grand Unified Boot Loader - GRUBIndexup to index

5.1 A sample GRUB Legacy configuration file (version 0.9x)Indexup to index

All versions of GRUB use a configuration file under /boot/grub to display a menu of alternative operating systems to boot. Without a configuration file, GRUB starts in interactive mode and you have to specify and type everything yourself. With a configuration file, you can select from a menu list of choices.

In GRUB Legacy, each choice in the configuration file starts with a “title” keyword followed by a descriptive name:

# Sample GRUB menu.lst or grub.conf file (GRUB Legacy version 0.9x)
timeout=30
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
default=0

# this sdb disk has partition sdb1 for /boot and sdb2 for / (ROOT)
# (Note how pathnames do *not* start with /boot on a separate partition!)
title Fedora 2.6.31 on second disk
    root (hd1,0)
    kernel /vmlinuz-2.6.31.5-127.fc12.i686.PAE ro root=/dev/sdb2
    initrd /initramfs-2.6.31.5-127.fc12.i686.PAE.img

# this sdc disk has partition sdc1 for / (ROOT) and uses a /boot directory
# (not a separate /boot partition, so pathnames must start with /boot)
title Old Fedora 2.6.23 on third disk
    password sesame
    root (hd2,0)
    kernel /boot/vmlinuz-2.6.23.15.137.fc8 ro root=/dev/sdc1
    initrd /boot/initrd-2.6.23.15.137.fc8.img

# this first disk partition has a Windows boot loader in the first sector
title Windows on first disk
    rootnoverify (hd0,0)
    makeactive
    chainloader +1

Notes:

5.2 grub.conf keywordsIndexup to index

Note: To find out about additional GRUB commands, type help at the GRUB shell prompt, and see the above Resources.

5.3 GRUB Device and file Naming Convention - (hd0,0)/grub/menu.lstIndexup to index

A full GRUB path name specification is a device name (often a partition name) followed by a file system pathname inside that partition (relative to the start of the partition), e.g. (hd0,0)/grub/menu.lst where /grub/menu.lst is relative to the start of the partition (hd0,0). (This is similar to DOS/Windows and its drive letters.)

5.4 Effect of separate /boot partition on GRUB pathnamesIndexup to index

GRUB configuration files are stored under directory /boot/grub in Linux. /boot/grub is the Linux pathname, not necessarily the GRUB pathname, because GRUB pathnames are composed of a partition name followed by a pathname inside the partition, e.g. (hd0,0)/some/path/name where /some/path/name is relative to the start of the partition.

Since partitions are mounted on directories in Linux, and those directory pathnames prefix the names inside the partition for Linux pathnames, a GRUB pathname and a Linux absolute pathname will always differ, except for the one partition that is mounted on ROOT (because prefixing an absolute pathname with / [ROOT] doesn’t change it).

5.4.1 /boot is on the ROOT partitionIndexup to index

If /boot is not its own partition, then it is a directory inside the ROOT partition. GRUB shell command pathnames referring to the kernel and to GRUB configuration files will also be inside the ROOT partition and will therefore all start with the ROOT partition name followed by the subdirectory name /boot inside the partition, e.g. (hd0,0)/boot/grub/grub.conf refers to the Linux pathname /boot/grub/grub.conf (because /boot is a directory inside the ROOT partition (hd0,0)).

5.4.2 /boot is its own partitionIndexup to index

If /boot is its own mounted partition, then the GRUB files will be on this separate BOOT partition (not on the ROOT partition) that gets mounted on /boot and the GRUB pathnames (which are relative to the start of partitions, not relative to the ROOT of the file system) will therefore not start with /boot, they will start directly under the BOOT partition device name e.g. (hd0,0)/grub/grub.conf refers to the Linux pathname /boot/grub/grub.conf (because (hd0,0) is mounted on /boot and so /boot is prefixed to the part of the pathname contained inside the partition).

5.4.3 SummaryIndexup to index

  • Separate /boot partition: (hd0,0)/grub/grub.conf
  • /boot is under ROOT: (hd0,0)/boot/grub/grub.conf

Fedora 12 uses a separate BOOT partition. Do not use “/boot” at the start of GRUB pathnames because the pathnames are inside their own BOOT partition (that will be mounted on /boot) and GRUB addresses pathnames by partition name.

5.5 Installing GRUBIndexup to index

Your Linux installation already installed GRUB for you. If you have to re-install GRUB, you may find (or be able to install) the “grub-install” script that will do it for you. You can also try it manually, if the GRUB setup files are already stored under /boot/grub:

Most versions of the GRUB shell have TAB command completion, where you can type part of a device or pathname and GRUB will give you all the possible completions. The command-line GRUB in Fedora 12 is broken, and does not have this feature. The GRUB that runs at boot time is not broken and does have the TAB completion feature.

BE CAREFUL. GRUB does not ask you for confirmation! If you type the wrong thing, you will overwrite your boot sector with garbage and be unable to boot your system. You will need to boot a “live” CD and repair.

5.6 Booting without a GRUB menu - interactive GRUB commandsIndexup to index

If grub.conf is not present or has been moved, GRUB cannot display a menu. In this case it will display the GRUB interactive shell, similar to what you get by typing grub at a Linux command line.

The interactive GRUB shell has its own prompt (“grub>”) and its own built-in commands, some with the same names as BASH shell commands. Be clear on when you are typing into the GRUB shell and when you are typing into BASH. The same command name may do different things, depending on whether GRUB executes it or BASH executes it.

Most versions of the GRUB shell have TAB command completion, where you can type part of a device or pathname and GRUB will give you all the possible completions. The command-line GRUB in Fedora 12 is broken, and does not have this feature enabled. The GRUB that runs stand-alone at boot time is not broken and does have the TAB completion feature.

Type “help” for a partial list of commands you can use. Some examples:

At the GRUB shell prompt, GRUB commands can be entered to query the system, see text files, and load and then boot a kernel image. Example:

Note: The GRUB shell can also be accessed by following directions (usually by pressing c) when the GRUB menu is presented. [Esc] brings you from the GRUB shell back to the menu. Pressing e allows you to edit boot menu entries of grub.conf. Pressing b boots the edited menu item. Some versions of GRUB allow typing a to go directly to a GRUB “kernel” line and edit the options.

6 Kernel options: single user mode, run levels, confirmation, kernelIndexup to index

Kernel options influence how the system boots and what software might be enabled. The options are given after the kernel image name on a “kernel” line, allow you to boot your system with different features enabled. Some versions of GRUB allow you to type a while viewing the GRUB menu, to go directly to a GRUB “kernel” line and edit the kernel options. Options are separated by blanks, e.g.: ro single txt 3

When you edit these GRUB lines, you are only changing the in-memory copy of the configuration, you are not changing the actual configuration on disk. To make any edit permanent, you must boot the system (single-user is fine) and actually edit the configuration file and save it.

6.1 Booting Single User Mode (Maintenance Mode)Indexup to index

Single-user mode is a “half-up” state used for system repair and maintenance (especially for resetting the ROOT password!). The system only brings up a minimal number of services. The GUI is not started. Networking may not be enabled. Not all disks may be mounted. The console terminal gets a shell running as the ROOT user.

To boot into single-user mode, add the word “single” as an option to a “kernel” line in GRUB and then boot that entry, e.g.:

6.2 Booting into a different Run LevelIndexup to index

(Run Levels are summarized below.) To start Linux with a different run level than the default, add the run level digit to the kernel options, e.g. to boot Run Level 3 (multi-user without the X11 GUI window system):

6.3 Confirming the startup of individual servicesIndexup to index

To be prompted at boot time before each system service starts up:

6.4 Fixing a kernel panic (missing ROOT file system)Indexup to index

If you moved your ROOT file system to a different partition but forgot to change the GRUB configuration file, your kernel will “panic” and tell you it can’t find the root. You can reboot into the GRUB shell and edit the root= option on the “kernel” line to point to the correct ROOT partition:

7 Legacy Run LevelsIndexup to index

Run Levels system was a crude way to specify groups of services that were to be started and stopped together. Some Enterprise systems (long maintenance window) still use Run Levels, and newer versions of the system (using upstart or systemd) emulate Run Levels.

Run Levels expect that a system boots into a fixed state, with a fixed set of disks and fixed set of services. They do not work well with systems where devices come and go after booting, e.g. USB drives, printers, cameras, hotplug disks, etc.

7.1 Run Level CommandsIndexup to index

7.2 Run Level Services and chkconfigIndexup to index

You can see which services are started and stopped in each Run Level using the chkconfig command. If that command is not available, look at the file symlinks under the Run Level directories /etc/rc?.d. Each symlink starts with either an “S” (start this service) or a “K” (kill this service) followed by a two-digit sequence number followed by the name of the service, e.g.

Each of those symlinks points to a script file responsible for killing or starting the indicated service. You can change what services get killed or started using the chkconfig command that adds or removes symlinks from the Run Level directories (or you can add/remove symlinks manually).

8 Upstart and SystemdIndexup to index

Run Levels expect that a system boots into a fixed state, with a fixed set of disks and fixed set of services. They do not work well with systems where devices come and go after booting, e.g. USB drives, printers, cameras, hotplug disks, etc.

Modern Unix/Linux systems moved away from static Run Levels to use the more dynamic and complex upstart system of starting/stopping services. Run Levels were “emulated” by upstart, but upstart could handle devices coming and going dynamically much better. When devices were added/removed, “events” were generated that could start and stop related system services.

The complexity and limitations of upstart prompted Lennart Poettering to write a new Linux-only systemd session manager. Fedora 15 then moved from upstart to use the new systemd. Debian is reluctant to use a Linux-only start-up system, and so Debian and Ubuntu still use upstart. There is still controversy as to which is the better system. See the Wikipedia references for details and read up on systemd.

Author: 
| Ian! D. Allen  -  idallen@idallen.ca  -  Ottawa, Ontario, Canada
| Home Page: http://idallen.com/   Contact Improv: http://contactimprov.ca/
| College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/
| Defend digital freedom:  http://eff.org/  and have fun:  http://fools.ca/

Plain Text - plain text version of this page in Pandoc Markdown format

Campaign for non-browser-specific HTML   Valid XHTML 1.0 Transitional   Valid CSS!   Creative Commons by nc sa 3.0   Hacker Ideals Emblem   Author Ian! D. Allen