aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2001-05-04 21:46:00 +0000
committerMark Whitley <markw@lineo.com>2001-05-04 21:46:00 +0000
commita0ba9f45fb0c9f3e34d5a2b25e45b7e5d5cac9a4 (patch)
tree4f000c6356ba330d7cf5ade9d79a4167fb90e69f
parentd24f878546806aa8fd50dc95fe3cc111ad10f92f (diff)
downloadbusybox-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.txt185
-rw-r--r--examples/bootfloppy/display.txt4
-rw-r--r--examples/bootfloppy/etc/fstab2
-rwxr-xr-xexamples/bootfloppy/etc/init.d/rcS3
-rw-r--r--examples/bootfloppy/etc/inittab5
-rw-r--r--examples/bootfloppy/etc/profile8
-rwxr-xr-xexamples/bootfloppy/mkdevs.sh62
-rwxr-xr-xexamples/bootfloppy/mkrootfs.sh106
-rwxr-xr-xexamples/bootfloppy/mksyslinux.sh48
-rw-r--r--examples/bootfloppy/quickstart.txt15
-rw-r--r--examples/bootfloppy/syslinux.cfg7
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 @@
1Building a Busybox Boot Floppy
2==============================
3
4This document describes how to buid a boot floppy using the following
5components:
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
12It is based heavily on a paper presented by Erik Andersen at the 2001 Embedded
13Systems Conference.
14
15
16
17Building The Software Components
18--------------------------------
19
20Detailed instructions on how to build Busybox, uClibc, or a working Linux
21kernel are beyond the scope of this document. The following guidelines will
22help 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
30If you require further information on building Busybox uClibc or Linux, please
31refer to the web pages and documentation for those individual programs.
32
33
34
35Making a Root File System
36-------------------------
37
38The 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
101Making a SYSLINUX boot floppy
102-----------------------------
103
104The following steps will create the boot floppy.
105
106Note: 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
136Sample syslinux.cfg
137~~~~~~~~~~~~~~~~~~~
138
139The following simple syslinux.cfg file should work. You can tweak it if you
140like.
141
142----begin-syslinux.cfg---------------
143DEFAULT linux
144APPEND initrd=rootfs.gz root=/dev/ram0
145TIMEOUT 10
146PROMPT 1
147----end-syslinux.cfg---------------
148
149Some 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
164Additional Resources
165--------------------
166
167Other useful information on making a Linux bootfloppy is available at the
168following URLs:
169
170http://www.linuxdoc.org/HOWTO/Bootdisk-HOWTO/index.html
171http://www.linux-embedded.com/howto/Embedded-Linux-Howto.html
172http://linux-embedded.org/howto/LFS-HOWTO.html
173http://linux-embedded.org/pmhowto.html
174http://recycle.lbl.gov/~ldoolitt/embedded/ (Larry Doolittle's stuff)
175
176
177
178Possible TODOs
179--------------
180
181The 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
2This boot floppy is made with Busybox, uClibc, and the Linux kernel.
3Hit 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 @@
1proc /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
3tty2::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
3echo
4echo -n "Processing /etc/profile... "
5# no-op
6echo "Done"
7echo
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
7if [ -z "$1" ]; then
8 echo "usage: `basename $0` path/to/dev/dir"
9 exit 1
10fi
11
12cd $1
13
14
15# miscellaneous one-of-a-kind stuff
16mknod console c 5 1
17mknod full c 1 7
18mknod kmem c 1 2
19mknod mem c 1 1
20mknod null c 1 3
21mknod port c 1 4
22mknod random c 1 8
23mknod urandom c 1 9
24mknod zero c 1 5
25ln -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.
30mknod hda b 3 0
31mknod hdb b 3 64
32mknod hdc b 22 0
33mknod hdd b 22 64
34
35# loop devs
36for i in `seq 0 7`; do
37 mknod loop$i b 7 $i
38done
39
40# ram devs
41for i in `seq 0 9`; do
42 mknod ram$i b 1 $i
43done
44ln -s ram1 ram
45
46# ttys
47mknod tty c 5 0
48for i in `seq 0 9`; do
49 mknod tty$i c 4 $i
50done
51
52# virtual console screen devs
53for i in `seq 0 9`; do
54 mknod vcs$i b 7 $i
55done
56ln -s vcs0 vcs
57
58# virtual console screen w/ attributes devs
59for i in `seq 0 9`; do
60 mknod vcsa$i b 7 $i
61done
62ln -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
11BUSYBOX_DIR=..
12UCLIBC_DIR=../../uClibc
13TARGET_DIR=./loop
14FSSIZE=4000
15CLEANUP=1
16MKFS='mkfs.ext2 -F'
17
18# don't-touch variables
19BASE_DIR=`pwd`
20
21
22while getopts 'b:u:s:t:Cm' opt
23do
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
43done
44
45
46
47
48# clean up from any previous work
49mount | 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
57dd if=/dev/zero of=rootfs bs=1k count=$FSSIZE
58$MKFS -i 2000 rootfs
59mkdir $TARGET_DIR
60mount -o loop,exec rootfs $TARGET_DIR # must be root
61
62
63# install uClibc
64mkdir -p $TARGET_DIR/lib
65cd $UCLIBC_DIR
66make INSTALL_DIR=
67cp -a libc.so* $BASE_DIR/$TARGET_DIR/lib
68cp -a uClibc*.so $BASE_DIR/$TARGET_DIR/lib
69cp -a ld.so-1/d-link/ld-linux-uclibc.so* $BASE_DIR/$TARGET_DIR/lib
70cp -a ld.so-1/libdl/libdl.so* $BASE_DIR/$TARGET_DIR/lib
71cp -a crypt/libcrypt.so* $BASE_DIR/$TARGET_DIR/lib
72cd $BASE_DIR
73
74
75# install busybox and components
76cd $BUSYBOX_DIR
77make distclean
78make CC=$BASE_DIR/$UCLIBC_DIR/extra/gcc-uClibc/i386-uclibc-gcc
79make PREFIX=bootfloppy/loop install
80cd $BASE_DIR
81
82
83# make files in /dev
84mkdir $TARGET_DIR/dev
85./mkdevs.sh $TARGET_DIR/dev
86
87
88# make files in /etc
89cp -a etc $TARGET_DIR
90ln -s /proc/mounts $TARGET_DIR/etc/mtab
91
92
93# other miscellaneous setup
94mkdir $TARGET_DIR/initrd
95mkdir $TARGET_DIR/proc
96$UCLIBC_DIR/ld.so-1/util/ldconfig -r $TARGET_DIR
97
98
99# Done. Maybe do cleanup.
100if [ $CLEANUP -eq 1 ]
101then
102 umount $TARGET_DIR
103 rmdir $TARGET_DIR
104 gzip -9 rootfs
105fi
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
5dummy=""
6
7
8# need to have mtools installed
9if [ -z `which mformat` -o -z `which mcopy` ]; then
10 echo "You must have the mtools package installed to run this script"
11 exit 1
12fi
13
14
15# need an arg for the location of the kernel
16if [ -z "$1" ]; then
17 echo "usage: `basename $0` path/to/linux/kernel"
18 exit 1
19fi
20
21
22# need to have a root file system built
23if [ ! -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
28fi
29
30
31# prepare the floppy
32echo "Please insert a blank floppy in the drive and press RETURN to format"
33echo "(WARNING: All data will be erased! Hit Control-C to abort)"
34read dummy
35
36echo "Formatting the floppy..."
37mformat a:
38echo "Making it bootable with Syslinux..."
39syslinux -s /dev/fd0
40echo "Copying Syslinux configuration files..."
41mcopy syslinux.cfg display.txt a:
42echo "Copying root filesystem file..."
43mcopy rootfs.gz a:
44# XXX: maybe check for "no space on device" errors here
45echo "Copying linux kernel..."
46mcopy $1 a:linux
47# XXX: maybe check for "no space on device" errors here too
48echo "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 @@
1Quickstart 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 @@
1display display.txt
2default linux
3timeout 10
4prompt 1
5label linux
6 kernel linux
7 append initrd=rootfs.gz root=/dev/ram0