source: chapter06/grub-cfg.xml@ 20549cb0

xry111/clfs-ng
Last change on this file since 20549cb0 was 20549cb0, checked in by Xi Ruoyao <xry111@…>, 2 years ago

cross-ng: chapter 6: add grub configuration for temporary system

  • Property mode set to 100644
File size: 8.4 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
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-temp" role="wrap">
9 <?dbhtml filename="grub-cfg.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>Making the Temporary System Bootable</title>
18
19 <sect2>
20 <title>Introduction</title>
21
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>
27
28 <sect2>
29 <title>Creating the GRUB Configuration File</title>
30
31 <para>Generate <filename>$LFS/boot/grub/grub.cfg</filename>:</para>
32
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
37
38menuentry "LFS Temporary System" {
39 linux /vmlinux root=/dev/sda3 rw init=/bin/bash
40 boot
41}</literal>
42EOF</userinput></screen>
43
44 <variablelist>
45 <title>The meaning of the linux command options:</title>
46
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>
54
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>
66
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>
77
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>
97
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>
103
104 </sect2>
105
106 <sect2>
107 <title>Copy the Temporary System to the Target Machine</title>
108
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>
117
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>
130
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>
138
139 <para>Create filesystems for the partitions:</para>
140
141<screen><userinput role='nodump'>mkfs.ext4 /dev/<replaceable>sdx</replaceable>2
142mkfs.ext4 /dev/<replaceable>sdx</replaceable>3</userinput></screen>
143
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>
149
150<screen role="nodump"><userinput>fdisk /dev/<replaceable>sdx</replaceable></userinput>
151<literal>
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.
155
156
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'.
161
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>
166
167 <para><replaceable>sdx</replaceable> should be replaced with the name
168 of the device node corresponding to your moveable device. Then mount
169 the filesystems:</para>
170
171<screen><userinput role='nodump'>mkdir -pv /mnt/lfs-target
172mount -v -t ext4 /dev/<replaceable>sdx</replaceable>3 /mnt/lfs-target
173mkdir -pv /mnt/lfs-target/boot
174mount -v -t ext4 /dev/<replaceable>sdx</replaceable>2 /mnt/lfs-target/boot</userinput></screen>
175
176 <para>Copy the temporary system onto the device, and change the
177 ownership of the copy to user
178 <systemitem class="username">root</systemitem>:</para>
179
180<screen><userinput role='nodump'>cp -av $LFS/* /mnt/lfs-target
181chown -R root:root /mnt/lfs-target</userinput></screen>
182
183 <para>Install the bootloader onto the device:</para>
184
185<screen><userinput role='nodump'>$LFS/tools/sbin/lfs-grub-install \
186 --target=i386-pc \
187 --boot-directory=/mnt/lfs-target/boot \
188 /dev/<replaceable>sdx</replaceable></userinput></screen>
189
190 <para>Create the mountpoint for
191 <systemitem class="filesystem">devtmpfs</systemitem>, so the kernel
192 will mount it automatically:</para>
193
194<screen><userinput role='nodump'>install -v -dm755 /mnt/lfs-target/dev</userinput></screen>
195
196 <para>Now, unmount the device:</para>
197
198<screen><userinput role='nodump'>umount -Rv /mnt/lfs-target</userinput></screen>
199
200 <para>Now unplug the device and connect it onto the target system,
201 and boot the target system with this device as the boot device.
202 Read the manual from the vendor of the target system to know how to
203 select the boot device.</para>
204
205 </sect2>
206
207</sect1>
Note: See TracBrowser for help on using the repository browser.