[7152faa] | 1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
[fcc02767] | 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
| 4 | <!ENTITY % general-entities SYSTEM "../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
| 7 |
|
---|
| 8 | <sect1 id="ch-bootable-grub" role="wrap">
|
---|
| 9 | <?dbhtml filename="grub.html"?>
|
---|
| 10 |
|
---|
| 11 | <sect1info condition="script">
|
---|
| 12 | <productname>grub</productname>
|
---|
| 13 | <productnumber>&grub-version;</productnumber>
|
---|
| 14 | <address>&grub-url;</address>
|
---|
| 15 | </sect1info>
|
---|
| 16 |
|
---|
| 17 | <title>Using GRUB to Set Up the Boot Process</title>
|
---|
| 18 |
|
---|
[1c16a05] | 19 | <note>
|
---|
| 20 | <para>
|
---|
[d89cc558] | 21 | This section assume your system has UEFI support and you wish to boot
|
---|
[7c1451f] | 22 | LFS with UEFI.
|
---|
[d89cc558] | 23 | If your system does not support UEFI or you don't want to use it,
|
---|
| 24 | you'll need to figure out how to configure the booting process of
|
---|
| 25 | the system on your own.
|
---|
[1c16a05] | 26 | </para>
|
---|
| 27 | </note>
|
---|
| 28 |
|
---|
[fcc02767] | 29 | <sect2>
|
---|
| 30 | <title>Introduction</title>
|
---|
| 31 |
|
---|
| 32 | <warning><para>Configuring GRUB incorrectly can render your system
|
---|
[37b5ac1] | 33 | inoperable without an alternate boot device such as a CD-ROM or bootable
|
---|
| 34 | USB drive. This section is not required to boot your LFS system. You may
|
---|
| 35 | just want to modify your current boot loader, e.g. Grub-Legacy, GRUB2, or
|
---|
[fcc02767] | 36 | LILO.</para></warning>
|
---|
| 37 |
|
---|
[d89cc558] | 38 | <para>Ensure that an emergency boot disk is ready to <quote>rescue</quote>
|
---|
[fcc02767] | 39 | the computer if the computer becomes unusable (un-bootable). If you do not
|
---|
[d89cc558] | 40 | already have a boot device, you can create one. To create a emergency
|
---|
| 41 | boot device for UEFI, consult section <quote>Create an Emergency Boot
|
---|
| 42 | Disk</quote> in
|
---|
| 43 | <ulink url="&blfs-book;postlfs/grub-setup.html">the BLFS page</ulink>.</para>
|
---|
[fcc02767] | 44 |
|
---|
[d89cc558] | 45 | </sect2>
|
---|
| 46 |
|
---|
| 47 | <sect2>
|
---|
| 48 | <title>Turn off Secure Boot</title>
|
---|
[fcc02767] | 49 |
|
---|
[d89cc558] | 50 | <para>LFS does not have the essential packages to support Secure Boot.
|
---|
| 51 | To set up the boot process following the instructions in this section,
|
---|
| 52 | Secure Boot must be turned off from the configuration interface of the
|
---|
| 53 | firmware. Read the documentation provided by the manufacturer of your
|
---|
| 54 | system to find out how.</para>
|
---|
[fcc02767] | 55 | </sect2>
|
---|
| 56 |
|
---|
| 57 | <sect2>
|
---|
| 58 | <title>GRUB Naming Conventions</title>
|
---|
| 59 |
|
---|
| 60 | <para>GRUB uses its own naming structure for drives and partitions in
|
---|
| 61 | the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis>
|
---|
| 62 | is the hard drive number and <emphasis>m</emphasis> is the partition
|
---|
[8190ca0] | 63 | number. The hard drive numbers start from zero, but the partition numbers
|
---|
| 64 | start from one for normal partitions (from five for extended partitions).
|
---|
[fcc02767] | 65 | Note that this is different from earlier versions where
|
---|
| 66 | both numbers started from zero. For example, partition <filename
|
---|
| 67 | class="partition">sda1</filename> is <emphasis>(hd0,1)</emphasis> to
|
---|
| 68 | GRUB and <filename class="partition">sdb3</filename> is
|
---|
| 69 | <emphasis>(hd1,3)</emphasis>. In contrast to Linux, GRUB does not
|
---|
| 70 | consider CD-ROM drives to be hard drives. For example, if using a CD
|
---|
| 71 | on <filename class="partition">hdb</filename> and a second hard drive
|
---|
| 72 | on <filename class="partition">hdc</filename>, that second hard drive
|
---|
| 73 | would still be <emphasis>(hd1)</emphasis>.</para>
|
---|
| 74 |
|
---|
| 75 | </sect2>
|
---|
| 76 |
|
---|
| 77 | <sect2>
|
---|
| 78 | <title>Setting Up the Configuration</title>
|
---|
| 79 |
|
---|
[d89cc558] | 80 | <para>GRUB works by creating an EFI executable in the EFI System
|
---|
| 81 | Partition (ESP). You can find the ESP with:</para>
|
---|
| 82 |
|
---|
| 83 | <screen role="nodump"><userinput>fdisk -l | grep 'EFI System'</userinput></screen>
|
---|
| 84 |
|
---|
| 85 | <para>If no ESP exists on your hard drive (for example, you are building
|
---|
| 86 | LFS on a fresh new system with a Live CD as the host distro), read
|
---|
| 87 | <ulink url="&blfs-book;postlfs/grub-setup.html">the BLFS page</ulink>
|
---|
| 88 | for the instruction to create an ESP on your hard drive.</para>
|
---|
| 89 |
|
---|
| 90 | <para>If the ESP is not mounted at
|
---|
| 91 | <filename class="directory">/boot/efi</filename> (in the chroot),
|
---|
| 92 | mount it now:</para>
|
---|
| 93 |
|
---|
| 94 | <screen role="nodump"><userinput>mkdir -pv /boot/efi
|
---|
| 95 | mount /boot/efi</userinput></screen>
|
---|
| 96 |
|
---|
| 97 | <note>
|
---|
| 98 | <para>The path to the device node is intentionally omitted in the
|
---|
| 99 | command. We expect the entry for mounting the ESP to
|
---|
| 100 | <filename class="directory">/boot/efi</filename> is already in
|
---|
| 101 | <filename>/etc/fstab</filename>. Add the entry before running the
|
---|
| 102 | command if you forgot to create an entry for the ESP in
|
---|
| 103 | <xref linkend="ch-bootable-fstab"/>.</para>
|
---|
| 104 | </note>
|
---|
[fcc02767] | 105 |
|
---|
| 106 | <para>The location of the boot partition is a choice of the user that
|
---|
| 107 | affects the configuration. One recommendation is to have a separate small
|
---|
[37b5ac1] | 108 | (suggested size is 200 MB) partition just for boot information. That way
|
---|
[fcc02767] | 109 | each build, whether LFS or some commercial distro, can access the same boot
|
---|
| 110 | files and access can be made from any booted system. If you choose to do
|
---|
| 111 | this, you will need to mount the separate partition, move all files in the
|
---|
| 112 | current <filename class="directory">/boot</filename> directory (e.g. the
|
---|
[8190ca0] | 113 | Linux kernel you just built in the previous section) to the new partition.
|
---|
[fcc02767] | 114 | You will then need to unmount the partition and remount it as <filename
|
---|
| 115 | class="directory">/boot</filename>. If you do this, be sure to update
|
---|
| 116 | <filename>/etc/fstab</filename>.</para>
|
---|
| 117 |
|
---|
[c7f74cd] | 118 | <para>Leaving <filename class="directory">/boot</filename> on
|
---|
[8190ca0] | 119 | the current LFS partition will also work, but configuration
|
---|
[fcc02767] | 120 | for multiple systems is more difficult.</para>
|
---|
| 121 |
|
---|
| 122 | <para>Using the above information, determine the appropriate
|
---|
| 123 | designator for the root partition (or boot partition, if a separate
|
---|
| 124 | one is used). For the following example, it is assumed that the root
|
---|
| 125 | (or separate boot) partition is <filename
|
---|
| 126 | class="partition">sda2</filename>.</para>
|
---|
| 127 |
|
---|
| 128 | <para>Install the GRUB files into <filename
|
---|
[d89cc558] | 129 | class="directory">/boot/grub</filename> and the GRUB EFI executable into
|
---|
[c423f883] | 130 | <filename>/boot/efi/EFI/BOOT/BOOTLOONGARCH64.EFI</filename>:</para>
|
---|
[fcc02767] | 131 |
|
---|
| 132 | <warning>
|
---|
[d89cc558] | 133 | <para>The following command will overwrite
|
---|
| 134 | <filename>BOOTLOONGARCH64.EFI</filename>. Do not run the command if
|
---|
| 135 | this is not desired, for example, if it contains a third party boot
|
---|
| 136 | manager. You can backup it with <command>cp</command> as it's a
|
---|
| 137 | regular file.</para>
|
---|
[fcc02767] | 138 | </warning>
|
---|
| 139 |
|
---|
[d89cc558] | 140 | <screen role="nodump"><userinput>grub-install --removable</userinput></screen>
|
---|
[fcc02767] | 141 |
|
---|
| 142 | <note>
|
---|
[d89cc558] | 143 | <para>
|
---|
| 144 | <parameter>--removable</parameter> may seem strange here. The UEFI
|
---|
| 145 | firmware searches EFI executables for boot loaders in a hardcoded
|
---|
| 146 | path, <filename>EFI/BOOT/BOOTLOONGARCH64.EFI</filename> in the ESP, and other
|
---|
| 147 | boot loader paths listed in the EFI variables. We've not installed
|
---|
| 148 | the utilities for manipulating EFI variables so we need to install
|
---|
| 149 | the EFI executable into the hardcoded path. The hardcoded path is
|
---|
| 150 | usually used by removable devices (for example, USB thumb devices)
|
---|
| 151 | so the <command>grub-install</command> option for this purpose is
|
---|
| 152 | named <parameter>--removable</parameter>.
|
---|
| 153 | </para>
|
---|
| 154 | <para>
|
---|
| 155 | UEFI implementation usually prefers the boot loaders with paths
|
---|
| 156 | recorded in an EFI variable, to the boot loader with the hardcoded
|
---|
| 157 | search path. You may need to invoke the boot device selection menu
|
---|
| 158 | or setting interface of your EFI firmware on next boot to explicitly
|
---|
| 159 | select the bootloader.
|
---|
| 160 | </para>
|
---|
| 161 | <para>
|
---|
| 162 | Some UEFI implementation may completely skip the hardcoded path if
|
---|
| 163 | there are other boot loaders in the same hard drive with paths
|
---|
| 164 | recorded in an EFI variable. Then you need to create an EFI
|
---|
| 165 | variable for the newly installed boot loader. Install
|
---|
| 166 | <ulink url="&blfs-book;postlfs/efibootmgr.html">efibootmgr</ulink>,
|
---|
[7c1451f] | 167 | and follow
|
---|
| 168 | <ulink url="&blfs-book;postlfs/grub-setup.html">the BLFS
|
---|
| 169 | instruction</ulink> to run the <command>grub-install</command>
|
---|
| 170 | command without the <parameter>--removable</parameter> option then.
|
---|
[d89cc558] | 171 | </para>
|
---|
[fcc02767] | 172 | </note>
|
---|
| 173 |
|
---|
| 174 | </sect2>
|
---|
| 175 |
|
---|
| 176 | <sect2 id="grub-cfg">
|
---|
| 177 | <title>Creating the GRUB Configuration File</title>
|
---|
| 178 |
|
---|
| 179 | <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para>
|
---|
| 180 |
|
---|
[3d7b4f6] | 181 | <screen><userinput>cat > /boot/grub/grub.cfg << "EOF"
|
---|
[fcc02767] | 182 | <literal># Begin /boot/grub/grub.cfg
|
---|
| 183 | set default=0
|
---|
| 184 | set timeout=5
|
---|
| 185 |
|
---|
[67ca5ef] | 186 | insmod part_gpt
|
---|
[fcc02767] | 187 | insmod ext2
|
---|
| 188 | set root=(hd0,2)
|
---|
| 189 |
|
---|
[7e06ddd] | 190 | insmod efi_gop
|
---|
| 191 | insmod efi_uga
|
---|
[d89cc558] | 192 |
|
---|
[fcc02767] | 193 | menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
|
---|
| 194 | linux /boot/vmlinuz-&linux-version;-lfs-&version; root=/dev/sda2 ro
|
---|
| 195 | }</literal>
|
---|
| 196 | EOF</userinput></screen>
|
---|
| 197 |
|
---|
[93ec8b3] | 198 | <para>
|
---|
| 199 | The <command>insmod</command> commands load the
|
---|
| 200 | <application>GRUB</application> modules named
|
---|
| 201 | <filename>part_gpt</filename> and <filename>ext2</filename>.
|
---|
| 202 | Despite the naming, <filename>ext2</filename> actually supports
|
---|
| 203 | <systemitem class='filesystem'>ext2</systemitem>,
|
---|
| 204 | <systemitem class='filesystem'>ext3</systemitem>, and
|
---|
| 205 | <systemitem class='filesystem'>ext4</systemitem> filesystems.
|
---|
| 206 | The <command>grub-install</command> command has embedded some modules
|
---|
| 207 | into the main <application>GRUB</application> image (installed into
|
---|
| 208 | the MBR or the GRUB BIOS partition) to access the other modules
|
---|
| 209 | (in <filename class='directory'>/boot/grub/i386-pc</filename>) without
|
---|
| 210 | a chicken-or-egg issue, so with a typical configuration these two
|
---|
| 211 | modules are already embedded and those two <command>insmod</command>
|
---|
| 212 | commands will do nothing. But they do no harm anyway, and they may
|
---|
| 213 | be needed with some rare configurations.
|
---|
| 214 | </para>
|
---|
| 215 |
|
---|
[fcc02767] | 216 | <note><para>From <application>GRUB</application>'s perspective, the
|
---|
| 217 | kernel files are relative to the partition used. If you
|
---|
| 218 | used a separate /boot partition, remove /boot from the above
|
---|
| 219 | <emphasis>linux</emphasis> line. You will also need to change the
|
---|
| 220 | <emphasis>set root</emphasis> line to point to the boot partition.
|
---|
| 221 | </para></note>
|
---|
| 222 |
|
---|
[5353a19] | 223 | <note>
|
---|
| 224 | <para>The GRUB designator for a partition may change if you added or
|
---|
| 225 | removed some disks (including removable disks like USB thumb devices).
|
---|
| 226 | The change may cause boot failure because
|
---|
| 227 | <filename>grub.cfg</filename> refers to some <quote>old</quote>
|
---|
| 228 | designators. If you wish to avoid such a problem, you may use
|
---|
[8190ca0] | 229 | the UUID of a partition and the UUID of a filesystem instead of a GRUB designator to
|
---|
| 230 | specify a device.
|
---|
[5353a19] | 231 | Run <command>lsblk -o UUID,PARTUUID,PATH,MOUNTPOINT</command> to show
|
---|
[8190ca0] | 232 | the UUIDs of your filesystems (in the <literal>UUID</literal> column) and
|
---|
| 233 | partitions (in the <literal>PARTUUID</literal> column). Then replace
|
---|
[5353a19] | 234 | <literal>set root=(hdx,y)</literal> with
|
---|
[8190ca0] | 235 | <literal>search --set=root --fs-uuid <replaceable><UUID of the filesystem
|
---|
| 236 | where the kernel is installed></replaceable></literal>, and replace
|
---|
[5353a19] | 237 | <literal>root=/dev/sda2</literal> with
|
---|
[8190ca0] | 238 | <literal>root=PARTUUID=<replaceable><UUID of the partition where LFS
|
---|
| 239 | is built></replaceable></literal>.</para>
|
---|
| 240 | <para>Note that the UUID of a partition is completely different from the
|
---|
| 241 | UUID of the filesystem in this partition. Some online resources may
|
---|
[5353a19] | 242 | instruct you to use
|
---|
| 243 | <literal>root=UUID=<replaceable><filesystem UUID></replaceable></literal>
|
---|
| 244 | instead of
|
---|
| 245 | <literal>root=PARTUUID=<replaceable><partition UUID></replaceable></literal>,
|
---|
[8190ca0] | 246 | but doing so will require an initramfs, which is beyond the scope of
|
---|
[5353a19] | 247 | LFS.</para>
|
---|
| 248 | <para>The name of the device node for a partition in
|
---|
[8190ca0] | 249 | <filename class='directory'>/dev</filename> may also change (this is less
|
---|
| 250 | likely than a GRUB designator change). You can also replace
|
---|
[5353a19] | 251 | paths to device nodes like <literal>/dev/sda1</literal> with
|
---|
| 252 | <literal>PARTUUID=<replaceable><partition UUID></replaceable></literal>,
|
---|
| 253 | in <filename>/etc/fstab</filename>, to avoid a potential boot failure
|
---|
| 254 | in case the device node name has changed.</para>
|
---|
| 255 | </note>
|
---|
| 256 |
|
---|
[fcc02767] | 257 | <para>GRUB is an extremely powerful program and it provides a tremendous
|
---|
| 258 | number of options for booting from a wide variety of devices, operating
|
---|
| 259 | systems, and partition types. There are also many options for customization
|
---|
| 260 | such as graphical splash screens, playing sounds, mouse input, etc. The
|
---|
| 261 | details of these options are beyond the scope of this introduction.</para>
|
---|
| 262 |
|
---|
| 263 | <caution><para>There is a command, <application>grub-mkconfig</application>, that
|
---|
| 264 | can write a configuration file automatically. It uses a set of scripts in
|
---|
| 265 | /etc/grub.d/ and will destroy any customizations that you make. These scripts
|
---|
| 266 | are designed primarily for non-source distributions and are not recommended for
|
---|
| 267 | LFS. If you install a commercial Linux distribution, there is a good chance
|
---|
| 268 | that this program will be run. Be sure to back up your grub.cfg file.</para></caution>
|
---|
| 269 |
|
---|
| 270 | </sect2>
|
---|
| 271 |
|
---|
| 272 | </sect1>
|
---|