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