diff options
author | Mark Whitley <markw@lineo.com> | 2001-05-04 21:46:00 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2001-05-04 21:46:00 +0000 |
commit | a0ba9f45fb0c9f3e34d5a2b25e45b7e5d5cac9a4 (patch) | |
tree | 4f000c6356ba330d7cf5ade9d79a4167fb90e69f | |
parent | d24f878546806aa8fd50dc95fe3cc111ad10f92f (diff) | |
download | busybox-w32-a0ba9f45fb0c9f3e34d5a2b25e45b7e5d5cac9a4.tar.gz busybox-w32-a0ba9f45fb0c9f3e34d5a2b25e45b7e5d5cac9a4.tar.bz2 busybox-w32-a0ba9f45fb0c9f3e34d5a2b25e45b7e5d5cac9a4.zip |
Wrote documentation and scripts for creating a busybox boot floppy. Initial revision.
-rw-r--r-- | examples/bootfloppy/bootfloppy.txt | 185 | ||||
-rw-r--r-- | examples/bootfloppy/display.txt | 4 | ||||
-rw-r--r-- | examples/bootfloppy/etc/fstab | 2 | ||||
-rwxr-xr-x | examples/bootfloppy/etc/init.d/rcS | 3 | ||||
-rw-r--r-- | examples/bootfloppy/etc/inittab | 5 | ||||
-rw-r--r-- | examples/bootfloppy/etc/profile | 8 | ||||
-rwxr-xr-x | examples/bootfloppy/mkdevs.sh | 62 | ||||
-rwxr-xr-x | examples/bootfloppy/mkrootfs.sh | 106 | ||||
-rwxr-xr-x | examples/bootfloppy/mksyslinux.sh | 48 | ||||
-rw-r--r-- | examples/bootfloppy/quickstart.txt | 15 | ||||
-rw-r--r-- | examples/bootfloppy/syslinux.cfg | 7 |
11 files changed, 445 insertions, 0 deletions
diff --git a/examples/bootfloppy/bootfloppy.txt b/examples/bootfloppy/bootfloppy.txt new file mode 100644 index 000000000..575c93fcc --- /dev/null +++ b/examples/bootfloppy/bootfloppy.txt | |||
@@ -0,0 +1,185 @@ | |||
1 | Building a Busybox Boot Floppy | ||
2 | ============================== | ||
3 | |||
4 | This document describes how to buid a boot floppy using the following | ||
5 | components: | ||
6 | |||
7 | - Linux Kernel (http://www.kernel.org) | ||
8 | - uClibc: C library (http://cvs.uclinux.org/uClibc.html) | ||
9 | - Busybox: Unix utilities (http://busybox.lineo.com) | ||
10 | - Syslinux: bootloader (http://syslinux.zytor.com) | ||
11 | |||
12 | It is based heavily on a paper presented by Erik Andersen at the 2001 Embedded | ||
13 | Systems Conference. | ||
14 | |||
15 | |||
16 | |||
17 | Building The Software Components | ||
18 | -------------------------------- | ||
19 | |||
20 | Detailed instructions on how to build Busybox, uClibc, or a working Linux | ||
21 | kernel are beyond the scope of this document. The following guidelines will | ||
22 | help though: | ||
23 | |||
24 | - Stock Busybox from CVS or a tarball will work with no modifications to | ||
25 | any files. Just extract and go. | ||
26 | - Ditto uClibc. | ||
27 | - Your Linux kernel must include support for initrd or else the floppy | ||
28 | won't be able to mount it's root file system. | ||
29 | |||
30 | If you require further information on building Busybox uClibc or Linux, please | ||
31 | refer to the web pages and documentation for those individual programs. | ||
32 | |||
33 | |||
34 | |||
35 | Making a Root File System | ||
36 | ------------------------- | ||
37 | |||
38 | The following steps will create a root file system. | ||
39 | |||
40 | - Create an empty file that you can format as a filesystem: | ||
41 | |||
42 | dd if=/dev/zero of=rootfs bs=1k count=4000 | ||
43 | |||
44 | - Set up the rootfs file we just created to be used as a loop device (may not | ||
45 | be necessary) | ||
46 | |||
47 | losetup /dev/loop0 rootfs | ||
48 | |||
49 | - Format the rootfs file with a filesystem: | ||
50 | |||
51 | mkfs.ext2 -F -i 2000 rootfs | ||
52 | |||
53 | - Mount the file on a mountpoint so we can place files in it: | ||
54 | |||
55 | mkdir loop | ||
56 | mount -o loop rootfs loop/ | ||
57 | |||
58 | (you will probably need to be root to do this) | ||
59 | |||
60 | - Copy on the C library, the dynamic linking library, and other necessary | ||
61 | libraries. For this example, we copy the following files from the uClibc | ||
62 | tree: | ||
63 | |||
64 | mkdir loop/lib | ||
65 | (chdir to uClibc directory) | ||
66 | cp -a libc.so* uClibc*.so \ | ||
67 | ld.so-1/d-link/ld-linux-uclibc.so* \ | ||
68 | ld.so-1/libdl/libdl.so* \ | ||
69 | crypt/libcrypt.so* \ | ||
70 | (path to)loop/lib | ||
71 | |||
72 | - Install the Busybox binary and accompanying symlinks: | ||
73 | |||
74 | (chdir to busybox directory) | ||
75 | make PREFIX=(path to)loop/ install | ||
76 | |||
77 | - Make device files in /dev: | ||
78 | |||
79 | This can be done by running the 'mkdevs.sh' script. If you want the gory | ||
80 | details, you can read the script. | ||
81 | |||
82 | - Make necessary files in /etc: | ||
83 | |||
84 | For this, just cp -a the etc/ directory onto rootfs. Again, if you want | ||
85 | all the details, you can just look at the files in the dir. | ||
86 | |||
87 | - Run ldconfig so busybox and other binaries can have access to the libraries | ||
88 | that they need: | ||
89 | |||
90 | (path to)uClibc/ld.so-1/util/ldconfig -r loop/ | ||
91 | |||
92 | - Unmount the rootfs from the mountpoint: | ||
93 | |||
94 | umount loop | ||
95 | |||
96 | - Compress it: | ||
97 | |||
98 | gzip -9 rootfs | ||
99 | |||
100 | |||
101 | Making a SYSLINUX boot floppy | ||
102 | ----------------------------- | ||
103 | |||
104 | The following steps will create the boot floppy. | ||
105 | |||
106 | Note: You will need to have the mtools package installed beforehand. | ||
107 | |||
108 | - Insert a floppy in the drive and format it with an MSDOS filesystem: | ||
109 | |||
110 | mformat a: | ||
111 | |||
112 | (if the system doesn't know what device 'a:' is, look at /etc/mtools.conf) | ||
113 | |||
114 | - Run syslinux on the floppy: | ||
115 | |||
116 | syslinux -s /dev/fd0 | ||
117 | |||
118 | (the -s stands for "safe, slow, and stupid" and should work better with | ||
119 | buggy BIOSes; it can be omitted) | ||
120 | |||
121 | - Put on a syslinux.cfg file: | ||
122 | |||
123 | mcopy syslinux.cfg a: | ||
124 | |||
125 | (more on syslinux.cfg below) | ||
126 | |||
127 | - Copy the root file system you made onto the MSDOS formatted floppy | ||
128 | |||
129 | mcopy rootfs.gz a: | ||
130 | |||
131 | - Build a linux kernel and copy it onto the disk with the filename 'linux' | ||
132 | |||
133 | mcopy bzImage a:linux | ||
134 | |||
135 | |||
136 | Sample syslinux.cfg | ||
137 | ~~~~~~~~~~~~~~~~~~~ | ||
138 | |||
139 | The following simple syslinux.cfg file should work. You can tweak it if you | ||
140 | like. | ||
141 | |||
142 | ----begin-syslinux.cfg--------------- | ||
143 | DEFAULT linux | ||
144 | APPEND initrd=rootfs.gz root=/dev/ram0 | ||
145 | TIMEOUT 10 | ||
146 | PROMPT 1 | ||
147 | ----end-syslinux.cfg--------------- | ||
148 | |||
149 | Some changes you could make to syslinux.cfg: | ||
150 | |||
151 | - This value is the number seconds it will wait before booting. You can set | ||
152 | the timeout to 0 (or omit) to boot instantly, or you can set it as high as | ||
153 | 10 to wait awhile. | ||
154 | |||
155 | - PROMPT can be set to 0 to disable the 'boot:' prompt. | ||
156 | |||
157 | - you can add this line to display the contents of a file as a welcome | ||
158 | message: | ||
159 | |||
160 | DISPLAY display.txt | ||
161 | |||
162 | |||
163 | |||
164 | Additional Resources | ||
165 | -------------------- | ||
166 | |||
167 | Other useful information on making a Linux bootfloppy is available at the | ||
168 | following URLs: | ||
169 | |||
170 | http://www.linuxdoc.org/HOWTO/Bootdisk-HOWTO/index.html | ||
171 | http://www.linux-embedded.com/howto/Embedded-Linux-Howto.html | ||
172 | http://linux-embedded.org/howto/LFS-HOWTO.html | ||
173 | http://linux-embedded.org/pmhowto.html | ||
174 | http://recycle.lbl.gov/~ldoolitt/embedded/ (Larry Doolittle's stuff) | ||
175 | |||
176 | |||
177 | |||
178 | Possible TODOs | ||
179 | -------------- | ||
180 | |||
181 | The following features that we might want to add later: | ||
182 | |||
183 | - support for additional filesystems besides ext2, i.e. minix | ||
184 | - different libc, static vs dynamic loading | ||
185 | - maybe using an alternate bootloader | ||
diff --git a/examples/bootfloppy/display.txt b/examples/bootfloppy/display.txt new file mode 100644 index 000000000..399d326d9 --- /dev/null +++ b/examples/bootfloppy/display.txt | |||
@@ -0,0 +1,4 @@ | |||
1 | |||
2 | This boot floppy is made with Busybox, uClibc, and the Linux kernel. | ||
3 | Hit RETURN to boot or enter boot parameters at the prompt below. | ||
4 | |||
diff --git a/examples/bootfloppy/etc/fstab b/examples/bootfloppy/etc/fstab new file mode 100644 index 000000000..ef14ca2cc --- /dev/null +++ b/examples/bootfloppy/etc/fstab | |||
@@ -0,0 +1,2 @@ | |||
1 | proc /proc proc defaults 0 0 | ||
2 | |||
diff --git a/examples/bootfloppy/etc/init.d/rcS b/examples/bootfloppy/etc/init.d/rcS new file mode 100755 index 000000000..4f29b923f --- /dev/null +++ b/examples/bootfloppy/etc/init.d/rcS | |||
@@ -0,0 +1,3 @@ | |||
1 | #! /bin/sh | ||
2 | |||
3 | /bin/mount -a | ||
diff --git a/examples/bootfloppy/etc/inittab b/examples/bootfloppy/etc/inittab new file mode 100644 index 000000000..eb3e979ce --- /dev/null +++ b/examples/bootfloppy/etc/inittab | |||
@@ -0,0 +1,5 @@ | |||
1 | ::sysinit:/etc/init.d/rcS | ||
2 | ::respawn:-/bin/sh | ||
3 | tty2::askfirst:-/bin/sh | ||
4 | ::ctrlaltdel:/bin/umount -a -r | ||
5 | |||
diff --git a/examples/bootfloppy/etc/profile b/examples/bootfloppy/etc/profile new file mode 100644 index 000000000..e9b11e90a --- /dev/null +++ b/examples/bootfloppy/etc/profile | |||
@@ -0,0 +1,8 @@ | |||
1 | # /etc/profile: system-wide .profile file for the Bourne shells | ||
2 | |||
3 | echo | ||
4 | echo -n "Processing /etc/profile... " | ||
5 | # no-op | ||
6 | echo "Done" | ||
7 | echo | ||
8 | |||
diff --git a/examples/bootfloppy/mkdevs.sh b/examples/bootfloppy/mkdevs.sh new file mode 100755 index 000000000..03a1a8550 --- /dev/null +++ b/examples/bootfloppy/mkdevs.sh | |||
@@ -0,0 +1,62 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # makedev.sh - creates device files for a busybox boot floppy image | ||
4 | |||
5 | |||
6 | # we do our work in the dev/ directory | ||
7 | if [ -z "$1" ]; then | ||
8 | echo "usage: `basename $0` path/to/dev/dir" | ||
9 | exit 1 | ||
10 | fi | ||
11 | |||
12 | cd $1 | ||
13 | |||
14 | |||
15 | # miscellaneous one-of-a-kind stuff | ||
16 | mknod console c 5 1 | ||
17 | mknod full c 1 7 | ||
18 | mknod kmem c 1 2 | ||
19 | mknod mem c 1 1 | ||
20 | mknod null c 1 3 | ||
21 | mknod port c 1 4 | ||
22 | mknod random c 1 8 | ||
23 | mknod urandom c 1 9 | ||
24 | mknod zero c 1 5 | ||
25 | ln -s /proc/kcore core | ||
26 | |||
27 | # IDE HD devs | ||
28 | # note: not going to bother creating all concievable partitions; you can do | ||
29 | # that yourself as you need 'em. | ||
30 | mknod hda b 3 0 | ||
31 | mknod hdb b 3 64 | ||
32 | mknod hdc b 22 0 | ||
33 | mknod hdd b 22 64 | ||
34 | |||
35 | # loop devs | ||
36 | for i in `seq 0 7`; do | ||
37 | mknod loop$i b 7 $i | ||
38 | done | ||
39 | |||
40 | # ram devs | ||
41 | for i in `seq 0 9`; do | ||
42 | mknod ram$i b 1 $i | ||
43 | done | ||
44 | ln -s ram1 ram | ||
45 | |||
46 | # ttys | ||
47 | mknod tty c 5 0 | ||
48 | for i in `seq 0 9`; do | ||
49 | mknod tty$i c 4 $i | ||
50 | done | ||
51 | |||
52 | # virtual console screen devs | ||
53 | for i in `seq 0 9`; do | ||
54 | mknod vcs$i b 7 $i | ||
55 | done | ||
56 | ln -s vcs0 vcs | ||
57 | |||
58 | # virtual console screen w/ attributes devs | ||
59 | for i in `seq 0 9`; do | ||
60 | mknod vcsa$i b 7 $i | ||
61 | done | ||
62 | ln -s vcsa0 vcsa | ||
diff --git a/examples/bootfloppy/mkrootfs.sh b/examples/bootfloppy/mkrootfs.sh new file mode 100755 index 000000000..cd6bef632 --- /dev/null +++ b/examples/bootfloppy/mkrootfs.sh | |||
@@ -0,0 +1,106 @@ | |||
1 | #!/bin/bash | ||
2 | # | ||
3 | # mkrootfs.sh - creates a root file system | ||
4 | # | ||
5 | |||
6 | # TODO: need to add checks here to verify that busybox, uClibc and bzImage | ||
7 | # exist | ||
8 | |||
9 | |||
10 | # command-line settable variables | ||
11 | BUSYBOX_DIR=.. | ||
12 | UCLIBC_DIR=../../uClibc | ||
13 | TARGET_DIR=./loop | ||
14 | FSSIZE=4000 | ||
15 | CLEANUP=1 | ||
16 | MKFS='mkfs.ext2 -F' | ||
17 | |||
18 | # don't-touch variables | ||
19 | BASE_DIR=`pwd` | ||
20 | |||
21 | |||
22 | while getopts 'b:u:s:t:Cm' opt | ||
23 | do | ||
24 | case $opt in | ||
25 | b) BUSYBOX_DIR=$OPTARG ;; | ||
26 | u) UCLIBC_DIR=$OPTARG ;; | ||
27 | t) TARGET_DIR=$OPTARG ;; | ||
28 | s) FSSIZE=$OPTARG ;; | ||
29 | C) CLEANUP=0 ;; | ||
30 | m) MKFS='mkfs.minix' ;; | ||
31 | *) | ||
32 | echo "usage: `basename $0` [-bu]" | ||
33 | echo " -b DIR path to busybox direcory (default ..)" | ||
34 | echo " -u DIR path to uClibc direcory (default ../../uClibc)" | ||
35 | echo " -t DIR path to target direcory (default ./loop)" | ||
36 | echo " -s SIZE size of root filesystem in Kbytes (default 4000)" | ||
37 | echo " -C don't perform cleanup (umount target dir, gzip rootfs, etc.)" | ||
38 | echo " (this allows you to 'chroot loop/ /bin/sh' to test it)" | ||
39 | echo " -m use minix filesystem (default is ext2)" | ||
40 | exit 1 | ||
41 | ;; | ||
42 | esac | ||
43 | done | ||
44 | |||
45 | |||
46 | |||
47 | |||
48 | # clean up from any previous work | ||
49 | mount | grep -q loop | ||
50 | [ $? -eq 0 ] && umount $TARGET_DIR | ||
51 | [ -d $TARGET_DIR ] && rm -rf $TARGET_DIR/ | ||
52 | [ -f rootfs ] && rm -f rootfs | ||
53 | [ -f rootfs.gz ] && rm -f rootfs.gz | ||
54 | |||
55 | |||
56 | # prepare root file system and mount as loopback | ||
57 | dd if=/dev/zero of=rootfs bs=1k count=$FSSIZE | ||
58 | $MKFS -i 2000 rootfs | ||
59 | mkdir $TARGET_DIR | ||
60 | mount -o loop,exec rootfs $TARGET_DIR # must be root | ||
61 | |||
62 | |||
63 | # install uClibc | ||
64 | mkdir -p $TARGET_DIR/lib | ||
65 | cd $UCLIBC_DIR | ||
66 | make INSTALL_DIR= | ||
67 | cp -a libc.so* $BASE_DIR/$TARGET_DIR/lib | ||
68 | cp -a uClibc*.so $BASE_DIR/$TARGET_DIR/lib | ||
69 | cp -a ld.so-1/d-link/ld-linux-uclibc.so* $BASE_DIR/$TARGET_DIR/lib | ||
70 | cp -a ld.so-1/libdl/libdl.so* $BASE_DIR/$TARGET_DIR/lib | ||
71 | cp -a crypt/libcrypt.so* $BASE_DIR/$TARGET_DIR/lib | ||
72 | cd $BASE_DIR | ||
73 | |||
74 | |||
75 | # install busybox and components | ||
76 | cd $BUSYBOX_DIR | ||
77 | make distclean | ||
78 | make CC=$BASE_DIR/$UCLIBC_DIR/extra/gcc-uClibc/i386-uclibc-gcc | ||
79 | make PREFIX=bootfloppy/loop install | ||
80 | cd $BASE_DIR | ||
81 | |||
82 | |||
83 | # make files in /dev | ||
84 | mkdir $TARGET_DIR/dev | ||
85 | ./mkdevs.sh $TARGET_DIR/dev | ||
86 | |||
87 | |||
88 | # make files in /etc | ||
89 | cp -a etc $TARGET_DIR | ||
90 | ln -s /proc/mounts $TARGET_DIR/etc/mtab | ||
91 | |||
92 | |||
93 | # other miscellaneous setup | ||
94 | mkdir $TARGET_DIR/initrd | ||
95 | mkdir $TARGET_DIR/proc | ||
96 | $UCLIBC_DIR/ld.so-1/util/ldconfig -r $TARGET_DIR | ||
97 | |||
98 | |||
99 | # Done. Maybe do cleanup. | ||
100 | if [ $CLEANUP -eq 1 ] | ||
101 | then | ||
102 | umount $TARGET_DIR | ||
103 | rmdir $TARGET_DIR | ||
104 | gzip -9 rootfs | ||
105 | fi | ||
106 | |||
diff --git a/examples/bootfloppy/mksyslinux.sh b/examples/bootfloppy/mksyslinux.sh new file mode 100755 index 000000000..e25417353 --- /dev/null +++ b/examples/bootfloppy/mksyslinux.sh | |||
@@ -0,0 +1,48 @@ | |||
1 | #!/bin/bash | ||
2 | # | ||
3 | # Formats a floppy to use Syslinux | ||
4 | |||
5 | dummy="" | ||
6 | |||
7 | |||
8 | # need to have mtools installed | ||
9 | if [ -z `which mformat` -o -z `which mcopy` ]; then | ||
10 | echo "You must have the mtools package installed to run this script" | ||
11 | exit 1 | ||
12 | fi | ||
13 | |||
14 | |||
15 | # need an arg for the location of the kernel | ||
16 | if [ -z "$1" ]; then | ||
17 | echo "usage: `basename $0` path/to/linux/kernel" | ||
18 | exit 1 | ||
19 | fi | ||
20 | |||
21 | |||
22 | # need to have a root file system built | ||
23 | if [ ! -f rootfs.gz ]; then | ||
24 | echo "You need to have a rootfs built first." | ||
25 | echo "Hit RETURN to make one now or Control-C to quit." | ||
26 | read dummy | ||
27 | ./mkrootfs.sh | ||
28 | fi | ||
29 | |||
30 | |||
31 | # prepare the floppy | ||
32 | echo "Please insert a blank floppy in the drive and press RETURN to format" | ||
33 | echo "(WARNING: All data will be erased! Hit Control-C to abort)" | ||
34 | read dummy | ||
35 | |||
36 | echo "Formatting the floppy..." | ||
37 | mformat a: | ||
38 | echo "Making it bootable with Syslinux..." | ||
39 | syslinux -s /dev/fd0 | ||
40 | echo "Copying Syslinux configuration files..." | ||
41 | mcopy syslinux.cfg display.txt a: | ||
42 | echo "Copying root filesystem file..." | ||
43 | mcopy rootfs.gz a: | ||
44 | # XXX: maybe check for "no space on device" errors here | ||
45 | echo "Copying linux kernel..." | ||
46 | mcopy $1 a:linux | ||
47 | # XXX: maybe check for "no space on device" errors here too | ||
48 | echo "Finished: boot floppy created" | ||
diff --git a/examples/bootfloppy/quickstart.txt b/examples/bootfloppy/quickstart.txt new file mode 100644 index 000000000..0d8090824 --- /dev/null +++ b/examples/bootfloppy/quickstart.txt | |||
@@ -0,0 +1,15 @@ | |||
1 | Quickstart on making the Busybox boot-floppy: | ||
2 | |||
3 | 1) Download Busybox and uClibc from CVS or tarballs. Make sure they share a | ||
4 | common parent directory. (i.e. busybox/ and uclibc/ are both right off of | ||
5 | /tmp, or wherever.) | ||
6 | |||
7 | 2) Build a Linux kernel. Make sure you include support for initrd. | ||
8 | |||
9 | 3) Put a floppy in the drive. Make sure it is a floppy you don't care about | ||
10 | because the contents will be overwritten. | ||
11 | |||
12 | 4) As root, type ./mksyslinux.sh path/to/linux/kernel from this directory. | ||
13 | Wait patiently while the magic happens. | ||
14 | |||
15 | 5) Boot up on the floppy. | ||
diff --git a/examples/bootfloppy/syslinux.cfg b/examples/bootfloppy/syslinux.cfg new file mode 100644 index 000000000..8d407cad4 --- /dev/null +++ b/examples/bootfloppy/syslinux.cfg | |||
@@ -0,0 +1,7 @@ | |||
1 | display display.txt | ||
2 | default linux | ||
3 | timeout 10 | ||
4 | prompt 1 | ||
5 | label linux | ||
6 | kernel linux | ||
7 | append initrd=rootfs.gz root=/dev/ram0 | ||