Grub cmdline linux fedora

Bootloading with GRUB2

This page has been converted from the Fedora Project Wiki and cleaned up for publishing here on the Fedora Docs Portal, but it has not yet been reviewed for technical accuracy. This means any information on this page may be outdated or inaccurate. Reviews for technical accuracy are greatly appreciated. If you want to help, see the README file in the source repository for instructions.

GRUB2 is the latest version of GNU GRUB, the GRand Unified Bootloader. A bootloader is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the operating system kernel. In Fedora, the kernel is Linux. The kernel then initializes the rest of the operating system.

GRUB2 is the follower of the previous version GRUB (version 0.9x). The original version is available under the name GRUB Legacy.

Since Fedora 16, GRUB2 has been the default bootloader on x86 BIOS systems. For upgrades of BIOS systems, the default is also to install GRUB2, but you can opt to skip bootloader configuration entirely.

Installing GRUB2 on a BIOS system

Normally, GRUB2 will be installed and set up by the installer, Anaconda, during the installation process. You will probably never have to deal with manual installation of GRUB2. However, in certain situations , you will want to install GRUB2 manually, especially if you need to repair the existing GRUB2 installation or you want to change its configuration.

This procedure shows the steps to install GRUB2 on your Master Boot Record (MBR) of your primary hard disk.

Make sure you have the the GRUB2 packages and the os-prober package installed in your system:

To automatically collect information about your disks and operating systems installed on them, the os-prober package needs to be installed on your system.

Create a configuration file for GRUB2.

List block devices available on the system.

Identify the primary hard disk. Usually, it is the sda device.

Install GRUB2 in the MBR of the primary hard disk.

Reboot your computer to boot with the newly installed bootloader.

The grub2-mkconfig command creates a new configuration based on the currently running system. It collects information from the /boot partition (or directory), from the /etc/default/grub file, and the customizable scripts in /etc/grub.d/ .

The configuration format is changing with time, and a new configuration file can become slightly incompatible with the older versions of the bootloader. Always run grub2-install before you create the configuration file with grub2-mkconfig .

In Fedora, it is generally safe to edit /boot/grub2/grub.cfg manually. Grubby in Fedora patches the configuration when a kernel update is performed and will try to not make any other changes than what is necessary. Manual changes can be overwritten with grub2-mkconfig when the system gets upgraded with Anaconda. Customizations placed in /etc/grub.d/40_custom or /boot/grub2/custom.cfg files will survive running the grub2-mkconfig command.

Installing GRUB2 on a UEFI system

Normally, GRUB2 will be installed and set up by the installer, Anaconda, during the installation process. You will probably never have to deal with manual installation of GRUB2. However, in certain situations , you will want to install GRUB2 manually, especially if you need to repair the existing GRUB2 installation or you want to change its configuration.

This procedure shows the steps to install GRUB2 on a UEFI system on Fedora 18 or newer. The procedure consists of four parts.

Creating an EFI System Partition

The UEFI firmware requires to boot from an EFI System Partition on a disk with a GPT label. To create such a partition:

List available block devices to find a place to create your ESP.

Create at least a 128 MiB disk partition using a GPT label on the primary hard disk.

For the sake of this procedure, we assume that the created partition is recognized as /dev/sda1 .

Format the partition with the FAT32 file system.

Create the /boot/efi directory as a mount point for the new partition.

Mount the partition to the /boot/efi mount point.

Proceed to the next part.

Install the bootloader files

In order to use GRUB2 with on the UEFI systems, you need to install or re-install appropriate packages:

Re-install the necessary packages.

If the above command ends with an error, install the packages.

Читайте также:  Sharp ar m205 драйвер windows 10 x64

This installs the signed shim and the GRUB2 binary.

Create a GRUB2 configuration

If you already have a working GRUB2 EFI configuration file, you do not need to do anything else.

Otherwise, create the configuration file using the grub2-mkconfig command.

Under EFI, GRUB2 looks for its configuration in /boot/efi/EFI/fedora/grub.cfg .

For newly installed kernels to work, grubby expects /etc/grub2-efi.cfg to be a symlink to the real grub.cfg (for example /boot/efi/EFI/fedora/grub.cfg ).

Solving problems with UEFI bootloader

When you power on your system, your firmware will look for EFI variables that tell it how to boot. On running systems, which have booted into the EFI mode and their EFI runtime services are working correctly, you can configure your boot menu with efibootmgr .

Источник

Working with the GRUB 2 Boot Loader

Introduction to GRUB 2

GRUB 2 reads its configuration from the /boot/grub2/grub.cfg file on traditional BIOS-based machines and from the /boot/efi/EFI/fedora/grub.cfg file on UEFI machines. This file contains menu information.

The GRUB 2 configuration file, grub.cfg , is generated during installation, or by invoking the /usr/sbin/grub2-mkconfig utility, and is automatically updated by grubby each time a new kernel is installed. When regenerated manually using grub2-mkconfig, the file is generated according to the template files located in /etc/grub.d/ , and custom settings in the /etc/default/grub file. Edits of grub.cfg will be lost any time grub2-mkconfig is used to regenerate the file, so care must be taken to reflect any manual changes in /etc/default/grub as well.

Normal operations on grub.cfg , such as the removal and addition of new kernels, should be done using the grubby tool and, for scripts, using new-kernel-pkg tool. If you use grubby to modify the default kernel the changes will be inherited when new kernels are installed. For more information on grubby , see Making Persistent Changes to a GRUB 2 Menu Using the grubby Tool.

The /etc/default/grub file is used by the grub2-mkconfig tool, which is used by anaconda when creating grub.cfg during the installation process, and can be used in the event of a system failure, for example if the boot loader configurations need to be recreated. In general, it is not recommended to replace the grub.cfg file by manually running grub2-mkconfig except as a last resort. Note that any manual changes to /etc/default/grub require rebuilding the grub.cfg file.

Among various code snippets and directives, the grub.cfg configuration file contains one or more menuentry blocks, each representing a single GRUB 2 boot menu entry. These blocks always start with the menuentry keyword followed by a title, list of options, and an opening curly bracket, and end with a closing curly bracket. Anything between the opening and closing bracket should be indented. For example, the following is a sample menuentry block for Fedora Rawhide with Linux kernel 3.17.4-301.fc21.x86_64:

Each menuentry block that represents an installed Linux kernel contains linux on 64-bit IBM POWER Series, linux16 on x86_64 BIOS-based systems, and linuxefi on UEFI-based systems. Then the initrd directives followed by the path to the kernel and the initramfs image respectively. If a separate /boot partition was created, the paths to the kernel and the initramfs image are relative to /boot . In the example above, the initrd /initramfs-3.17.4-301.fc21.x86_64.img line means that the initramfs image is actually located at /boot/initramfs-3.17.4-301.fc21.x86_64.img when the root file system is mounted, and likewise for the kernel path.

The kernel version number as given on the linux16 /vmlinuz-kernel_version line must match the version number of the initramfs image given on the initrd /initramfs-kernel_version.img line of each menuentry block. For more information on how to verify the initial RAM disk image, see Verifying the Initial RAM Disk Image.

In menuentry blocks, the initrd directive must point to the location (relative to the /boot/ directory if it is on a separate partition) of the initramfs file corresponding to the same kernel version. This directive is called initrd because the previous tool which created initial RAM disk images, mkinitrd , created what were known as initrd files. The grub.cfg directive remains initrd to maintain compatibility with other tools. The file-naming convention of systems using the dracut utility to create the initial RAM disk image is initramfs-kernel_version.img .

Configuring the GRUB 2 Boot Loader

Changes to the GRUB 2 menu can be made temporarily at boot time, made persistent for a single system while the system is running, or as part of making a new GRUB 2 configuration file.

To make non-persistent changes to the GRUB 2 menu, see Making Temporary Changes to a GRUB 2 Menu.

For information on making and customizing a GRUB 2 configuration file, see Customizing the GRUB 2 Configuration File.

Making Temporary Changes to a GRUB 2 Menu

To change kernel parameters only during a single boot process, proceed as follows:

Читайте также:  Server linux ��� windows

Start the system and, on the GRUB 2 boot screen, move the cursor to the menu entry you want to edit, and press the e key for edit.

Move the cursor down to find the kernel command line. The kernel command line starts with linux on 64-Bit IBM Power Series, linux16 on x86-64 BIOS-based systems, or linuxefi on UEFI systems.

Move the cursor to the end of the line.

Press Ctrl + a and Ctrl + e to jump to the start and end of the line, respectively. On some systems, Home and End might also work.

Edit the kernel parameters as required. For example, to run the system in emergency mode, add the emergency parameter at the end of the linux16 line:

The rhgb and quiet parameters can be removed in order to enable system messages.

These settings are not persistent and apply only for a single boot. To make persistent changes to a menu entry on a system, use the grubby tool. See Adding and Removing Arguments from a GRUB Menu Entry for more information on using grubby .

Making Persistent Changes to a GRUB 2 Menu Using the grubby Tool

The grubby tool can be used to read information from, and make persistent changes to, the grub.cfg file. It enables, for example, changing GRUB menu entries to specify what arguments to pass to a kernel on system start and changing the default kernel.

In Red Hat Enterprise Linux 7, if grubby is invoked manually without specifying a GRUB configuration file, it defaults to searching for /etc/grub2.cfg , which is a symbolic link to the grub.cfg file, whose location is architecture dependent. If that file cannot be found it will search for an architecture dependent default.

To find out the file name of the default kernel, enter a command as follows:

To find out the index number of the default kernel, enter a command as follows:

To make a persistent change in the kernel designated as the default kernel, use the grubby command as follows:

To list all the kernel menu entries, enter a command as follows:

On UEFI systems, all grubby commands must be entered as root .

To view the GRUB menu entry for a specific kernel, enter a command as follows:

Try tab completion to see the available kernels within the /boot/ directory.

The —update-kernel option can be used to update a menu entry when used in combination with —args to add new arguments and —remove-arguments to remove existing arguments. These options accept a quoted space-separated list. The command to simultaneously add and remove arguments a from GRUB menu entry has the follow format:

To add and remove arguments from a kernel’s GRUB menu entry, use a command as follows:

This command removes the Red Hat graphical boot argument, enables boot message to be seen, and adds a serial console. As the console arguments will be added at the end of the line, the new console will take precedence over any other consoles configured.

To review the changes, use the —info command option as follows:

To add the same kernel boot arguments to all the kernel menu entries, enter a command as follows:

The —update-kernel parameter also accepts DEFAULT or a comma separated list of kernel index numbers.

To change a value in an existing kernel argument, specify the argument again, changing the value as required. For example, if the virtual console font size has been set to latarcyrheb-sun16 and you want to change the virtual console font size to 32 , use a command as follows:

See the grubby(8) manual page for more command options.

To add a new entry with the default kernel but with additionnal kernel arguments and make it the default entry, use:

In this example, we set the crashkernel=128M argument for kdump support.

Customizing the GRUB 2 Configuration File

GRUB 2 scripts search the user’s computer and build a boot menu based on what operating systems the scripts find. To reflect the latest system boot options, the boot menu is rebuilt automatically when the kernel is updated or a new kernel is added.

However, users may want to build a menu containing specific entries or to have the entries in a specific order. GRUB 2 allows basic customization of the boot menu to give users control of what actually appears on the screen.

GRUB 2 uses a series of scripts to build the menu; these are located in the /etc/grub.d/ directory. The following files are included:

00_header , which loads GRUB 2 settings from the /etc/default/grub file.

01_users , which is created only when a boot loader password is assigned in a kickstart file.

10_linux , which locates kernels in the default partition of Fedora.

30_os-prober , which builds entries for operating systems found on other partitions.

40_custom , a template, which can be used to create additional menu entries.

Читайте также:  Run gcc on linux

Scripts from the /etc/grub.d/ directory are read in alphabetical order and can be therefore renamed to change the boot order of specific menu entries.

With the GRUB_TIMEOUT key set to 0 in the /etc/default/grub file, GRUB 2 does not display the list of bootable kernels when the system starts up. In order to display this list when booting, press and hold any alphanumeric key when the BIOS information is displayed; GRUB 2 will present you with the GRUB menu.

Changing the Default Boot Entry

By default, the key for the GRUB_DEFAULT directive in the /etc/default/grub file is the word saved . This instructs GRUB 2 to load the kernel specified by the saved_entry directive in the GRUB 2 environment file, located at /boot/grub2/grubenv . You can set another GRUB record to be the default, using the grub2-set-default command, which will update the GRUB 2 environment file.

By default, the saved_entry value is set to the name of latest installed kernel of package type kernel. This is defined in /etc/sysconfig/kernel by the UPDATEDEFAULT and DEFAULTKERNEL directives. The file can be viewed by the root user as follows:

The DEFAULTKERNEL directive specifies what package type will be used as the default. Installing a package of type kernel-debug will not change the default kernel while the DEFAULTKERNEL is set to package type kernel.

GRUB 2 supports using a numeric value as the key for the saved_entry directive to change the default order in which the operating systems are loaded. To specify which operating system should be loaded first, pass its number to the grub2-set-default command. For example:

Note that the position of a menu entry in the list is denoted by a number starting with zero; therefore, in the example above, the third entry will be loaded. This value will be overwritten by the name of the next kernel to be installed.

To force a system to always use a particular menu entry, use the menu entry name as the key to the GRUB_DEFAULT directive in the /etc/default/grub file. To list the available menu entries, run the following command as root :

The file name /etc/grub2.cfg is a symlink to the grub.cfg file, whose location is architecture dependent. For reliability reasons, the symlink is not used in other examples in this chapter. It is better to use absolute paths when writing to a file, especially when repairing a system.

Changes to /etc/default/grub require rebuilding the grub.cfg file as follows:

On BIOS-based machines, issue the following command as root :

On UEFI-based machines, issue the following command as root :

Editing a Menu Entry

If required to prepare a new GRUB 2 file with different parameters, edit the values of the GRUB_CMDLINE_LINUX key in the /etc/default/grub file. Note that you can specify multiple parameters for the GRUB_CMDLINE_LINUX key. For example:

Where console=tty0 is the first virtual terminal and console=ttyS0 is the serial terminal to be used.

Changes to /etc/default/grub require rebuilding the grub.cfg file as follows:

On BIOS-based machines, issue the following command as root :

On UEFI-based machines, issue the following command as root :

Adding a new Entry

When executing the grub2-mkconfig command, GRUB 2 searches for Linux kernels and other operating systems based on the files located in the /etc/grub.d/ directory. The /etc/grub.d/10_linux script searches for installed Linux kernels on the same partition. The /etc/grub.d/30_os-prober script searches for other operating systems. Menu entries are also automatically added to the boot menu when updating the kernel.

The 40_custom file located in the /etc/grub.d/ directory is a template for custom entries and looks as follows:

This file can be edited or copied. Note that as a minimum, a valid menu entry must include at least the following:

Creating a Custom Menu

If you do not want menu entries to be updated automatically, you can create a custom menu.

Before proceeding, back up the contents of the /etc/grub.d/ directory in case you need to revert the changes later.

Note that modifying the /etc/default/grub file does not have any effect on creating custom menus.

On BIOS-based machines, copy the contents of /boot/grub2/grub.cfg , or, on UEFI machines, copy the contents of /boot/efi/EFI/fedora/grub.cfg . Put the content of the grub.cfg into the /etc/grub.d/40_custom file below the existing header lines. The executable part of the 40_custom script has to be preserved.

From the content put into the /etc/grub.d/40_custom file, only the menuentry blocks are needed to create the custom menu. The /boot/grub2/grub.cfg and /boot/efi/EFI/fedora/grub.cfg files might contain function specifications and other content above and below the menuentry blocks. If you put these unnecessary lines into the 40_custom file in the previous step, erase them.

This is an example of a custom 40_custom script:

Remove all files from the /etc/grub.d directory except the following:

Источник

Оцените статью