source: chapter06/grub-cfg.xml@ 3a5d53a

Last change on this file since 3a5d53a was 3a5d53a, checked in by Xi Ruoyao <xry111@…>, 9 months ago

cross-ng: adjust backup & restore for cross build

  • Property mode set to 100644
File size: 8.8 KB
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "" [
4 <!ENTITY % general-entities SYSTEM "../general.ent">
5 %general-entities;
8<sect1 id="ch-bootable-temp" role="wrap">
9 <?dbhtml filename="grub-cfg.html"?>
11 <sect1info condition="script">
12 <productname>grub</productname>
13 <productnumber>&grub-version;</productnumber>
14 <address>&grub-url;</address>
15 </sect1info>
17 <title>Making the Temporary System Bootable</title>
19 <sect2>
20 <title>Introduction</title>
22 <para>In a normal LFS building procedure, we will chroot into the
23 temporary system and continue to build additional temporary tools.
24 But, as we've explained, in the Cross Edition we need to make the
25 temporary system bootable and boot it on the target system.</para>
26 </sect2>
28 <sect2>
29 <title>Creating the GRUB Configuration File</title>
31 <para>Generate <filename>$LFS/boot/grub/grub.cfg</filename>:</para>
33 <screen><userinput>cat &gt; $LFS/boot/grub/grub.cfg &lt;&lt; "EOF"
34<literal># Begin /boot/grub/grub.cfg
35set default=0
36set timeout=5
38menuentry "LFS Temporary System" {
39 linux /vmlinux root=/dev/sda3 rw init=/bin/bash
40 boot
44 <variablelist>
45 <title>The meaning of the linux command options:</title>
47 <varlistentry>
48 <term><parameter>root=/dev/sda3</parameter></term>
49 <listitem>
50 <para>We will use the third parition as the partition for the
51 root filesystem of the LFS system.</para>
52 </listitem>
53 </varlistentry>
55 <varlistentry>
56 <term><parameter>rw</parameter></term>
57 <listitem>
58 <para>Tell the kernel to mount the root filesystem read-write.
59 In normal distros there is <parameter>ro</parameter> instead, so
60 the kernel will mount the root filesystem read-only. Then
61 the <command>init</command> process can check the filesystem
62 integrity and remount it read-write. For the temporary system
63 it's not needed.</para>
64 </listitem>
65 </varlistentry>
67 <varlistentry>
68 <term><parameter>init=/bin/bash</parameter></term>
69 <listitem>
70 <para>By default the kernel runs <command>/sbin/init</command>
71 as the first process. It's provided by SysVinit or Systemd
72 package, which is not installed yet. We explicitly tell the
73 kernel to run <command>/bin/bash</command> instead to start a
74 shell, so we can run further commands interactively.</para>
75 </listitem>
76 </varlistentry>
78 <varlistentry>
79 <term>(optional) <parameter>console=ttyS0,115200</parameter></term>
80 <listitem>
81 <para>Use the serial port at <filename>/dev/ttyS0</filename> as
82 the output console device. It's very useful if the virtual
83 console is not avaliable (for example, the target system may lack
84 graphic output, or the framebuffer console may be too slow).
85 And, by connecting the host system and the target system with a
86 NULL modem or USB serial converter, it will be able to copy the
87 commands from the book and paste it into a terminal emulator
88 (for example,
89 <ulink url='&blfs-book;general/screen.html'>GNU Screen</ulink>)
90 on the host, to execute them on the target system.
91 <parameter>115200</parameter> specifies the baudrate, the default
92 (9600) is too slow for large amount of console output building
93 LFS.</para>
94 </listitem>
95 </varlistentry>
96 </variablelist>
98 <note><para>From <application>GRUB</application>'s perspective, the
99 kernel files are relative to the partition used. We will use a
100 a separate /boot partition, so /boot is not needed in the above
101 <emphasis>linux</emphasis> line.
102 </para></note>
104 </sect2>
106 <sect2>
107 <title>Copy the Temporary System to the Target Machine</title>
109 <note>
110 <para>The commands in the subsection must be performed on the host
111 system while logged in as user
112 <systemitem class="username">root</systemitem>
113 and no longer as user <systemitem class="username">lfs</systemitem>.
114 Also, double check that <envar>$LFS</envar> is set in <systemitem
115 class="username">root</systemitem>'s environment.</para>
116 </note>
118 <para>Now it's the time to copy the
119 <filename class="directory">$LFS</filename> hierarchy over to your
120 target machine. You'll need a <quote>moveable</quote> device for this.
121 Using a normal USB stick is likely a bad choice: the USB sticks are
122 generally not optimized for reading or writing many small files
123 (which will happen building packages from source). Especially, if a
124 ext filesystem is used, the performance can be very bad. You may use
125 a USB to SATA adapter and a HDD or SSD (then you can directly connect
126 it onto the SATA port of the target system, or continuing to use the
127 adapter on a USB port of the target system), or a USB stick with an I/O
128 controller for SSD (these USB sticks are significantly more expansive
129 than a normal one).</para>
131 <para>Create a GUID partition table on the device, and then create
132 three partitions on it. The first will be used as the BIOS boot
133 partition, 1 MB is sufficient enough. But if you want to use EFI to
134 boot your LFS system later, assign 100 MB for it so it will be possible
135 to convert it into an EFI system partition. The second partition will
136 be used as the boot partition, 500 MB is sufficient enough. The third
137 will be the root partition, it should be at least 20 GB.</para>
139 <para>Create filesystems for the partitions:</para>
141<screen><userinput role='nodump'>mkfs.ext4 /dev/<replaceable>sdx</replaceable>2
142mkfs.ext4 /dev/<replaceable>sdx</replaceable>3</userinput></screen>
144 <para>
145 It's not needed to create a filesystem for the BIOS boot partition.
146 But, its type should be set to <quote>BIOS boot</quote> in
147 the partition table using <command>fdisk</command>:
148 </para>
150<screen role="nodump"><userinput>fdisk /dev/<replaceable>sdx</replaceable></userinput>
152Welcome to fdisk (util-linux &util-linux-version;).
153Changes will remain in memory only, until you decide to write them.
154Be careful before using the write command.
157Command (m for help): </literal><userinput>t</userinput>
158<literal>Partition number (1-9, default 9): </literal><userinput>1</userinput>
159<literal>Partition type or alias (type L to list all): </literal><userinput>BIOS boot</userinput>
160<literal>Changed type of partition 'Linux' to 'BIOS boot'.
162Command (m for help): </literal><userinput>w</userinput>
163<literal>The partition table has been altered.
164Calling ioctl() to re-read partition table.
165Syncing disks.</literal></screen>
167 <para>In <xref linkend="ch-tools-cleanup"/> it's optional to make a
168 backup for the temporary system. If you'd like to do so, prepare
169 another parition (1 GB should be enough) and make an
170 <systemitem class="filesystem">ext4</systemitem> filesystem to hold
171 the backup:</para>
173<screen><userinput role='nodump'>mkfs.ext4 /dev/<replaceable>sdx4</replaceable></userinput></screen>
175 <para><replaceable>sdx</replaceable> should be replaced with the name
176 of the device node corresponding to your moveable device. Then mount
177 the filesystems:</para>
179<screen><userinput role='nodump'>mkdir -pv /mnt/lfs-target
180mount -v -t ext4 /dev/<replaceable>sdx</replaceable>3 /mnt/lfs-target
181mkdir -pv /mnt/lfs-target/boot
182mount -v -t ext4 /dev/<replaceable>sdx</replaceable>2 /mnt/lfs-target/boot</userinput></screen>
184 <para>Copy the temporary system onto the device, and change the
185 ownership of the copy to user
186 <systemitem class="username">root</systemitem>:</para>
188<screen><userinput role='nodump'>cp -av $LFS/* /mnt/lfs-target
189chown -R root:root /mnt/lfs-target</userinput></screen>
191 <para>Install the bootloader onto the device:</para>
193<screen><userinput role='nodump'>$LFS/tools/sbin/lfs-grub-install \
194 --target=i386-pc \
195 --boot-directory=/mnt/lfs-target/boot \
196 /dev/<replaceable>sdx</replaceable></userinput></screen>
198 <para>Create the mountpoint for
199 <systemitem class="filesystem">devtmpfs</systemitem>, so the kernel
200 will mount it automatically:</para>
202<screen><userinput role='nodump'>install -v -dm755 /mnt/lfs-target/dev</userinput></screen>
204 <para>Now, unmount the device:</para>
206<screen><userinput role='nodump'>umount -Rv /mnt/lfs-target</userinput></screen>
208 <para>Now unplug the device and connect it onto the target system,
209 and boot the target system with this device as the boot device.
210 Read the manual from the vendor of the target system to know how to
211 select the boot device.</para>
213 </sect2>
Note: See TracBrowser for help on using the repository browser.