1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
|
---|
3 | "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
|
---|
4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
5 | %general-entities;
|
---|
6 | ]>
|
---|
7 |
|
---|
8 | <sect1 id="postlfs-config-bootdisk">
|
---|
9 | <?dbhtml filename="bootdisk.html"?>
|
---|
10 | <title>Creating a Custom Boot Disk</title>
|
---|
11 |
|
---|
12 | <sect2>
|
---|
13 | <title>Decent Rescue Boot Disk Needs</title>
|
---|
14 | <para>This section is really about creating a <emphasis>rescue</emphasis>
|
---|
15 | diskette. As the name <emphasis>rescue</emphasis> implies, the host
|
---|
16 | system has a problem, often lost partition information or corrupted file
|
---|
17 | systems, that prevents it from booting and/or operating normally. For
|
---|
18 | this reason, you <emphasis>must not</emphasis> depend on resources from
|
---|
19 | the host being "rescued". To presume that any given partition or hard
|
---|
20 | drive <emphasis>will</emphasis> be available is a risky presumption.</para>
|
---|
21 |
|
---|
22 | <para>Heeding the warning, the rescue disk created here has no
|
---|
23 | dependency on the host system's resources, other than basic bootability
|
---|
24 | and hardware soundness. At a minimum, the most common sorts of failures
|
---|
25 | requiring a rescue boot disk should be addressed by the contents of the
|
---|
26 | boot disk. This would include the common loss of partitioning (master
|
---|
27 | boot record is lost or corrupted), file system corruption, and the need
|
---|
28 | to allow creation and editing of files that may have been lost or
|
---|
29 | corrupted, possibly as an effect of the other two problems.</para>
|
---|
30 |
|
---|
31 | <para>Additional utilities should be available to search for text or
|
---|
32 | files, copy, move and remove files, and many other normal operations
|
---|
33 | that might be expected to be needed when reconstructing.</para>
|
---|
34 | </sect2>
|
---|
35 |
|
---|
36 | <sect2>
|
---|
37 | <title>This Minimal Decent Rescue Disk</title>
|
---|
38 |
|
---|
39 | <para>The intent here is to create a "rescue boot disk" that will support
|
---|
40 | the common operations listed above. These functions are provided by
|
---|
41 | including selected executables from <application><ulink
|
---|
42 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox
|
---|
43 | </ulink></application> and <application><ulink
|
---|
44 | url="http://freshmeat.net/projects/e2fsprogs/">e2fsprogs</ulink></application>.
|
---|
45 | A basic editor and rudimentary disk partitioning utility may also be
|
---|
46 | optionally included.</para>
|
---|
47 |
|
---|
48 | <para>This, however, is not the limit. A minimal disk is described
|
---|
49 | here, but you can add anything you can fit on the floppy. Furthermore,
|
---|
50 | if one floppy is not enough to meet your needs, you can make a
|
---|
51 | multi-diskette rescue set that means, essentially, the sky is the limit.
|
---|
52 | This is discussed below. The number of other possible variations are
|
---|
53 | just too numerous to mention here.</para>
|
---|
54 | </sect2>
|
---|
55 |
|
---|
56 | <sect2>
|
---|
57 | <title>Build the Rescue Boot Disk</title>
|
---|
58 | <sect3>
|
---|
59 | <title>Prerequisites</title>
|
---|
60 |
|
---|
61 | <para>You should have known-good floppy diskettes available. Some
|
---|
62 | people prefer to use the <command>fdformat</command> command to prepare
|
---|
63 | these because it also does a verification. See the man page for more
|
---|
64 | details. Another good idea is to always prepare duplicates of the
|
---|
65 | rescue diskette. Media does deteriorate.</para>
|
---|
66 |
|
---|
67 | <para>These instructions presume a base <acronym>LFS</acronym> install
|
---|
68 | using ext2/ext3 file systems.</para>
|
---|
69 |
|
---|
70 | <para>You need to have loopback device support enabled in your host's
|
---|
71 | kernel to use this procedure.</para>
|
---|
72 |
|
---|
73 | <para>You should make a custom kernel that includes only those features
|
---|
74 | needed to rescue your system, so it will have the least size. No
|
---|
75 | sense in building in support for things like <application>XFree86</application>,
|
---|
76 | <application>DRI</application>, etc, as most rescues are performed from the
|
---|
77 | command prompt. Along the same lines, if you have <xref linkend="gcc2"/>, it
|
---|
78 | is known to produce smaller kernels. So you might want to use that
|
---|
79 | compiler for this kernel. If you do so, don't overlook any loadable
|
---|
80 | modules (which are not addressed here) you might need - they need to be
|
---|
81 | compiled with the same compiler used to make the kernel.</para>
|
---|
82 |
|
---|
83 | <para>The rescue image must include support for the file system of your
|
---|
84 | choice (we presume ext2/3 here), ramdisk and initial ramdisk (initrd).
|
---|
85 | Disable everything that you can in the kernel configuration. You should
|
---|
86 | keep support for the proc file system and tempfs file system enabled
|
---|
87 | because of their general utility. The proc file system is needed for
|
---|
88 | the <command>mount</command> to report properly.</para>
|
---|
89 |
|
---|
90 | <para>If you install <emphasis>only</emphasis> the minimal set of
|
---|
91 | components shown in this document, you will need a kernel that is 643 or
|
---|
92 | fewer blocks in size. If you want the optional programs - a very basic
|
---|
93 | editor, like <command>ed</command>, and rudimentary disk partitioning, like
|
---|
94 | <command>sfdisk</command> - the kernel will need to be 595 or fewer blocks in
|
---|
95 | size. This should not be a major problem unless your needs are fairly
|
---|
96 | esoteric. On the system used to develop this version of the procedures, using
|
---|
97 | only ext2 file systems and not using networking or <acronym>CD</acronym>s for
|
---|
98 | recovery, the kernel image is only 481 blocks. And there may be more to gain - it has not been closely examined for additional gains.</para>
|
---|
99 |
|
---|
100 | <para>This kernel image will be called "rescueimage" hereinafter. You
|
---|
101 | can actually name your image anything you like and just use its name
|
---|
102 | instead in any commands that include "rescueimage".</para>
|
---|
103 |
|
---|
104 | <para>If you can not get your rescueimage down to the size needed to allow
|
---|
105 | all you need on the ramdisk image, don't fret. You can always build a
|
---|
106 | two diskette set, one boot and one root diskette. The kernel will prompt
|
---|
107 | you to insert the root file system diskette. This will allow room for a
|
---|
108 | compressed ramdisk image of 1440 blocks and a rescueimage of the same
|
---|
109 | size.</para>
|
---|
110 |
|
---|
111 | <para>The rescueimage size limits given above are likely to vary as
|
---|
112 | local system-specific configurations change. Use them only as a
|
---|
113 | guideline and not as gospel. The size of rescueimage as shown by
|
---|
114 | <command>ls -sk</command> is only an approximation because of some
|
---|
115 | "overhead". On the system used to develop this version of these
|
---|
116 | procedures, that command shows 488 blocks but the actual number of
|
---|
117 | blocks written is only 480 and a fraction, which means that 481 blocks
|
---|
118 | are actually used.</para>
|
---|
119 | </sect3>
|
---|
120 |
|
---|
121 | <sect3>
|
---|
122 | <title>Rescue Disk Build Process</title>
|
---|
123 |
|
---|
124 | <para>The basic process will be:</para>
|
---|
125 | <itemizedlist>
|
---|
126 | <listitem><para>make a mount point for a file system</para></listitem>
|
---|
127 | <listitem><para>make an empty file to hold the file system</para></listitem>
|
---|
128 | <listitem><para>bind the empty file to a loopback device</para></listitem>
|
---|
129 | <listitem><para>make a 4MB file system</para></listitem>
|
---|
130 | <listitem><para>mount the file system</para></listitem>
|
---|
131 | <listitem><para>add components to the file system</para></listitem>
|
---|
132 | <listitem><para>make the compressed initrd</para></listitem>
|
---|
133 | <listitem><para>join rescueimage and initrd onto a diskette</para></listitem>
|
---|
134 | </itemizedlist>
|
---|
135 |
|
---|
136 | <para>The initial ramdisk will be automatically loaded at boot time if
|
---|
137 | setup is done correctly.</para>
|
---|
138 |
|
---|
139 | <para><emphasis>Make a mount point and an empty file to hold a file
|
---|
140 | system</emphasis></para>
|
---|
141 |
|
---|
142 | <screen><userinput><command>mkdir -p /mnt/loop1
|
---|
143 | dd if=/dev/zero of=/tmp/rfloppy bs=1k count=4096</command></userinput></screen>
|
---|
144 |
|
---|
145 | <para><emphasis>Command explanations</emphasis></para>
|
---|
146 |
|
---|
147 | <para><command>dd</command>: This is a generalized input-to-output copy
|
---|
148 | utility that also has many transformation capabilities.</para>
|
---|
149 |
|
---|
150 | <para><parameter>if=/dev/zero</parameter>: This parameter assigns
|
---|
151 | <command>dd</command>'s input file to a device that returns an infinite
|
---|
152 | stream of zeroes.</para>
|
---|
153 |
|
---|
154 | <para><parameter>of=/tmp/rfloppy</parameter>: This parameter directs
|
---|
155 | <command>dd</command>'s output to <filename>/tmp/rfloppy</filename>.</para>
|
---|
156 |
|
---|
157 | <para><parameter>bs=1k count=4096</parameter>: These parameters tell
|
---|
158 | <command>dd</command> to read and write in "chunks" of 1024 bytes and
|
---|
159 | process 4096 "chunks".</para>
|
---|
160 |
|
---|
161 | <para><emphasis>Bind the file to a loopback device, make a file system and mount it.</emphasis></para>
|
---|
162 |
|
---|
163 | <para>The reason these commands are used is that they work regardless of
|
---|
164 | the version of <command>mount</command> (older ones don't have the
|
---|
165 | <userinput>-o loop</userinput> option) or if <filename>/etc/mtab</filename>
|
---|
166 | is symlinked to <filename class="directory">/proc</filename> (which causes mount to be
|
---|
167 | unable to properly "unbind" a loop device, due to "lost" information).
|
---|
168 | An alternate set of commands is provided, after these three commands,
|
---|
169 | that you can use if you don't have either of these situations.</para>
|
---|
170 |
|
---|
171 | <screen><userinput><command>losetup /dev/loop1 /tmp/rfloppy
|
---|
172 | mke2fs -m 0 -N 504 /dev/loop1
|
---|
173 | mount -t ext2 /dev/loop1 /mnt/loop1</command></userinput></screen>
|
---|
174 |
|
---|
175 | <para><emphasis>Command explanations</emphasis></para>
|
---|
176 |
|
---|
177 | <para><command>losetup /dev/loop1 /tmp/rfloppy</command>: This
|
---|
178 | command "binds" a loopback device to the empty file.</para>
|
---|
179 |
|
---|
180 | <para><command>mke2fs -m 0 -N 504 /dev/loop1</command>: This
|
---|
181 | command makes an ext2 file system on the loopback device (which really
|
---|
182 | means it is created in the file to which the loopback device is bound)
|
---|
183 | and reserves no blocks. The <userinput>-N 504</userinput> parameter causes
|
---|
184 | only 504 inodes to be allocated, leaving more space for other things needed
|
---|
185 | in the file system.</para>
|
---|
186 |
|
---|
187 | <para><command>mount -t ext2 /dev/loop1 /mnt/loop1</command>: This
|
---|
188 | mounts the file system just created, just as if it were a real device,
|
---|
189 | like a hard drive or diskette. This allows all the normal system I/O
|
---|
190 | commands to operate as if a real device were present.</para>
|
---|
191 |
|
---|
192 | <para>If your <command>mount</command> supports the
|
---|
193 | <option>-o loop</option> option <emphasis>and</emphasis> your
|
---|
194 | <filename>/etc/mtab</filename> is a real file, rather than a symlink to
|
---|
195 | <filename class="directory">/proc</filename>, the three above commands can be replaced
|
---|
196 | by these next two commands.</para>
|
---|
197 |
|
---|
198 | <screen><userinput><command>mke2fs -F -m 0 -N 504 /tmp/rfloppy
|
---|
199 | mount -o loop /tmp/rfloppy /mnt/loop1</command></userinput></screen>
|
---|
200 |
|
---|
201 | <para><emphasis>Command explanations</emphasis></para>
|
---|
202 |
|
---|
203 | <para><command>mke2fs -F -m 0 -N 504 /tmp/rfloppy</command>: As before,
|
---|
204 | a file system is made, with only 504 inodes and no reserved blocks, that
|
---|
205 | will be bound to a loopback device. The <userinput>-F</userinput> parameter
|
---|
206 | just suppresses an irritating question issued when
|
---|
207 | <command>mke2fs</command> realizes that you are not accessing a
|
---|
208 | device.</para>
|
---|
209 |
|
---|
210 | <para><command>mount -o loop /tmp/rfloppy /mnt/loop1</command>: This
|
---|
211 | command tells <command>mount</command> to bind the named file to a
|
---|
212 | loopback device it automatically selects (the first available) and mount
|
---|
213 | the device on <filename class="directory">/mnt/loop1</filename>.</para>
|
---|
214 |
|
---|
215 | <para><emphasis>Add components to the file system</emphasis></para>
|
---|
216 |
|
---|
217 | <para><emphasis>A cautionary note:</emphasis> if you are not running in a
|
---|
218 | <command>chroot</command> environment, be sure that you do not accidentally
|
---|
219 | omit the <filename class="directory">/mnt/loop1</filename> reference in the commands. If
|
---|
220 | you do so, you might replace the equivalent components on your host with
|
---|
221 | the components that are installed by these procedures. Even if you are
|
---|
222 | in a chroot environment, you may need to be careful if the environment
|
---|
223 | is your freshly built <acronym>LFS</acronym> system which you intend to
|
---|
224 | use as a host in the future.</para>
|
---|
225 |
|
---|
226 | <para>First, to have as much free space as possible, remove the
|
---|
227 | <filename>lost+found</filename> directory, which is not needed because
|
---|
228 | it is only used by <command>fsck</command>. Since <command>fsck</command>
|
---|
229 | will never be run on this file system, it is unneeded.</para>
|
---|
230 |
|
---|
231 | <screen><userinput><command>rmdir /mnt/loop1/lost+found/</command></userinput></screen>
|
---|
232 |
|
---|
233 | <para>Now make a minimal set of directories.</para>
|
---|
234 |
|
---|
235 | <screen><userinput><command>mkdir /mnt/loop1/{dev,proc,etc,sbin,bin,lib,mnt,usr,var}</command></userinput></screen>
|
---|
236 |
|
---|
237 | <para>Add needed device files to the initrd image. If you use devfs,
|
---|
238 | the following command works well, as you only have the devices you use
|
---|
239 | anyway.</para>
|
---|
240 |
|
---|
241 | <screen><userinput><command>cp -dpR /dev/* /mnt/loop1/dev</command></userinput></screen>
|
---|
242 |
|
---|
243 | <para>If you used <command>MAKEDEV</command> to create your devices on
|
---|
244 | your host, you'll want to use something similar to this longer command,
|
---|
245 | to minimize wasting space with unneeded inodes.</para>
|
---|
246 |
|
---|
247 | <para><emphasis>You must modify this to suit your rescueimage configuration and
|
---|
248 | other needs.</emphasis> For example, you may need
|
---|
249 | <acronym>SCSI</acronym> devices and may not need
|
---|
250 | frame buffer devices or the pseudo-terminal directory. Also, the number
|
---|
251 | of hard drives and partitions that you include should be the minimal
|
---|
252 | that you need. Extensive analysis has not been done on the list below,
|
---|
253 | so there are more inodes and space to be gained by "fine tuning" this
|
---|
254 | set.</para>
|
---|
255 |
|
---|
256 | <screen><userinput><command>mkdir /mnt/loop1/dev/pts
|
---|
257 | cp -a \
|
---|
258 | /dev/null /dev/console \
|
---|
259 | /dev/fb[0-7] /dev/fd /dev/fd0 /dev/fd0h1440 /dev/full \
|
---|
260 | /dev/hda* /dev/hdb* /dev/hdc* /dev/hdd* /dev/initctl /dev/kmem \
|
---|
261 | /dev/loop[0-3] /dev/lp0 /dev/mem /dev/port \
|
---|
262 | /dev/psaux /dev/ram \
|
---|
263 | /dev/ram0 /dev/ram1 /dev/ram2 /dev/ram3 /dev/random /dev/rtc \
|
---|
264 | /dev/shm /dev/stderr /dev/stdin /dev/stdout /dev/tty \
|
---|
265 | /dev/tty[0-9] /dev/ttyS0 /dev/ttyS1 /dev/urandom /dev/zero \
|
---|
266 | /mnt/loop1/dev</command></userinput></screen>
|
---|
267 |
|
---|
268 | <para><emphasis>What is needed in the <filename class="directory">/etc</filename>
|
---|
269 | directory</emphasis></para>
|
---|
270 |
|
---|
271 | <para>If you choose, you can copy all or selected parts of your
|
---|
272 | <filename>/etc/passwd</filename> and <filename>/etc/group</filename>
|
---|
273 | files. But even if each is less than 1024 bytes, you will lose two
|
---|
274 | inodes and two blocks of space on the initial ramdisk. This only really
|
---|
275 | matters because of trying to squeeze everything onto a 1.44MB
|
---|
276 | diskette. Every little bit helps. The strategy taken here is to create
|
---|
277 | these two files as part of the rescue boot and initialization process.
|
---|
278 | The commands that make the two files will be embedded inside the
|
---|
279 | <filename>rcS</filename> script that <filename>linuxrc</filename>
|
---|
280 | (really <application><ulink
|
---|
281 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox
|
---|
282 | </ulink></application>) invokes after the initrd is
|
---|
283 | loaded. This way no more inodes or blocks are used on the
|
---|
284 | diskette to carry these files.</para>
|
---|
285 |
|
---|
286 | <para>Some might like to copy their <filename class="directory">/etc/rc*</filename>
|
---|
287 | directory into the ramdisk image, but this may have no value, other
|
---|
288 | than archival use, in a worst-case recovery scenario. If you want
|
---|
289 | automatic initialization of the system after repair, they may have some
|
---|
290 | value. But few people need or want this to happen. If the file system
|
---|
291 | on the hard drives are corrupted, what good will mount scripts do? Some
|
---|
292 | scripts may be useful, like access to a network to copy over backup data
|
---|
293 | when the hard drive's file systems are usable again. The point is that
|
---|
294 | you should copy only the parts that you can use because space is at a
|
---|
295 | premium on the diskette.</para>
|
---|
296 |
|
---|
297 | <para>Here, only the <filename>fstab</filename> will be included. This
|
---|
298 | is handy because it eases mounting of partitions that may be useful and
|
---|
299 | also can be examined and used as a guide as to what is available and
|
---|
300 | what may need reconstruction. Because it may be larger than needed, you
|
---|
301 | should edit it to remove any useless entries and minimize commentary.
|
---|
302 | No other editing is needed because the boot scripts are not included and
|
---|
303 | no automatic mounting will be done using the <filename>fstab</filename>.
|
---|
304 | If you decide to include some boot scripts that might try to mount
|
---|
305 | things, change the <filename>fstab</filename>'s entries to
|
---|
306 | <command>noauto</command> in the options field so they don't cause an
|
---|
307 | attempt to mount a potentially corrupt partition. Copy it to
|
---|
308 | <filename class="directory">/tmp</filename>, edit it as desired and then:</para>
|
---|
309 |
|
---|
310 | <screen><userinput><command>cp -a /tmp/fstab /mnt/loop1/etc</command></userinput></screen>
|
---|
311 |
|
---|
312 | <para>Now the initialization script will be added. As mentioned above,
|
---|
313 | <command>linuxrc</command> is symlinked to <application><ulink
|
---|
314 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox
|
---|
315 | </ulink></application>.
|
---|
316 | After the kernel and initial ramdisk have been loaded, the kernel gives
|
---|
317 | control to <command>linuxrc</command> (<application><ulink
|
---|
318 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox
|
---|
319 | </ulink></application>). It wants to run an <filename class="directory">/etc/init.d/rcS</filename>
|
---|
320 | script to do any initial setup.</para>
|
---|
321 |
|
---|
322 | <para>If you use devfsd, you will need to set up the
|
---|
323 | <filename>rcS</filename> script to handle the devfsd startup. Put the
|
---|
324 | following commands in <filename class="directory">/mnt/loop1/etc/init.d/rcS</filename>.
|
---|
325 | You may also want to add some of the processes shown in the non-devfs
|
---|
326 | version that follows.</para>
|
---|
327 |
|
---|
328 | <screen><userinput>#!/bin/sh
|
---|
329 | mount -t devfs devfs /dev
|
---|
330 | /sbin/devfsd /dev</userinput></screen>
|
---|
331 |
|
---|
332 | <para>If you don't use devfsd, but created a static <filename
|
---|
333 | class="directory">/dev</filename>
|
---|
334 | directory using <command>MAKEDEV</command>, or any similar process, the
|
---|
335 | <filename>rcS</filename> script will do slightly different things.
|
---|
336 | Also, don't forget that it is creating the
|
---|
337 | <filename>/etc/passwd</filename> and <filename>/etc/group</filename>
|
---|
338 | files, thus saving space on the diskette.</para>
|
---|
339 |
|
---|
340 | <para>The script made next will mount <filename class="directory">/proc</filename>, turn
|
---|
341 | on swap (no harm is done if it fails), make the
|
---|
342 | <filename>/etc/passwd</filename> and <filename>/etc/group</filename>
|
---|
343 | files, create a log directory and turn on swapping. Create the script
|
---|
344 | with:</para>
|
---|
345 |
|
---|
346 | <screen><userinput><command>mkdir -p /mnt/loop1/etc/init.d
|
---|
347 | cat >/mnt/loop1/etc/init.d/rcS << EOD</command>
|
---|
348 | #!/bin/sh
|
---|
349 | mount -t proc proc /proc
|
---|
350 | swapon -a
|
---|
351 |
|
---|
352 | echo "root:x:0:0:root:/root:/bin/bash" > /etc/passwd
|
---|
353 |
|
---|
354 | <command>cat > /etc/group <<EOF</command>
|
---|
355 | root:x:0:
|
---|
356 | bin:x:1:
|
---|
357 | sys:x:2:
|
---|
358 | kmem:x:3:
|
---|
359 | tty:x:4:
|
---|
360 | tape:x:5:
|
---|
361 | daemon:x:6:
|
---|
362 | floppy:x:7:
|
---|
363 | disk:x:8:
|
---|
364 | lp:x:9:
|
---|
365 | dialout:x:10:
|
---|
366 | audio:x:11:
|
---|
367 | <command>EOF
|
---|
368 | chmod 644 /etc/passwd /etc/group</command>
|
---|
369 |
|
---|
370 | mkdir /var/log
|
---|
371 |
|
---|
372 | <command>EOD
|
---|
373 | chmod u+x /mnt/loop1/etc/init.d/rcS</command></userinput></screen>
|
---|
374 |
|
---|
375 | <para>Unless you add a lot to this script, which <emphasis>is</emphasis>
|
---|
376 | encouraged, the above should be reasonably close to what you need.</para>
|
---|
377 |
|
---|
378 | <para><emphasis>Install packages</emphasis></para>
|
---|
379 |
|
---|
380 | <para>There are two packages that must be installed. The <application><ulink
|
---|
381 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox</ulink></application>
|
---|
382 | package incorporates the core functions that provide a shell and many
|
---|
383 | basic utilities. A file system package, like <application><ulink
|
---|
384 | url="http://freshmeat.net/projects/e2fsprogs/">e2fsprogs</ulink></application>, or
|
---|
385 | a package for the file system you are using, will provide a minimal
|
---|
386 | set of utilities for file system checking and reconstruction. The whole
|
---|
387 | package will not be installed, but only certain needed components.</para>
|
---|
388 |
|
---|
389 | <para>If you use devfsd, you will also need to install that software.</para>
|
---|
390 |
|
---|
391 | <para>Install <application><ulink
|
---|
392 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox</ulink></application>
|
---|
393 | into the initial ramdisk image. Busybox incorporates many Unix utility
|
---|
394 | program functions into a single small executable file.</para>
|
---|
395 |
|
---|
396 | <screen><userinput><command>make &&
|
---|
397 | make PREFIX=/mnt/loop1 install &&
|
---|
398 | > /mnt/loop1/var/utmp</command></userinput></screen>
|
---|
399 |
|
---|
400 | <para>A <filename>var/utmp</filename> is made because <application><ulink
|
---|
401 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox</ulink></application>
|
---|
402 | needs it for the reboot command to work properly. If this file doesn't
|
---|
403 | exist when <application><ulink
|
---|
404 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox</ulink></application>
|
---|
405 | is started, the reboot command will not work. This would be a bad thing
|
---|
406 | for people that have no reset button available to them.</para>
|
---|
407 |
|
---|
408 | <para>If you use devfs to create devices on the fly and free up precious
|
---|
409 | inodes on the floppy, you'll also install devfsd to facilitate the
|
---|
410 | devices that <application><ulink
|
---|
411 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox</ulink></application>
|
---|
412 | expects to find. Use the following commands to do the install.</para>
|
---|
413 |
|
---|
414 | <screen><userinput><command>mv GNUmakefile Makefile &&
|
---|
415 | make &&
|
---|
416 | make PREFIX=/mnt/loop1 install</command></userinput></screen>
|
---|
417 |
|
---|
418 | <para><emphasis>Install part of <application>e2fsprogs</application></emphasis></para>
|
---|
419 |
|
---|
420 | <para>If you use the ext2 or ext3 (journaling) file system, you can use
|
---|
421 | the commands below to install the minimal functionality that should
|
---|
422 | allow you to get your hard drives usable again. If you use ext3, keep in
|
---|
423 | mind that it is a part of the <application>e2fsprogs</application>
|
---|
424 | package and you can get the components, which are mostly hard links,
|
---|
425 | from the same places shown below. If you use some other file system,
|
---|
426 | such as reiserfs, you should apply the <emphasis>principals</emphasis>
|
---|
427 | you see here to install parts of that package instead.</para>
|
---|
428 |
|
---|
429 | <screen><userinput><command>LDFLAGS='-s'
|
---|
430 | mkdir build &&
|
---|
431 | cd build &&
|
---|
432 | ../configure --prefix=/mnt/loop1/usr --with-root-prefix="" \
|
---|
433 | --disable-swapfs --disable-debugfs \
|
---|
434 | --enable-dynamic-e2fsck --disable-nls --disable-evms \
|
---|
435 | --disable-rpath &&
|
---|
436 | make LDFLAGS="$LDFLAGS" &&
|
---|
437 | strip -p --strip-unneeded --remove-section=.comment \
|
---|
438 | -o /mnt/loop1/sbin/mke2fs misc/mke2fs &&
|
---|
439 | strip -p --strip-unneeded --remove-section=.comment \
|
---|
440 | -o /mnt/loop1/sbin/e2fsck e2fsck/e2fsck &&
|
---|
441 | chmod 555 /mnt/loop1/sbin/{mke2fs,e2fsck}
|
---|
442 | </command></userinput></screen>
|
---|
443 |
|
---|
444 | <para><emphasis>Two useful utilities</emphasis></para>
|
---|
445 |
|
---|
446 | <para>There are two very useful utilities that any rescue disk should
|
---|
447 | have, to help in faster and more accurate recovery. The first is a
|
---|
448 | partitioning utility. The <command>sfdisk</command> program is
|
---|
449 | used here because of its small size and great power. Be warned though -
|
---|
450 | it is not what is considered to be "user friendly". But the
|
---|
451 | <command>fdisk</command> and <command>cfdisk</command> programs are
|
---|
452 | substantially larger or require more shared objects, like <application>ncurses
|
---|
453 | </application>.</para>
|
---|
454 |
|
---|
455 | <para>The second utility is an editor. Most graphical editors are
|
---|
456 | inherently too large and also require additional shared objects. For
|
---|
457 | this reason, <command>ed</command> is used here. It is small, requires
|
---|
458 | no additional shared objects and is a regex-based editor that is the
|
---|
459 | ancestor to almost all subsequent editors that support regex-based
|
---|
460 | editing, whether graphical or not. It is a "context editor" and offers
|
---|
461 | powerful, but non-graphical, editing features. There are many other
|
---|
462 | editors that may be suitable - feel free to use one of them instead.</para>
|
---|
463 |
|
---|
464 | <para>Read the <application>busybox</application>
|
---|
465 | <filename>INSTALL</filename> and <filename>README</filename> files to
|
---|
466 | see how to include a <command>vi</command> editor. It has not been
|
---|
467 | investigated here yet, so it may or may not easily fit onto a single
|
---|
468 | diskette image such as is made here.</para>
|
---|
469 |
|
---|
470 | <para>You can install these or not, but it is important for you to have
|
---|
471 | some capability such as these offer. Exactly how you would install the
|
---|
472 | utilities you choose will have to be determined by you.</para>
|
---|
473 |
|
---|
474 | <para><command>Sfdisk</command> and <command>ed</command> are installed
|
---|
475 | by, essentially, copying them from your host. Strip is used, just to
|
---|
476 | assure that they carry no "excess baggage", even though the base
|
---|
477 | <acronym>LFS</acronym> install should have stripped them already. Use
|
---|
478 | the following commands:</para>
|
---|
479 |
|
---|
480 | <screen><userinput><command>strip -p --strip-unneeded --remove-section=.comment \
|
---|
481 | -o /mnt/loop1/sbin/sfdisk /sbin/sfdisk
|
---|
482 | strip -p --strip-unneeded --remove-section=.comment \
|
---|
483 | -o /mnt/loop1/bin/ed /bin/ed
|
---|
484 | chmod 555 /mnt/loop1/sbin/sfdisk /mnt/loop1/bin/ed</command></userinput></screen>
|
---|
485 |
|
---|
486 | <para>Also, keeping in mind your space limitations, copy any other
|
---|
487 | binaries and libraries you need to the image. Use the
|
---|
488 | <command>ldd</command> command to see which libraries you will need to
|
---|
489 | copy over for any executables. Don't forget to also strip them
|
---|
490 | <emphasis>before</emphasis> copying them to the ramdisk image or use the
|
---|
491 | <command>strip</command>, as above, to "copy" them.</para>
|
---|
492 |
|
---|
493 | <para><emphasis>Set up the lib directory</emphasis></para>
|
---|
494 |
|
---|
495 | <para>Once you have installed all the utilities from above and any
|
---|
496 | additional ones you want, use the <command>ldd</command> command, as
|
---|
497 | mentioned above, on those that were not listed in this document. If
|
---|
498 | any additional libraries are needed, add them into the setup commands
|
---|
499 | shown next.</para>
|
---|
500 |
|
---|
501 | <para>If you installed only those things shown above, the shared objects
|
---|
502 | needed will be minimal. You can add them to the ramdisk image with:</para>
|
---|
503 |
|
---|
504 | <screen><userinput><command>strip -p --strip-unneeded --remove-section=.comment \
|
---|
505 | -o /mnt/loop1/lib/libc.so.6 /lib/libc-2.3.3.so &&
|
---|
506 | strip -p --strip-unneeded --remove-section=.comment \
|
---|
507 | -o /mnt/loop1/lib/ld-linux.so.2 /lib/ld-2.3.3.so &&
|
---|
508 | strip -p --strip-unneeded --remove-section=.comment \
|
---|
509 | -o /mnt/loop1/lib/libdl.so.2 /lib/libdl-2.3.3.so &&
|
---|
510 | chmod 555 /mnt/loop1/lib/{libc.so.6,ld-linux.so.2,libdl.so.2}</command></userinput></screen>
|
---|
511 |
|
---|
512 | <para>Note that the above commands change the names of the libraries,
|
---|
513 | eliminating the need for the usual symlinks. If you add any additional
|
---|
514 | shared objects, be alert for similar opportunities and also the pitfalls
|
---|
515 | that may be present.</para>
|
---|
516 |
|
---|
517 | <para><emphasis>Make the compressed initrd</emphasis></para>
|
---|
518 |
|
---|
519 | <para>Unmount the loopback file. If you used <command>mount</command>'s
|
---|
520 | <option>-o loop</option> option, the "bond" between the loop device
|
---|
521 | and the file will be removed when the unmount is done. Just omit the
|
---|
522 | <command>losetup -d /dev/loop1</command> from the following
|
---|
523 | sequence. The <userinput>-9</userinput> parameter is used with
|
---|
524 | <command>gzip</command> to make the smallest possible compressed image. To
|
---|
525 | make sure it will fit on the diskette, list the file's size.</para>
|
---|
526 |
|
---|
527 | <screen><userinput><command>umount /mnt/loop1 &&
|
---|
528 | losetup -d /dev/loop1 && # Omit if mount's -o loop was used
|
---|
529 | gzip -9 < /tmp/rfloppy > /tmp/rootfs.gz
|
---|
530 | ls -l /tmp/rootfs.gz</command></userinput></screen>
|
---|
531 |
|
---|
532 | <para><emphasis>Join rescueimage and initrd onto a diskette</emphasis></para>
|
---|
533 |
|
---|
534 | <para>Now the rescueimage and initial ramdisk image will be written to
|
---|
535 | the boot diskette. Before doing this, calculate the number of blocks
|
---|
536 | needed for rescueimage and for <filename>/tmp/rootfs.gz</filename>
|
---|
537 | (the initial ramdisk), individually, by dividing each
|
---|
538 | size by 1024 and adding one if there is any remainder. Add these two
|
---|
539 | results together. They must total 1,440 or fewer blocks. If they total
|
---|
540 | more than this, don't worry too much. Changes to make a two-diskette
|
---|
541 | set are presented later. Of course, you could reexamine your choices and
|
---|
542 | try to shrink either the rescueimage or the initial ramdisk image.</para>
|
---|
543 |
|
---|
544 | <para>To make a single-floppy rescue, using devfs, use the following
|
---|
545 | commands. If you use the static <filename class="directory">/dev</filename> setup, use
|
---|
546 | <filename>/dev/fd0</filename> instead of the /dev/floppy/0.</para>
|
---|
547 |
|
---|
548 | <screen><userinput><command>dd if=rescueimage of=/dev/floppy/0 bs=1k
|
---|
549 | rdev /dev/floppy/0 0,0
|
---|
550 | rdev -R /dev/floppy/0 0</command></userinput></screen>
|
---|
551 |
|
---|
552 | <para><emphasis>Command explanations</emphasis></para>
|
---|
553 |
|
---|
554 | <para><command>rdev /dev/floppy/0 0,0</command>: sets the root file system
|
---|
555 | the kernel will use when it boots. Because it loads an initrd, it will
|
---|
556 | automatically set that as the root device, initially. So, the
|
---|
557 | <option>0,0</option> gives it "no value", telling the kernel to not
|
---|
558 | mount any other device. Some folks give <filename>/dev/fd0</filename> or
|
---|
559 | something similar. But this has effect <emphasis>only</emphasis> when
|
---|
560 | <command>linuxrc</command> (really <application><ulink
|
---|
561 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox
|
---|
562 | </ulink></application>) exits and the normal <command>init</command>
|
---|
563 | processes get invoked. Since this is not being done here, and the floppy
|
---|
564 | is <emphasis>not</emphasis> a valid file system, it would be useless
|
---|
565 | here. A hard drive would be a better choice if you are looking to
|
---|
566 | automatically bring the system up after repair. Since <application><ulink
|
---|
567 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox
|
---|
568 | </ulink></application> provides the <command>reboot</command> command,
|
---|
569 | automatic initialization is not needed.</para>
|
---|
570 |
|
---|
571 | <para>The <command>rdev -R /dev/floppy/0 0</command> will set the
|
---|
572 | "root flags" to zero. They have no use in this application.</para>
|
---|
573 |
|
---|
574 | <para>The <command>dd</command> from above showed some results, like</para>
|
---|
575 |
|
---|
576 | <screen> 480+1 records in
|
---|
577 | 480+1 records out</screen>
|
---|
578 |
|
---|
579 | <para>In this example the rescueimage (kernel) was 480+1 blocks in size.
|
---|
580 | Make sure that this number, which may be different for you, matches your
|
---|
581 | calculations from above. You need to calculate a "magic number" now
|
---|
582 | that will be inserted into rescueimage. The value consists of three
|
---|
583 | significant parts. Two are discussed here. The third is touched upon
|
---|
584 | later.</para>
|
---|
585 |
|
---|
586 | <para>Bits 0 - 10 will contain the size of rescueimage, in blocks,
|
---|
587 | that you calculated above, and which should match the results from the
|
---|
588 | dd above. Bit 14 (the 15th bit, which is 2 to the 14th power, or 16,384)
|
---|
589 | is a flag that, when set to 1, tells the kernel an initial ramdisk is to
|
---|
590 | be loaded. So for the single-floppy rescue diskette, the two numbers
|
---|
591 | 16,384 and 481 (or whatever number is right for your rescueimage size) are
|
---|
592 | added together to produce a decimal value, like 16865. This value is
|
---|
593 | inserted into the proper place in rescueimage by the
|
---|
594 | <command>rdev</command> command done next.</para>
|
---|
595 |
|
---|
596 | <para>Insert the "magic number" into rescueimage and then write the
|
---|
597 | root file system right after rescueimage on the floppy by executing the
|
---|
598 | following commands, with the proper numbers inserted. Notice that the
|
---|
599 | <command>seek</command> parameter's number must be the size, in blocks,
|
---|
600 | of your rescueimage. If you use the static <filename class="directory">/dev</filename>
|
---|
601 | setup, use <filename>/dev/fd0</filename> in the commands below, instead
|
---|
602 | of <filename>/dev/floppy/0</filename>.</para>
|
---|
603 |
|
---|
604 | <screen><userinput><command>rdev -r /dev/floppy/0 <replaceable>16865</replaceable>
|
---|
605 | dd if=/tmp/rootfs.gz of=/dev/floppy/0 bs=1k seek=<replaceable>481</replaceable></command></userinput></screen>
|
---|
606 |
|
---|
607 | <para>In this command, <command>seek</command> was used to position to
|
---|
608 | the block following the end of the rescueimage (480+1) and begin writing the
|
---|
609 | root file system to the floppy.</para>
|
---|
610 | </sect3>
|
---|
611 | </sect2>
|
---|
612 |
|
---|
613 | <sect2>
|
---|
614 | <title>A Two-diskette Rescue Setup</title>
|
---|
615 |
|
---|
616 | <para>If you just can't live with a single-diskette rescue system, here
|
---|
617 | is what to do to make a simple two-diskette system. Note that the
|
---|
618 | endless possibilities presented by the availability of
|
---|
619 | <command>linuxrc</command> and other components are not addressed
|
---|
620 | here. Here you will just use the kernel's ability to prompt for a second
|
---|
621 | diskette that contains the initrd image and load it.</para>
|
---|
622 |
|
---|
623 | <para>Modify the above instructions as follows. First a different magic
|
---|
624 | number is needed. The 15th bit (bit 14) still needs to be set, but the
|
---|
625 | size of the rescueimage, in blocks, is replaced with a zero. The third
|
---|
626 | component, which was not discussed above, is now used. This is the 16th
|
---|
627 | bit (bit 15) of the "magic number". When set, it tells the kernel to ask
|
---|
628 | the user to insert the "root" floppy. It then loads the initrd image
|
---|
629 | from that diskette. Because the size of the rescueimage was replaced
|
---|
630 | by zero, the kernel starts loading from the "zero'th" block (the first
|
---|
631 | one) on the second diskette.</para>
|
---|
632 |
|
---|
633 | <para>The 16th bit (bit 15) represents 2 raised to the 15th power, or
|
---|
634 | 32,768. So the new magic number is 32,768 + 16384, which is 49,152. This
|
---|
635 | value tells the kernel to prompt for, and then load, an initial ramdisk
|
---|
636 | image from the first block on the inserted floppy. So your first
|
---|
637 | modification is to the command to write the "magic number" to the rescueimage
|
---|
638 | image on the diskette.</para>
|
---|
639 |
|
---|
640 | <screen><userinput><command>rdev -r /dev/floppy/0 <replaceable>49152</replaceable></command></userinput></screen>
|
---|
641 |
|
---|
642 | <para>Note that the initrd image is <emphasis>not</emphasis> copied to
|
---|
643 | the diskette yet. Remove the boot diskette and insert another diskette
|
---|
644 | that will hold your root file system. Run this modified command (don't
|
---|
645 | forget to use <filename>/dev/fd0</filename> if you don't use devfs).
|
---|
646 | Note that no <command>seek</command> parameter is used.</para>
|
---|
647 |
|
---|
648 | <screen><userinput><command>dd if=/tmp/rootfs.gz of=/dev/floppy/0 bs=1k</command></userinput></screen>
|
---|
649 |
|
---|
650 | <para>That's all there is to it. The possibilities from here are limited only
|
---|
651 | by your imagination and tenacity in pursuing enhancements. And your
|
---|
652 | willingness to research available documentation. A good starting point
|
---|
653 | is the "Documentation" directory in your kernel source tree. More help
|
---|
654 | may be gained at
|
---|
655 | <ulink url="http://linuxfromscratch.org/hints/news.html"><acronym>LFS </acronym> Hints</ulink>
|
---|
656 | (please use a mirror site that is suitable) and
|
---|
657 | <ulink url="http://www.tldp.org">TLDP</ulink>.</para>
|
---|
658 |
|
---|
659 | </sect2>
|
---|
660 | </sect1>
|
---|