[f45b1953] | 1 | <sect1 id="postlfs-config-bootdisk">
|
---|
| 2 | <?dbhtml filename="bootdisk.html" dir="postlfs"?>
|
---|
| 3 | <title>Creating a custom bootdisk</title>
|
---|
| 4 |
|
---|
[03973ca6] | 5 | <sect2>
|
---|
| 6 | <title>How to create a decent bootdisk</title>
|
---|
[35fd1edf] | 7 | <para>The intent here is to create a "rescue bootdisk" that will load
|
---|
[cfc2a54] | 8 | enough 'linux' to enable you to do rescue operations. What is presented here
|
---|
| 9 | is enough to do file manipulation, mounting and unmounting, and other tasks.
|
---|
[9ed94cb] | 10 | This, however, is not the limit. The minimal disk is described here, and you
|
---|
| 11 | can add anything you can fit on the floppy.</para>
|
---|
[03973ca6] | 12 | </sect2>
|
---|
[9ed94cb] | 13 |
|
---|
[03973ca6] | 14 | <sect2>
|
---|
| 15 | <title>Boot Disk/Rescue Disk</title>
|
---|
[9ed94cb] | 16 |
|
---|
| 17 | <para>First we will create a loopback file on which we build the root file
|
---|
[cfc2a54] | 18 | system for our rescue disk image. This is commonly known as the initial
|
---|
| 19 | ramdisk, or initrd for short, and it is automatically loaded by the boot
|
---|
| 20 | process if all setup is done correctly.</para>
|
---|
[9ed94cb] | 21 |
|
---|
| 22 | <para>Next we'll make a file system on the loopback file and use
|
---|
| 23 | <command>mount</command> to mount the loopback file as a regular disk, allowing
|
---|
| 24 | us to read and write files there. The following commands will build us a 4 MB
|
---|
| 25 | image.</para>
|
---|
| 26 |
|
---|
| 27 | <screen><userinput><command>dd if=/dev/zero of=/tmp/rfloppy bs=1k count=4096 &&
|
---|
[cc694ec] | 28 | mke2fs -m 0 -N 2000 /tmp/rfloppy &&
|
---|
| 29 | mount -o loop /tmp/rfloppy /mnt/loop1 &&
|
---|
[9ed94cb] | 30 | rmdir /mnt/loop1/lost+found/</command></userinput></screen>
|
---|
[f45b1953] | 31 |
|
---|
[9ed94cb] | 32 | <para>Now that we have a file mounted and usable, let's prepare it to be
|
---|
[35fd1edf] | 33 | filled with useful material. Since this is only a rescue floppy we'll
|
---|
| 34 | only need to set up the minimum directories.</para>
|
---|
[9ed94cb] | 35 |
|
---|
| 36 | <screen><userinput><command>mkdir /mnt/loop1/{dev,proc,etc,sbin,bin,lib,mnt,usr,var}</command></userinput></screen>
|
---|
| 37 |
|
---|
[35fd1edf] | 38 | <para>Next, we will set up the device files. I use devfs on my system, so
|
---|
| 39 | the following command works well, as I only have the devices I use
|
---|
[9ed94cb] | 40 | anyway. If you used <command>MAKEDEV</command> to create your devices, you'll
|
---|
| 41 | want to trim the <filename>/mnt/loop1/dev</filename> directory to reclaim the
|
---|
| 42 | inode space wasted by the devices you don't use in the <filename>dev</filename>
|
---|
| 43 | directory.</para>
|
---|
| 44 |
|
---|
| 45 | <screen><userinput><command>cp -dpR /dev/* /mnt/loop1/dev</command></userinput></screen>
|
---|
| 46 |
|
---|
| 47 | <para>Now to tend to the <filename>/etc</filename> directory. To start, all we
|
---|
| 48 | will do is use the passwd and group file that worked for our static chroot
|
---|
| 49 | environment when we built <acronym>LFS</acronym>. We'll also copy the startup scripts over and a
|
---|
| 50 | few other files that serve well as starting points.</para>
|
---|
| 51 |
|
---|
| 52 | <screen><userinput><command>cp -ax /etc/rc* /mnt/loop1/etc
|
---|
[35fd1edf] | 53 | cp -ax /etc/fstab /mnt/loop1/etc
|
---|
[1a310d10] | 54 | echo "root:x:0:0:root:/root:/bin/bash" > /mnt/loop1/etc/passwd
|
---|
[9ed94cb] | 55 | cat > /mnt/loop1/etc/group << "EOF"</command>
|
---|
[35fd1edf] | 56 | root:x:0:
|
---|
| 57 | bin:x:1:
|
---|
| 58 | sys:x:2:
|
---|
| 59 | kmem:x:3:
|
---|
| 60 | tty:x:4:
|
---|
| 61 | tape:x:5:
|
---|
| 62 | daemon:x:6:
|
---|
| 63 | floppy:x:7:
|
---|
| 64 | disk:x:8:
|
---|
| 65 | lp:x:9:
|
---|
| 66 | dialout:x:10:
|
---|
| 67 | audio:x:11:
|
---|
[9ed94cb] | 68 | <command>EOF</command></userinput></screen>
|
---|
[35fd1edf] | 69 |
|
---|
[9ed94cb] | 70 | <para>To prevent automatic mounting of hard drive partitions, make sure to add
|
---|
| 71 | the noauto option in their fstab entry. Also, add the following entries to the
|
---|
| 72 | <filename>/mnt/loop1/etc/fstab</filename> to assist with mounting our
|
---|
[35fd1edf] | 73 | floppy and the ram image</para>
|
---|
[9ed94cb] | 74 |
|
---|
| 75 | <screen><userinput>/dev/ram0 / ext2 defaults
|
---|
| 76 | /dev/fd0 / ext2 defaults</userinput></screen>
|
---|
[35fd1edf] | 77 |
|
---|
[036393e1] | 78 | <para>Next, we will install <ulink
|
---|
| 79 | url="http://www.busybox.net/downloads/busybox-0.60.4.tar.bz2">busybox</ulink>
|
---|
[9ed94cb] | 80 | onto the image. Busybox incorporates many of the unix functions into a single
|
---|
| 81 | small executable file.</para>
|
---|
| 82 |
|
---|
| 83 | <screen><userinput><command>make &&
|
---|
[01600b9] | 84 | make PREFIX=/mnt/loop1 install &&
|
---|
| 85 | cp -ax /var/utmp /mnt/loop1/var &&
|
---|
[9ed94cb] | 86 | mkdir /mnt/loop1/var/log</command></userinput></screen>
|
---|
| 87 |
|
---|
| 88 | <para>Also, keeping in mind your space limitations, copy any other binaries and
|
---|
| 89 | libraries you need to the image. Use the <userinput>ldd</userinput> command to
|
---|
| 90 | see which libraries you will need to copy over for any executables.</para>
|
---|
| 91 |
|
---|
| 92 | <para>Now, since I use devfs to create devices on the fly and free up precious
|
---|
[35fd1edf] | 93 | inodes on the floppy, we'll also install devfsd to facilitate the
|
---|
| 94 | devices that busybox expects to find.</para>
|
---|
| 95 |
|
---|
[9ed94cb] | 96 | <screen><userinput><command>mv GNUmakefile Makefile &&
|
---|
[01600b9] | 97 | make &&
|
---|
| 98 | make PREFIX=/mnt/loop1 install &&
|
---|
[34a762a8] | 99 | cp /lib/libc.so.6 /lib/ld-linux.so.2 /lib/libdl.so.2 /tmp &&
|
---|
[01600b9] | 100 | strip --strip-deb /tmp/ld-linux.so.2 /tmp/libc.so.6 /tmp/libdl.so.2 &&
|
---|
[9ed94cb] | 101 | mv /tmp/ld-linux.so.2 /tmp/libc.so.6 /tmp/libdl.so.2 /mnt/loop1/lib/</command></userinput></screen>
|
---|
| 102 |
|
---|
| 103 | <para>We will also need to set up an rc script to handle the devfsd startup.
|
---|
[036393e1] | 104 | Put this in <filename>/mnt/loop1/etc/init.d/rcS</filename>.</para>
|
---|
[9ed94cb] | 105 |
|
---|
| 106 | <screen><userinput>#!/bin/sh
|
---|
[35fd1edf] | 107 | mount -t devfs devfs /dev
|
---|
[9ed94cb] | 108 | /sbin/devfsd /dev</userinput></screen>
|
---|
[35fd1edf] | 109 |
|
---|
[9ed94cb] | 110 | <para>Next create your compressed root filesystem. We use -9 with gzip to
|
---|
[35fd1edf] | 111 | make the smallest possible compressed image.</para>
|
---|
[9ed94cb] | 112 |
|
---|
| 113 | <screen><userinput><command>umount /mnt/loop1 && dd if=/tmp/rfloppy bs=1k | gzip -v9 > rootfs.gz</command></userinput></screen>
|
---|
| 114 |
|
---|
| 115 | <para><userinput><command>ls -l rootfs.gz</command></userinput> to make
|
---|
| 116 | sure it will fit on the diskette.</para>
|
---|
| 117 |
|
---|
| 118 | <para>Make a custom kernel that is optimized for size. Include only those
|
---|
| 119 | features you will need to rescue your system. no sense in building in support
|
---|
| 120 | for things like xfree86 dri, etc, as most rescues are performed from the
|
---|
| 121 | command prompt.</para>
|
---|
| 122 |
|
---|
[84cf3abc] | 123 | <screen><userinput><command>dd if=rescueimg of=/dev/floppy/0 bs=1k</command>
|
---|
[35fd1edf] | 124 | 429+1 records in
|
---|
| 125 | 429+1 records out
|
---|
[9ed94cb] | 126 | <command>rdev /dev/floppy/0 /dev/floppy/0
|
---|
| 127 | rdev -R /dev/floppy/0 0</command></userinput></screen>
|
---|
[35fd1edf] | 128 |
|
---|
[9ed94cb] | 129 | <para>In this example the rescueimage (KERNEL) was 429+1 blocks in size.
|
---|
[35fd1edf] | 130 | We will remember this for the next command. We now write the root file
|
---|
[036393e1] | 131 | system right after the kernel on the floppy by doing 16384+429+1=
|
---|
| 132 | 16814.</para>
|
---|
[35fd1edf] | 133 |
|
---|
[9ed94cb] | 134 | <screen><userinput><command>rdev -r /dev/floppy/0 16814
|
---|
| 135 | dd if=rootfs.gz of=/dev/floppy/0 bs=1k seek=430</command></userinput></screen>
|
---|
[35fd1edf] | 136 |
|
---|
[9ed94cb] | 137 | <para>In this command we use seek to find the end of the kernel (429+1) and write the root file system to the floppy.</para>
|
---|
[03973ca6] | 138 | </sect2>
|
---|
[35fd1edf] | 139 | </sect1>
|
---|