1 Working With the GRUB 2 Bootloader and Configuring Boot Services

This chapter describes the Oracle Linux boot process and how to configure and use the GRUB 2 bootloader and other boot-related kernel parameters.

About the Boot Process

Understanding the Oracle Linux boot process can help you troubleshoot problems while booting a system. The boot process involves several files and errors in these files are the usual cause of boot problems.

When an Oracle Linux system boots, it performs the following operations:

  1. The computer's BIOS performs a power-on self-test (POST), and then locates and initializes any peripheral devices including the hard disk.

  2. The BIOS reads the Master Boot Record (MBR) into memory from the boot device. (For GUID Partition Table (GPT) disks, this MBR is the protective MBR on the first sector of the disk.) The MBR stores information about the organization of partitions on that device. On a computer with x86 architecture, the MBR occupies the first 512 bytes of the boot device. The first 446 bytes contain boot code that points to the boot loader program, which can be on the same device or on another device. The next 64 bytes contain the partition table. The final two bytes are the boot signature, which is used for error detection.

    The default boot loader program that is used in Oracle Linux is the GRand Unified Bootloader version 2 (GRUB 2).

  3. The boot loader loads the vmlinuz kernel image file into memory and extracts the contents of the initramfs image file into a temporary, memory-based file system (tmpfs).

  4. The kernel loads the driver modules from the initramfs file system that are needed to access the root file system.

  5. The kernel starts the systemd process with a process ID of 1 (PID 1). systemd is the ancestor of all processes on a system. systemd reads its configuration from files in the /etc/systemd directory. The /etc/systemd/system.conf file controls how systemd handles system initialization.

    systemd reads the file linked by /etc/systemd/system/default.target, for example /usr/lib/systemd/system/multi-user.target, to determine the default system target.

    Note:

    You can use a kernel boot parameter to override the default system target. See Kernel Boot Parameters.

    The system target file defines the services that systemd starts.

    systemd brings the system to the state defined by the system target, performing system initialization tasks such as:

    • Setting the host name.

    • Initializing the network.

    • Initializing SELinux based on its configuration.

    • Printing a welcome banner.

    • Initializing the system hardware based on kernel boot arguments.

    • Mounting the file systems, including virtual file systems such as the /proc file system.

    • Cleaning up directories in /var.

    • Starting swapping.

    See About System-State Targets.

  6. If you have made /etc/rc.local executable and you have copied /usr/lib/systemd/system/rc-local.service to /etc/systemd/system, systemd runs any actions that you have defined in /etc/rc.local. However, the preferred way of running such local actions is to define your own systemd unit.

For information about systemd and on how to write systemd units, see the systemd(1), systemd-system.conf(5), and systemd.unit(5) manual pages.

Working With the GRUB 2 Bootloader

The GRUB 2 bootloader can load many operating systems in addition to Oracle Linux and it can chain-load proprietary operating systems. GRUB 2 understands the formats of file systems and kernel executables, which allows it to load an arbitrary operating system without needing to know the exact location of the kernel on the boot device. GRUB 2 requires only the file name and drive partitions to load a kernel.

Customizing GRUB 2 Configuration

You can manage GRUB 2 configuration by using the GRUB 2 menu or by using the command line.

Note:

Do not edit the GRUB 2 configuration file directly. On BIOS-based systems, the configuration file is /boot/grub2/grub.cfg. On UEFI-based systems, the configuration file is /boot/efi/EFI/redhat/grub.cfg.

The grub2-mkconfig command generates the configuration file by using the template scripts in the /etc/grub.d file and menu configuration settings are taken from the /etc/default/grub configuration file.

The default menu entry is determined by the value of the GRUB_DEFAULT parameter in /etc/default/grub. The value saved allows you to use the grub2-set-default and grub2-reboot commands to specify the default entry. grub2-set-default sets the default entry for all subsequent reboots and grub2-reboot sets the default entry for the next reboot only.

If you specify a numeric value as the value of GRUB_DEFAULT or as an argument to either grub2-reboot or grub2-set-default, GRUB 2 counts the menu entries in the configuration file starting at 0 for the first entry.

Using the GRUB 2 Bootloader to Set the Default Boot Kernel

To set the UEK as the default boot kernel:

  1. Display the menu entries that are defined in the configuration file, for example:

    grep '^menuentry' /boot/grub2/grub.cfg
    menuentry 'Oracle Linux Everything, with Linux 3.10.0-123.el7.x86_64' ... {
    menuentry 'Oracle Linux Everything, with Linux 3.8.13-35.2.1.el7uek.x86_64' ... {
    menuentry 'Oracle Linux Everything, with Linux 0-rescue-052e316f566e4a45a3391cff21b4174b' ... {

    In this example for a BIOS-based system, the configuration file is /boot/grub2/grub.cfg, which contains menu entries 0, 1, and 2 that correspond to the RHCK, UEK, and the rescue kernel respectively.

  2. Enter the following commands to make the UEK (entry 1) the default boot kernel:

    sudo grub2-set-default 1
    sudo grub2-mkconfig -o /boot/grub2/grub.cfg 

    Alternatively, you can specify the value of the text of the entry as a string enclosed in quotes.

    sudo grub2-set-default 'Oracle Linux Everything, with Linux 3.8.13-35.2.1.el7uek.x86_64'
    sudo grub2-mkconfig -o /boot/grub2/grub.cfg 

For more information about using, configuring, and customizing GRUB 2, see the GNU GRUB Manual, which is also installed as /usr/share/doc/grub2-tools-2.00/grub.html.

Kernel Boot Parameters

There are several kernel boot parameters that you can set. The following table lists some of the more commonly used parameters.

Option Description

0, 1, 2, 3, 4, 5, or 6, or systemd.unit=runlevelN.target

Specifies the nearest systemd-equivalent system-state target to an Oracle Linux 6 run level. N can take an integer value between 0 and 6.

For a description of system-state targets, see About System-State Targets.

1, s, S, single, or systemd.unit=rescue.target

Specifies the rescue shell. The system boots to single-user mode prompts for the root password.

3 or systemd.unit=multi-user.target

Specifies the systemd target for multi-user, non-graphical login.

5 or systemd.unit=graphical.target

Specifies the systemd target for multi-user, graphical login.

-b, emergency, or systemd.unit=emergency.target

Specifies emergency mode. The system boots to single-user mode and prompts for the root password. Fewer services are started than when in rescue mode.

KEYBOARDTYPE=kbtype

Specifies the keyboard type, which is written to /etc/sysconfig/keyboard in the initramfs.

KEYTABLE=kbtype

Specifies the keyboard layout, which is written to /etc/sysconfig/keyboard in the initramfs.

LANG=language_territory.codeset

Specifies the system language and code set, which is written to /etc/sysconfig/i18n in the initramfs.

max_loop=N

Specifies the number of loop devices (/dev/loop*) that are available for accessing files as block devices. The default and maximum values of N are 8 and 255.

nouptrack

Disables Ksplice Uptrack updates from being applied to the kernel.

quiet

Reduces debugging output.

rd_LUKS_UUID=UUID

Activates an encrypted Linux Unified Key Setup (LUKS) partition with the specified UUID.

rd_LVM_VG=vg/lv_vol

Specifies an LVM volume group and volume to be activated.

rd_NO_LUKS

Disables detection of an encrypted LUKS partition.

rhgb

Specifies that the Red Hat graphical boot display should be used to indicate the progress of booting.

rn_NO_DM

Disables Device-Mapper (DM) RAID detection.

rn_NO_MD

Disables Multiple Device (MD) RAID detection.

ro root=/dev/mapper/vg-lv_root

Specifies that the root file system is to be mounted read only, and specifies the root file system by the device path of its LVM volume (where vg is the name of the volume group).

rw root=UUID=UUID

Specifies that the root (/) file system is to be mounted read-writable at boot time, and specifies the root partition by its UUID.

selinux=0

Disables SELinux.

SYSFONT=font

Specifies the console font, which is written to /etc/sysconfig/i18n in the initramfs.

The kernel boot parameters that were last used to boot a system are recorded in /proc/cmdline, as shown in the following example:

cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-3.10.0-123.el7.x86_64 root=UUID=52c1cab6-969f-4872-958d-47f8518267de
ro rootflags=subvol=root vconsole.font=latarcyrheb-sun16 crashkernel=auto vconsole.keymap=uk
rhgb quiet LANG=en_GB.UTF-8

For more information, see the kernel-command-line(7) manual page.

Modifying Kernel Boot Parameters Before Booting

To modify boot parameters before booting a kerne, follow these stepsl:

  1. When presented with the GRUB boot menu, use the arrow keys to highlight the required kernel and then press the space bar.

    The following figure shows the GRUB menu with the Unbreakable Enterprise Kernel (UEK) boot entry selected.

    Figure 1-1 GRUB Menu with UEK boot entry selected


    The figure shows the GRUB menu with the UEK boot option selected.
  2. Press E to edit the boot configuration for the kernel.

  3. Using the arrow keys, scroll down the screen until the cursor is at the start of the boot configuration line for the kernel (which starts linux16).

  4. Edit this line to change the boot parameters.

    For example, press End to go to the end of the line and enter an additional boot parameter.

    The following figure shows the kernel boot line with the additional parameter systemd.target=runlevel1.target, which starts the rescue shell.

    Figure 1-2 Kernel Boot Line with an Additional Parameter to Select the Rescue Shell


    The figure shows the kernel boot line with an additional parameter systemd.target=runlevel1.target, which starts the rescue shell.
  5. Press Ctrl+X to boot the system.

Modifying Kernel Boot Parameters in GRUB 2 Configuration

To modify boot parameters in the GRUB 2 configuration so that they are applied by default at every reboot, follow these steps:

  1. Edit the /etc/default/grub file and modify the parameters in the GRUB_CMDLINE_LINUX definition, for example:

    GRUB_CMDLINE_LINUX="vconsole.font=latarcyrheb-sun16 vconsole.keymap=uk 
    crashkernel=auto  rd.lvm.lv=ol/swap rd.lvm.lv=ol/root biosdevname=0 
    rhgb quiet systemd.unit=runlevel3.target"

    The previous example adds the systemd.unit=runlevel3.target parameter so that the system boots into multi-user, non-graphical mode by default.

  2. Rebuild the /boot/grub2/grub.cfg file as follows:

    sudo grub2-mkconfig -o /boot/grub2/grub.cfg

    This change takes effect for subsequent system reboots of all configured kernels.