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