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