|
@@ -19,25 +19,29 @@
|
|
|
<sect2>
|
|
|
<title>Introduction</title>
|
|
|
|
|
|
- <para>Boot loading can be a complex area, so a few cautionary
|
|
|
- words are in order. Be familiar with the current boot loader and any other
|
|
|
- operating systems present on the hard drive(s) that need to be
|
|
|
- bootable. Make sure that an emergency boot disk is ready to
|
|
|
+ <warning><para>Configuring GRUB incorrectly can render your system
|
|
|
+ inoperable without an alternate boot device such as a CD-ROM. This
|
|
|
+ section is not required to boot your LFS system. You may just
|
|
|
+ want to modify your current boot loader, e.g. Grub-Legacy, GRUB2, or
|
|
|
+ LILO.</para></warning>
|
|
|
+
|
|
|
+
|
|
|
+ <para> Ensure that an emergency boot disk is ready to
|
|
|
<quote>rescue</quote> the computer if the computer becomes
|
|
|
- unusable (un-bootable).</para>
|
|
|
+ unusable (un-bootable). If you do not already have a boot device,
|
|
|
+ you can create one. In order for the procedure below to work,
|
|
|
+ you need to jump ahead to BLFS and install <ulink
|
|
|
+ url="http://www.linuxfromscratch.org/blfs/view/svn/multimedia/xorriso.html">
|
|
|
+ xorriso</ulink>.</para>
|
|
|
|
|
|
- <para>The procedure involves writing some special GRUB files to specific
|
|
|
- locations on the hard drive. We highly recommend creating a GRUB boot
|
|
|
- floppy diskette as a backup. Insert a blank floppy diskette and run the
|
|
|
- following commands:</para>
|
|
|
+<screen role="nodump"><userinput>cd /tmp &&
|
|
|
+grub-mkrescue --output=grub-img.iso &&
|
|
|
+xorriso -as cdrecord -v dev=/dev/cdrw blank=as_needed grub-img.iso</userinput></screen>
|
|
|
|
|
|
-<screen role="nodump"><userinput>cd /tmp
|
|
|
-grub-mkrescue --output=grub-img.iso
|
|
|
-dd if=grub-img.iso of=/dev/fd0 bs=1440 count=1</userinput></screen>
|
|
|
+ </sect2>
|
|
|
|
|
|
- <para>Alternatively, a boot CD can be created by using your host system's
|
|
|
- CD burning tools to burn the <filename>grub-img.iso</filename> on to a
|
|
|
- blank CD.</para>
|
|
|
+ <sect2>
|
|
|
+ <title>GRUB Naming Conventions</title>
|
|
|
|
|
|
<para>GRUB uses its own naming structure for drives and partitions in
|
|
|
the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis>
|
|
@@ -59,6 +63,16 @@ dd if=grub-img.iso of=/dev/fd0 bs=1440 count=1</userinput></screen>
|
|
|
<screen role="nodump"><userinput>grub-mkdevicemap --device-map=device.map
|
|
|
cat device.map</userinput></screen>
|
|
|
|
|
|
+ </sect2>
|
|
|
+
|
|
|
+ <sect2>
|
|
|
+ <title>Setting Up the Configuration</title>
|
|
|
+
|
|
|
+ <para>GRUB works by writing data to the first physical track of the
|
|
|
+ hard disk. This area is not part of any file system. The programs
|
|
|
+ there access GRUB modules in the boot partition. The default location
|
|
|
+ is /boot/grub/.</para>
|
|
|
+
|
|
|
<para>The location of the boot partition is a choice of the user that
|
|
|
affects the configuration. One recommendation is to have a separate small
|
|
|
(suggested size is 100 MB) partition just for boot information. That way
|
|
@@ -73,10 +87,6 @@ cat device.map</userinput></screen>
|
|
|
|
|
|
<para>Using the current lfs partition will also work, but configuration
|
|
|
for multiple systems is more difficult.</para>
|
|
|
- </sect2>
|
|
|
-
|
|
|
- <sect2>
|
|
|
- <title>Setting Up the Configuration</title>
|
|
|
|
|
|
<para>Using the above information, determine the appropriate
|
|
|
designator for the root partition (or boot partition, if a separate
|
|
@@ -85,175 +95,58 @@ cat device.map</userinput></screen>
|
|
|
class="partition">sda2</filename>.</para>
|
|
|
|
|
|
<para>Install the GRUB files into <filename
|
|
|
- class="directory">/boot/grub</filename>:</para>
|
|
|
-
|
|
|
-<screen role="nodump"><userinput>grub-install --grub-setup=/bin/true /dev/sda</userinput></screen>
|
|
|
-
|
|
|
- <para>We use --grub-setup=/bin/true for now to prevent updating the
|
|
|
- Master Boot Record (MBR). In this way, we can test our installation
|
|
|
- before committing to a change that is hard to revert.</para>
|
|
|
+ class="directory">/boot/grub</filename> and set up the boot track:</para>
|
|
|
|
|
|
- <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para>
|
|
|
+ <warning>
|
|
|
+ <para>The following command will overwrite the current boot loader. Do not
|
|
|
+ run the command if this is not desired, for example, if using a third party
|
|
|
+ boot manager to manage the Master Boot Record (MBR).</para>
|
|
|
+ </warning>
|
|
|
|
|
|
-<screen role="nodump"><userinput>grub-mkconfig -o /boot/grub/grub.cfg</userinput></screen>
|
|
|
+<screen role="nodump"><userinput>grub-install /dev/sda</userinput></screen>
|
|
|
|
|
|
- <para>Here <command>grub-mkconfig</command> uses the files in <filename
|
|
|
- class="directory">/etc/grub.d/</filename> to determine the contents
|
|
|
- of this file. The configuration file will look something like:</para>
|
|
|
-<screen><computeroutput>#
|
|
|
-# DO NOT EDIT THIS FILE
|
|
|
-#
|
|
|
-# It is automatically generated by /usr/sbin/grub-mkconfig using templates
|
|
|
-# from /etc/grub.d and settings from /etc/default/grub
|
|
|
-#
|
|
|
+ <note><para><application>grub-install</application> is a script and calls another
|
|
|
+ program, grub-probe, that may fail with a message "cannot stat `/dev/root'".
|
|
|
+ If so, create a temporary symbolic link from your root partition to /dev/root:</para>
|
|
|
|
|
|
-### BEGIN /etc/grub.d/00_header ###
|
|
|
-set default=0
|
|
|
-set timeout=5
|
|
|
-### END /etc/grub.d/00_header ###
|
|
|
+<screen role="nodump"><userinput>ln -sv /dev/sda2 /dev/root</userinput></screen>
|
|
|
|
|
|
-### BEGIN /etc/grub.d/10_linux ###
|
|
|
-menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
|
|
|
- insmod ext2
|
|
|
- set root=(hd0,2)
|
|
|
- search --no-floppy --fs-uuid --set 915852a7-859e-45a6-9ff0-d3ebfdb5cea2
|
|
|
- linux /boot/vmlinux-&linux-version;-lfs-&version; root=/dev/sda2 ro
|
|
|
-}
|
|
|
-menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" (recovery mode)" {
|
|
|
- insmod ext2
|
|
|
- set root=(hd0,2)
|
|
|
- search --no-floppy --fs-uuid --set 915852a7-859e-45a6-9ff0-d3ebfdb5cea2
|
|
|
- linux /boot/vmlinux-&linux-version;-lfs-&version; root=/dev/sda2 ro single
|
|
|
-}
|
|
|
-menuentry "GNU/Linux, Linux 2.6.28-11-server" {
|
|
|
- insmod ext2
|
|
|
- set root=(hd0,2)
|
|
|
- search --no-floppy --fs-uuid --set 6b4c0339-5501-4a85-8351-e398e5252be8
|
|
|
- linux /boot/vmlinuz-2.6.28-11-server root=UUID=6b4c0339-5501-4a85-8351-e398e5252be8 ro
|
|
|
- initrd /boot/initrd.img-2.6.28-11-server
|
|
|
-}
|
|
|
-menuentry "GNU/Linux, Linux 2.6.28-11-server (recovery mode)" {
|
|
|
- insmod ext2
|
|
|
- set root=(hd0,2)
|
|
|
- search --no-floppy --fs-uuid --set 6b4c0339-5501-4a85-8351-e398e5252be8
|
|
|
- linux /boot/vmlinuz-2.6.28-11-server root=UUID=6b4c0339-5501-4a85-8351-e398e5252be8 ro single
|
|
|
- initrd /boot/initrd.img-2.6.28-11-server
|
|
|
-}
|
|
|
-### END /etc/grub.d/10_linux ###
|
|
|
-
|
|
|
-### BEGIN /etc/grub.d/30_os-prober ###
|
|
|
-### END /etc/grub.d/30_os-prober ###
|
|
|
-
|
|
|
-### BEGIN /etc/grub.d/40_custom ###
|
|
|
-# This file provides an easy way to add custom menu entries. Simply type the
|
|
|
-# menu entries you want to add after this comment. Be careful not to change
|
|
|
-# the 'exec tail' line above.
|
|
|
-### END /etc/grub.d/40_custom ###
|
|
|
-</computeroutput></screen>
|
|
|
-
|
|
|
- <note>
|
|
|
- <itemizedlist>
|
|
|
- <listitem><para>Even though there is a warning not to edit the file, you
|
|
|
- can do so as long as you do not re-run
|
|
|
- <command>grub-mkconfig</command>.</para></listitem>
|
|
|
-
|
|
|
- <listitem><para>The <emphasis>search</emphasis> lines are generally not
|
|
|
- useful for LFS systems as that command only sets an internal GRUB
|
|
|
- variable used to find the kernel image. The <emphasis>set root</emphasis>
|
|
|
- command provides the same capability without the overhead of
|
|
|
- searching.</para></listitem>
|
|
|
-
|
|
|
- <listitem><para>The <emphasis>set root</emphasis> and
|
|
|
- <emphasis>insmod ext2</emphasis> commands can be moved out of the
|
|
|
- <emphasis>menuentry</emphasis> sections to apply to all sections of the file.
|
|
|
- This leads to a simple section like:</para></listitem>
|
|
|
-
|
|
|
- </itemizedlist>
|
|
|
-<screen><computeroutput>menuentry "Linux &linux-version;-lfs-&version;" {
|
|
|
-linux /boot/vmlinux-&linux-version;-lfs-&version; root=/dev/sda2 ro
|
|
|
-}
|
|
|
-</computeroutput></screen>
|
|
|
-
|
|
|
- <itemizedlist>
|
|
|
-
|
|
|
- <listitem><para>Passing a UUID to the kernel requires an initial ram disk
|
|
|
- (initrd) not built by LFS.</para></listitem>
|
|
|
-
|
|
|
- <listitem><para>If the <filename>/boot</filename> partition is installed
|
|
|
- on a separate partition, the linux and initrd lines should not have the
|
|
|
- string <emphasis>/boot</emphasis> prefixed to the file
|
|
|
- names.</para></listitem>
|
|
|
-
|
|
|
- <listitem><para>In this example the kernel files for a Ubuntu
|
|
|
- installation are also found in <filename
|
|
|
- class="directory">/boot</filename>.</para></listitem>
|
|
|
-
|
|
|
- </itemizedlist>
|
|
|
- </note>
|
|
|
+ <para>The symbolic link will only be present until the system is rebooted.
|
|
|
+ The link is only needed for the installation procedure.
|
|
|
+ </para></note>
|
|
|
|
|
|
</sect2>
|
|
|
-
|
|
|
- <sect2>
|
|
|
- <title>Testing the Configuration</title>
|
|
|
-
|
|
|
- <para>The core image of GRUB is also a Multiboot kernel, so if you already
|
|
|
- have <emphasis>GRUB Legacy</emphasis> loaded you can load
|
|
|
- GRUB-&grub-version; through your old boot loader. To accomplish this, you
|
|
|
- will need to exit the <command>chroot</command> environment now and
|
|
|
- re-enter it in the next section to finish the few remaining portions of
|
|
|
- the book.</para>
|
|
|
-
|
|
|
-<screen role="nodump"><userinput>/sbin/reboot
|
|
|
-...
|
|
|
-grub> root (hd0,1)
|
|
|
-grub> kernel /boot/grub/core.img
|
|
|
-grub> boot</userinput></screen>
|
|
|
-
|
|
|
- <para>Note that the GRUB commands above are assumed to be GRUB Legacy.
|
|
|
- At this point the GRUB prompt will appear (very similar to GRUB Legacy) and
|
|
|
- you can explore the interface or boot to one of the systems in the grub.cfg
|
|
|
- file.</para>
|
|
|
-
|
|
|
- </sect2>
|
|
|
|
|
|
<sect2>
|
|
|
- <title>Updating the Master Boot Record</title>
|
|
|
-
|
|
|
- <para>If you tested the GRUB configuration as specified above, re-enter
|
|
|
- the <command>chroot</command> environment.</para>
|
|
|
+ <title>Creating the Configuration File</title>
|
|
|
|
|
|
- <warning>
|
|
|
- <para>The following command will overwrite the current boot loader. Do not
|
|
|
- run the command if this is not desired, for example, if using a third party
|
|
|
- boot manager to manage the Master Boot Record (MBR).</para>
|
|
|
- </warning>
|
|
|
-
|
|
|
- <para>Update the MBR with:</para>
|
|
|
-
|
|
|
-<screen role="nodump"><userinput>grub-setup '<DEVICE>'</userinput></screen>
|
|
|
-
|
|
|
- <para>Change the DEVICE above to your boot disk, normally '(hd0)' or /dev/sda.
|
|
|
- If using (hd0) be sure to escape the parentheses with backslashes or single
|
|
|
- quotes to prevent the shell from interpreting them as a sub-shell.</para>
|
|
|
+ <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para>
|
|
|
|
|
|
- <para>This program uses the following defaults and are correct if you did not
|
|
|
- deviate from the instructions above:</para>
|
|
|
+ <screen><userinput>cat > /boot/grub/grub.cfg << "EOF"
|
|
|
+<literal># Begin /boot/grub/grub.cfg
|
|
|
+set default=0
|
|
|
+set timeout=5
|
|
|
|
|
|
- <itemizedlist>
|
|
|
- <listitem><para>boot image - boot.img </para></listitem>
|
|
|
- <listitem><para>core image - core.img </para></listitem>
|
|
|
- <listitem><para>directory - /boot/grub</para></listitem>
|
|
|
- <listitem><para>device map - device.map</para></listitem>
|
|
|
- <listitem><para>default root setting - guessed</para></listitem>
|
|
|
- </itemizedlist>
|
|
|
+insmod ext2
|
|
|
+set root=(hd0,2)
|
|
|
|
|
|
- <note><para>The root setting is the default value if a 'set root'
|
|
|
- instruction is not found in grub.cfg. This is the partition that is
|
|
|
- searched for the kernel and other supporting files. It is different from
|
|
|
- the 'root=' parameter on the 'linux' line in the configuration line. The
|
|
|
- latter is the partition the kernel mounts as '/'. In the example grub.cfg
|
|
|
- above, both values point to /dev/sda2, but if there is a separate boot
|
|
|
- partition, they will be different.</para></note>
|
|
|
+menuentry "GNU/Linux, Linux &linux-version;-lfs-&version;" {
|
|
|
+ linux /boot/vmlinux-&linux-version;-lfs-&version; root=/dev/sda2 ro
|
|
|
+}</literal>
|
|
|
+EOF</userinput></screen>
|
|
|
+
|
|
|
+ <para>GRUB is an extremely powerful program and it provides a tremendous
|
|
|
+ number of options for booting from a wide variety of devices, operating
|
|
|
+ systems, and partition types. There are also many options for customization
|
|
|
+ such as graphical splash screens, playing sounds, mouse input, etc. The
|
|
|
+ details of these options are beyond the scope of this introduction.</para>
|
|
|
+
|
|
|
+ <note><para>There is a command, <application>grub-mkconfig</application> that
|
|
|
+ can write a configuration file automatically. It uses a set of scripts in
|
|
|
+ /etc/grub.d/ and will destroy any customizations that you make. These scripts
|
|
|
+ are designed primarily for non-source distributions and are not recommended for
|
|
|
+ LFS. If you install a commercial Linux distribution, there is a good chance
|
|
|
+ that this program will be run. Be sure to back up your grub.cfg file.</para></note>
|
|
|
|
|
|
</sect2>
|
|
|
|