diff options
Diffstat (limited to 'chapter08')
-rw-r--r-- | chapter08/grub.xml | 411 | ||||
-rw-r--r-- | chapter08/kernel.xml | 9 |
2 files changed, 164 insertions, 256 deletions
diff --git a/chapter08/grub.xml b/chapter08/grub.xml index f8c4efcad..bfe9bc510 100644 --- a/chapter08/grub.xml +++ b/chapter08/grub.xml @@ -14,96 +14,10 @@ <address>&grub-url;</address> </sect1info> - <title>GRUB-&grub-version;</title> - - <indexterm zone="ch-bootable-grub"> - <primary sortas="a-Grub">GRUB</primary> - </indexterm> - - <sect2 role="package"> - <title/> - - <para>The GRUB package contains the GRand Unified Bootloader.</para> - - <segmentedlist> - <segtitle>&buildtime;</segtitle> - <segtitle>&diskspace;</segtitle> - - <seglistitem> - <seg>&grub-ch6-sbu;</seg> - <seg>&grub-ch6-du;</seg> - </seglistitem> - </segmentedlist> - - </sect2> - - <sect2 role="installation"> - <title>Installation of GRUB</title> - - <para>Your shiny new LFS system is almost complete. One of the last - things to do is to ensure that the system can be properly booted.</para> - - <caution> - <para>This package will only build for x86 and x86_64 architectures - containing 32-bit libs. If you chose to build on x86_64 without 32-bit - libraries (no multilib), then you must use LILO instead. Information on - <quote>boot loading</quote> for other architectures should be available in - the usual resource-specific locations for those architectures.</para> - </caution> - - <para>This package is known to have issues when its default - optimization flags (including the <parameter>-march</parameter> and - <parameter>-mcpu</parameter> options) are changed. If any environment - variables that override default optimizations have been defined, such - as <envar>CFLAGS</envar> and <envar>CXXFLAGS</envar>, - unset them when building GRUB.</para> - - <para>Start by applying the following patch to allow for better drive - detection, fix some GCC 4.x issues, and provide better SATA support - for some disk controllers:</para> - -<screen><userinput remap="pre">patch -Np1 -i ../&grub-geometry-patch;</userinput></screen> - - <para>By default, GRUB doesn't support ext2 filesystems with 256-byte inodes. - Fix this by applying the following patch:</para> - -<screen><userinput remap="pre">patch -Np1 -i ../&grub-inode-patch;</userinput></screen> - - <para>Prepare GRUB for compilation:</para> - -<screen><userinput remap="configure">./configure --prefix=/usr</userinput></screen> - - <para>Compile the package, but use custom optimization flags to - prevent an error flagged in the test routines:</para> - -<screen><userinput remap="make">make CFLAGS="-march=i486 -mtune=native -Os"</userinput></screen> - - <para>To test the results, issue:</para> - -<screen><userinput remap="test">make check</userinput></screen> - - <para>Install the package:</para> - -<screen><userinput remap="install">make install -mkdir -v /boot/grub -cp -v /usr/lib/grub/i386-pc/stage{1,2} /boot/grub</userinput></screen> - - <para>Replace <filename class="directory">i386-pc</filename> with whatever - directory is appropriate for the hardware in use.</para> - - <para>The <filename class="directory">i386-pc</filename> directory - contains a number of <filename>*stage1_5</filename> files, different - ones for different file systems. Review the files available and copy - the appropriate ones to the <filename - class="directory">/boot/grub</filename> directory. Most users will - copy the <filename>e2fs_stage1_5</filename> and/or - <filename>reiserfs_stage1_5</filename> files.</para> - - </sect2> - - <sect2 role="configuration"> - <title>Configuring GRUB</title> + <title>Using GRUB to Set Up the Boot Process</title> + <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 @@ -113,194 +27,185 @@ cp -v /usr/lib/grub/i386-pc/stage{1,2} /boot/grub</userinput></screen> unusable (un-bootable).</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><userinput>dd if=/boot/grub/stage1 of=/dev/fd0 bs=512 count=1 -dd if=/boot/grub/stage2 of=/dev/fd0 bs=512 seek=1</userinput></screen> - - <para>Remove the diskette and store it somewhere safe. Now, run the - <command>grub</command> shell:</para> + 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><userinput>grub</userinput></screen> +<screen role="nodump"><userinput>cd /tmp +grub-mkrescue --image-type=floppy floppy.img +dd if=floppy.img of =/def/fd0 bs=1440 count=1</userinput></screen> <para>GRUB uses its own naming structure for drives and partitions in the form of <emphasis>(hdn,m)</emphasis>, where <emphasis>n</emphasis> is the hard drive number and <emphasis>m</emphasis> is the partition - number, both starting from zero. For example, partition <filename - class="partition">hda1</filename> is <emphasis>(hd0,0)</emphasis> to - GRUB and <filename class="partition">hdb3</filename> is - <emphasis>(hd1,2)</emphasis>. In contrast to Linux, GRUB does not + number. The hard drive number starts from zero, but he partition number + starts from one for normal partitions and five for extended partitions. + Note that this is different form earlier versions where + both numbers started from zero. For example, partition <filename + class="partition">sda1</filename> is <emphasis>(hd0,1)</emphasis> to + GRUB and <filename class="partition">sdb3</filename> is + <emphasis>(hd1,3)</emphasis>. In contrast to Linux, GRUB does not consider CD-ROM drives to be hard drives. For example, if using a CD on <filename class="partition">hdb</filename> and a second hard drive on <filename class="partition">hdc</filename>, that second hard drive would still be <emphasis>(hd1)</emphasis>.</para> + <para>You can determine what GRUB thinks your disk devices are by running:</para> + +<screen role="nodump"><userinput>grub-mkdevicemap --verbose --device-map=device.map +cat device.map</userinput></screen> + + <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 + each build, whether LFS or some commercial distro, can access the same boot + files and access can be made from any booted system. If you choose to do + this, you will need to mount the separate partition, move all files in the + current <filename class="directory">/boot</filename> directory (e.g. the + linux kernel you just built in the previous section) to the new partition. + You will then need to unmount the partition and remount it as <filename + class="directory">/boot</filename>. If you do this, be sure to update + <filename>/etc/fstab</filename>.</para> + + <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 one is used). For the following example, it is assumed that the root (or separate boot) partition is <filename - class="partition">hda4</filename>.</para> + 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 update the + Master Boot Record (MBR). In this way, we can test our installation + before committing to a change that is hard to revert.</para> + + <para>Generate <filename>/boot/grub/grub.cfg</filename>:</para> + +<screen role="nodump"><userinput>grub-mkconfig -o /boot/grub/grub.cfg</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 +# + +### BEGIN /etc/grub.d/00_header ### +set default=0 +set timeout=5 +### END /etc/grub.d/00_header ### + +### BEGIN /etc/grub.d/10_linux ### +menuentry "GNU/Linux, Linux 2.6.30.2-lfs65" { + 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 2.6.30.2-lfs65 (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> + + <para>Note that even though there is a warning not to edit the file, you can + do so as long as you do not re-reun <command>grub-mkconfig</command>. The + <emphasis>search</emphasis> lines are not meaningful for LFS systems as that + command needs an initrd image for processing. If installing on a separate + partition the linux and initrd lines will not have the /boot on the file + names. In this example the kernel files for a Ubuntu installation are + also found in <filename class="directory">/boot</filename>.</para> - <para>Tell GRUB where to search for its - <filename>stage{1,2}</filename> files. The Tab key can be used - everywhere to make GRUB show the alternatives:</para> - -<screen><userinput>root (hd0,3)</userinput></screen> + </sect2> + + <sect2> + <title>Testing the Configuration</title> + + <para>The core image of GRUB is also a Multiboot kernel, so if you already + have GRUB Legacy 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 and re-enter it 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> envronment.</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). In this scenario, it - would make more sense to install GRUB into the <quote>boot sector</quote> - of the LFS partition. In this case, this next command would become - <userinput>setup (hd0,3)</userinput>.</para> + boot manager to manage the Master Boot Record (MBR).</para> </warning> - <para>Tell GRUB to install itself into the MBR of - <filename class="partition">hda</filename>:</para> - -<screen><userinput>setup (hd0)</userinput></screen> - - <para>If all went well, GRUB will have reported finding its files in - <filename class="directory">/boot/grub</filename>. That's all there is - to it. Quit the <command>grub</command> shell:</para> - -<screen><userinput>quit</userinput></screen> - - <para>Create a <quote>menu list</quote> file defining GRUB's boot menu:</para> + <para>Update the MBR with:</para> -<screen><userinput>cat > /boot/grub/menu.lst << "EOF" -<literal># Begin /boot/grub/menu.lst +<screen role="nodump"><userinput>grub-setup</userinput></screen> -# By default boot the first menu entry. -default 0 + <para>This program uses the following defaults and are correct if you did not + deviate from the instructions above:</para> -# Allow 30 seconds before booting the default. -timeout 30 + <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>root device - guessed </para></listitem> + </itemizedlist> -# Use prettier colors. -color green/black light-green/black - -# The first entry is for LFS. -title LFS &version; -root (hd0,3) -kernel /boot/lfskernel-&linux-version; root=/dev/hda4</literal> -EOF</userinput></screen> - - <para>Add an entry for the host distribution if desired. It might look - like this:</para> - -<screen><userinput>cat >> /boot/grub/menu.lst << "EOF" -<literal>title Red Hat -root (hd0,2) -kernel /boot/kernel-2.6.5 root=/dev/hda3 -initrd /boot/initrd-2.6.5</literal> -EOF</userinput></screen> - - <para>If dual-booting Windows, the following entry will allow - booting it:</para> - -<screen><userinput>cat >> /boot/grub/menu.lst << "EOF" -<literal>title Windows -rootnoverify (hd0,0) -chainloader +1</literal> -EOF</userinput></screen> - - <para>If <command>info grub</command> does not provide all necessary material, - additional information regarding GRUB is located on its website at: - <ulink url="http://www.gnu.org/software/grub/"/>.</para> - - <para>The FHS stipulates that GRUB's <filename>menu.lst</filename> file should - be symlinked to <filename class="symlink">/etc/grub/menu.lst</filename>. To - satisfy this requirement, issue the following command:</para> - -<screen><userinput>mkdir -v /etc/grub -ln -sv /boot/grub/menu.lst /etc/grub</userinput></screen> - - </sect2> - - <sect2 id="contents-gRUB" role="content"> - <title>Contents of GRUB</title> - - <segmentedlist> - <segtitle>Installed programs</segtitle> - - <seglistitem> - <seg>grub, grub-install, grub-md5-crypt, grub-set-default, - grub-terminfo, and mbchk</seg> - </seglistitem> - </segmentedlist> - - <variablelist> - <bridgehead renderas="sect3">Short Descriptions</bridgehead> - <?dbfo list-presentation="list"?> - <?dbhtml list-presentation="table"?> - - <varlistentry id="grub"> - <term><command>grub</command></term> - <listitem> - <para>The Grand Unified Bootloader's command shell</para> - <indexterm zone="ch-bootable-grub grub"> - <primary sortas="b-grub">grub</primary> - </indexterm> - </listitem> - </varlistentry> - - <varlistentry id="grub-install"> - <term><command>grub-install</command></term> - <listitem> - <para>Installs GRUB on the given device</para> - <indexterm zone="ch-bootable-grub grub-install"> - <primary sortas="b-grub-install">grub-install</primary> - </indexterm> - </listitem> - </varlistentry> - - <varlistentry id="grub-md5-crypt"> - <term><command>grub-md5-crypt</command></term> - <listitem> - <para>Encrypts a password in MD5 format</para> - <indexterm zone="ch-bootable-grub grub-md5-crypt"> - <primary sortas="b-grub-md5-crypt">grub-md5-crypt</primary> - </indexterm> - </listitem> - </varlistentry> - - <varlistentry id="grub-set-default"> - <term><command>grub-set-default</command></term> - <listitem> - <para>Sets the default boot entry for GRUB</para> - <indexterm zone="ch-bootable-grub grub-set-default"> - <primary sortas="b-grub-set-default">grub-set-default</primary> - </indexterm> - </listitem> - </varlistentry> - - <varlistentry id="grub-terminfo"> - <term><command>grub-terminfo</command></term> - <listitem> - <para>Generates a terminfo command from a terminfo name; it can be - employed if an unknown terminal is being used</para> - <indexterm zone="ch-bootable-grub grub-terminfo"> - <primary sortas="b-grub-terminfo">grub-terminfo</primary> - </indexterm> - </listitem> - </varlistentry> - - <varlistentry id="mbchk"> - <term><command>mbchk</command></term> - <listitem> - <para>Checks the format of a multi-boot kernel</para> - <indexterm zone="ch-bootable-grub mbchk"> - <primary sortas="b-mbchk">mbchk</primary> - </indexterm> - </listitem> - </varlistentry> - - </variablelist> - - </sect2> + </sect2> </sect1> diff --git a/chapter08/kernel.xml b/chapter08/kernel.xml index 46cbb479d..a2b737b8d 100644 --- a/chapter08/kernel.xml +++ b/chapter08/kernel.xml @@ -115,10 +115,13 @@ required to complete the installation. Some files need to be copied to the <filename class="directory">/boot</filename> directory.</para> - <para>The path to the kernel image may vary depending on the platform - being used. The following command assumes an x86 architecture:</para> + <para>The path to the kernel image may vary depending on the platform being + used. The filename below can be changed to suit your taste, but the stem of + the filename should be <emphasis>vmlinux</emphasis> to be compatible with + the automatic setup of the boot process described in the next section. The + following command assumes an x86 architecture:</para> -<screen><userinput remap="install">cp -v arch/x86/boot/bzImage /boot/lfskernel-&linux-version;</userinput></screen> +<screen><userinput remap="install">cp -v arch/x86/boot/bzImage /boot/vmlinux-&linux-version;-lfs-&version;</userinput></screen> <para><filename>System.map</filename> is a symbol file for the kernel. It maps the function entry points of every function in the kernel API, |