1 AUTHOR: Csaba Henk <ekho@math-inst.hu>
5 LICENSE: The MIT License
7 SYNOPSIS: Making an uClibc-based bootfloppy
9 PRIMARY URI: http://www.math-inst.hu/~ekho/lowlife/
12 This hints shows how to create a cutting-edge bootfloppy from scratch,
13 based on uClibc, a lightweight C library.
16 This hint should be useable on any not too aged Linux installation with
17 a non-broken toolchain. It was tested on a (by and large) LFS-4.0
18 system. The sudo utility is advised to have.
21 http://www.linuxfromscratch.org/hints/downloads/attachments/uclibc-bootfloppy/busybox-0.60.5-Config.h
22 http://www.linuxfromscratch.org/hints/downloads/attachments/uclibc-bootfloppy/linux-2.4.22-.config
23 http://www.linuxfromscratch.org/hints/downloads/attachments/uclibc-bootfloppy/mkbootdisk
24 http://www.linuxfromscratch.org/patches/downloads/devfsd/devfsd-1.3.25-uclibc-1.patch
35 Setting up the development environment
36 Compiling the linux kernel
37 Installing uClibc on the development platform
38 Creating the root filesystem
39 Installing uClibc for the bootdisk
44 Bugs and weirdnesses, todo
49 * This hint is co-developed with the svnc-thinclient hint in the
50 framework of the lowlife project,
52 http://www.math-inst.hu/~ekho/lowlife/
54 This file belongs to lowlife-0.5.1.
56 * For the most recent version check out
58 http://www.math-inst.hu/~ekho/lowlife/uclibc-bootfloppy.txt
60 * Comments, ideas, critics, flames are welcome.
62 * (If you are an LFS user, you can skip this.) Although this document is
63 formally an LFS hint, you can see use of it without knowing what LFS is
64 (I tried to write it keeping this possibility in mind). Anyway, I
65 recommend you to check out what LFS is. If you are not familiar with
66 compiling source code in unix/linux environment, then there is no use of
67 going on without checking out what LFS is. Consult the following docs
70 http://www.linuxfromscratch.org/lfs/whatislfs.html
71 http://www.linuxfromscratch.org/faq/
72 http://www.linuxfromscratch.org/hints/downloads/files/essential_prereading.txt
73 http://www.linuxfromscratch.org/lfs/view/stable/preface/prerequisites.html
78 When you are to put together a Linux bootfloppy, you need to decide what
79 implementation of the standard C libraries will you use.
81 One possibility is using the C library implementation which is common on
82 Linux based systems: glibc. It's advantage is that you have it at hand:
83 to make a glibc-based bootfloppy, the only thing you have to do is to is
84 to copy the necessary libs to the filesystem you will put on the floppy.
85 This is way chosen by the rescue floppy described in the BLFS-book:
87 http://linuxfromscratch.org/blfs/view/test/postlfs/bootdisk.html
89 However, glibc is far from being lightweight, and eats up much of the
90 rather limited space you have when working with a floppy. So you might
91 like seek for an alternative which suits much better to the capabilities
92 of the floppy environment.
94 Here we will create a bootfloppy based on the uClibc C library, which is
95 just made for such purposes.
97 The bootfloppy will be cutting edge: uses uClibc and Busybox which are
98 actively developed projects for the embedded platform. Moreover, I used
99 a kernel from the 2.4.* branch (but feel free to use other kernel
100 releases). It is a good question to ask whether this is useful: many floppy
101 distros use older kernels for reducing resource usage. I can say the
102 following: on the one hand, I can afford using a recent kernel as my
103 bootfloppy merrily runs on my 486 with 8M RAM; on the other hand, from
104 the moment I began to use this up-to-date stuff, the problems with handling
105 the terminal buffer and plip timeouts vanished. So unless you are really
106 tight in resources, I think using a recent kernel is a good idea.
108 We will also use some kind of development environment, just to stay on
111 This hint has a continuation: there we will describe how to install the
112 svga vncviewer on the bootfloppy, which then becomes capable of turning a
113 machine to an X terminal. (Check out the svnc-thinclient hint:
115 http://www.linuxfromscratch.org/hints/downloads/files/svnc-thinclient.txt
116 http://www.math-inst.hu/~ekho/lowlife/svnc-thinclient.txt
120 Additional info and downloadable bootdisk image with svnc can be found
121 at the lowlife homepage (or at its mirror):
123 http://www.math-inst.hu/~ekho/lowlife/
124 http://www.personal.ceu.hu/students/01/Csaba_Henk/lowlife/
126 In this hint the assumption of using an x86 PC (both for making and
127 booting the floppy) and gcc is set. You may try to port it to another
128 architecture / compiler. Doing it on another architecture should not
129 be hard. Doing it with another compiler depends on how much does
130 uClibc support that compiler.
132 If you copy command from this hint to your shell, be careful that
133 line-terminating backslashes (\) keep their position (no whitespace
134 characters should follow them). A possible solution is open this hint in
135 the Vim GUI, and copy'n'paste from there.
140 We will need the following programs; in general, most recent stable
141 versions are recommended. Those programs where I have a certain
142 important comment on the version are marked with (!) and you can find
143 the comment at the beginning of the respective install instructons.
145 * Addons for the development platform:
148 ftp://ftp.sudo.ws/pub/sudo/
150 * Programs for the bootfloppy:
153 http://www.kernel.org
155 http://www.uclibc.org/downloads/
157 http://www.busybox.net/downloads/
159 ftp://arcana.linux.it/pub/gpm
164 In LFS, bootstrapping a linux system goes in the following fashion: one
165 first installs kernel headers, then builds a toolchain against these
166 headers, finally builds a kernel using the shiny new toolchain.
168 We don't need to produce a new toolchain: we will use the one of the
169 host distro (to which we'll refer as "development environment") (though
170 when making the userspace of our tiny linux system, we will access that
171 toolchain via the uClibc wrappers).
173 This lets us to proceed in a much simpler way: first we compile the
174 kernel, then build uClibc using the headers of this kernel, finally
175 build the userspace against uClibc.
177 We will use optimization for size (we'll pass the -Os flag to gcc). In
178 general you can delete sources after compilation if there is no specific
179 reasons to keep them. In those cases when you should *not* delete the
180 source I'll tell about it explicitly.
182 Setting up the development environment
183 --------------------------------------
185 We definitely need some kind of development environment to protect
186 us from mucking up our system; eg., if we are in the file system
187 which we will put on the floppy, it is very easy to mistake usr with
188 /usr, and without such a protection, you can imagine that this
189 mistake can have serious consequences...
191 We will create a non-privileged user named bootdisk for doing the
192 job. First choose a home directory for bootdisk and store this value
193 in $BDISKHOME. Then type:
196 useradd -g bootdisk -s /bin/bash -d $BDISKHOME bootdisk &&
197 mkdir -p $BDISKHOME &&
198 cat > $BDISKHOME/.bash_profile << "EOF"
200 export PATH=/usr/i386-linux-uclibc/bin/:$PATH:$HOME/bin
201 export CC=i386-uclibc-gcc
204 Of course, you may specify more cflags, like -march=i486. The above
205 setting of the $PATH variable assumes that the usual directories to
206 be contained in the path are already set in /etc/profile.
208 So the idea is that we will work as user bootdisk; however, there are
209 some tasks during the bootdisk creation which require a privileged user
210 -- namely, mounting ext2 files and raw-copying to a floppy.
212 We can do two things about this problem:
214 1) Ignore it, and execute these tasks as root.
216 2) Make a script named mkbootdisk for doing this tasks. This script must
217 be executable only by root (mode 744). With the help of the sudo utility
218 we let the bootdisk user to use this script as well. That is, we put it
219 to $BDISKHOME/bin and then type:
222 bootdisk ALL = NOPASSWD: $BDISKHOME/bin/mkbootdisk" >> /etc/sudoers
224 A realization of mkbootdisk can be found as an attachment of this hint
227 http://www.linuxfromscratch.org/hints/downloads/attachments/uclibc-bootfloppy/
231 http://www.math-inst.hu/~ekho/lowlife/mkbootdisk
233 or in the current directory if you read this hint as a file of the
234 lowlife tarball avaliable at
236 http://www.math-inst.hu/~ekho/lowlife
238 Typing "mkbootdisk -h" will print a brief information on usage.
240 We have the desired environment. We go on compiling the programs. Become
245 In the rest of the hint we will act as user bootdisk, with the following
248 * as uClibc will be installed systemwise, you should install it as root;
250 * if you don't use a mkbootdisk script, then the appropriate actions
251 are to be done as root;
253 * doing a chroot test of your filesystem for the floppy is possible only
256 This means that if you use a mkbootdisk script, then those steps of
257 creating the bootfloppy which shouldn't affect your development
258 platform, *can't* affect the development platform (provided your
259 mkbootdisk script doesn't do anything weird, which I think is
260 fulfilled by the one written by me).
262 Some of the commands below assume that the actual source archive is
263 decompressed in $HOME (which is the same as the prior $BDISKHOME).
264 Software installation instructions always start at the point when the
265 source tarball is already decompressed and you entered the source
266 directory (unless we explicitely claim to act differently).
268 Compiling the linux kernel
269 --------------------------
271 At the moment the latest stable release of the linux kernel belong to
272 the 2.4.* branch, but 2.6.0-test* releases are already out. This
273 situaton might change any time by the release of linux-2.6.0. The
274 following instructions regard to the 2.4.* releases; if you want to try
275 linux-2.6.*, not only the kernel compilation instructions but the whole
276 bootdisk creation procedure is to be revised (eg., you can't boot a
277 2.6.* kernel without a boot loader). After linux-2.6.0 will be out I
278 might consider to upgrade this hint to that version.
280 We will compile a network-aware kernel optimized to size. I don't give
281 a complete reference, I just highlight some crucial points.If you need
282 not network-awareness, you may omit TCP/IP netowrking and network
283 drivers; but even in this case it is strongly recommended to include
284 "Unix domain sockets".
286 In the kernel source tree type:
288 sed -e 's%-O2%-Os%g' -e '/^CFLAGS_KERNEL/s%\(^.*$\)%\1 -Os%' Makefile > \
290 mv Makefile.tmp Makefile
292 The above commands set optimization for size in the Makefile. Edit the
293 Makefile if you want further optimizations.
295 Now you should configure the kernel with "make menuconfig". Choose
296 carefully the value in the "Processor type and features ---> Processor
297 family" menupoint. When choosing options, it is advised to include only
298 those features you really need. Some important ones:
300 Networking options --->
301 <*> Unix domain sockets
302 [*] TCP/IP networking
304 In the "Network device support --->" menupoint choose those network
305 drivers you intend to use. If you want to use plip, choose it as a
306 module, and also set:
308 Parallel port support --->
309 <*> Parallel port support
310 <M> PC-style hardware
312 This is advised because of the following: as I experienced, if no
313 option is given, the kernel initializes the parallel port (PC-style)
314 IRQ-less! At boot time we won't have the possibility to pass options
315 to the kernel, as we won't use a boot loader or initrd. Thus we can
316 set the appropriate IRQ value only if we load the parallel port
317 driver as module. Also, to gain more control over the NIC drivers,
318 consider building them as modules.
320 In this hint we use the devfs facility, so choose
323 [*] /dev file system support
324 [*] Automatically mount at boot
326 (See a more detailed description in the devfs hint:
328 http://www.linuxfromscratch.org/hints/downloads/files/devfs+kernel_modules.txt
332 And don't forget to include support for the mouse type you will use with
333 the bootfloppy (if you will use any).
335 OK, one more remark. Here I don't digress on how to use initrd, but you may
336 have some reason for doing that. In this case with some kernels (eg., with
337 linux-2.4.22) you might encounter with booting problems, which can be cured
338 by the appropriate kernel patch. For info on initrd and the patch you can
339 consult the "Creating a Custom Boot Disk" chapter of the BLFS-book,
340 referenced in the Introduction.
342 Now compile the kernel with the
344 make dep && make bzImage && make modules
348 mkdir $HOME/rfloppy/lib/modules
350 and copy the NIC driver modules from the drivers/net directory to
351 $HOME/rfloppy/lib/modules, and also the other modules you built. Eg., if
352 you use plip, you will need the drivers/parport/parport_pc.o
355 Do not delete the kernel source.
357 If you have troubles with configuring the kernel properly, my .config file
358 might be of your help:
360 http://www.linuxfromscratch.org/hints/downloads/attachments/uclibc-bootfloppy/
361 http://www.math-inst.hu/~ekho/lowlife/linux-2.4.22/.config
363 Installing uClibc on the development platform
364 ---------------------------------------------
366 Usually we will optimize to size; in case of uClibc it's done
369 We install uClibc systemwise, thus the commands of this installation are
370 to be executed as root.
372 In the uClibc source tree type
376 uClibc now has a configuration interface similar to that of the linux
377 kernel. Apply the following settings:
379 Target Architecture Features and Options --->
380 ($BDISKHOME/<dir of your linux kernel for the floppy>)
381 Linux kernel header location
382 Library Installation Options --->
383 (/lib) Shared library loader path
385 This was enough for uClibc-0.9.19; in case of uClibc-0.9.21 we also need
388 General Library Settings --->
389 [ ] Support gprof profiling
390 String and Stdio Support --->
391 [*] Support sys_siglist[] (bsd-compat)
393 [Explanation: with profiling support set, uClibc wasn't willing to build
394 for me. The sys_siglist[] support will be needed by busybox which
395 encorporates some BSD code by having ash as its shell.]
397 (Other uClibc versions may have their own gotchas.)
399 Apart from this, the default configuration is quite suitable, probably
400 you need not change anything (especially you need not use full math
401 support). However, taking a look at the options never hurts; eg., you
402 may consider fine-tuning the target processor type. After you exit,
407 Further on we assume that you installed uClibc into
408 /usr/i386-linux-uclibc/ (the default installation location).
410 Creating the root filesystem
411 ----------------------------
413 We will put the files of the root filesysem of the floppy to a directory
414 named rfloppy. Firstly we create the directory and a basic tree of
415 subdirectories which vaguley resembles the FHS idea:
418 mkdir -p rfloppy/{dev,proc,etc/init.d,sbin,bin,lib,mnt,usr,var/log} &&
419 cat > rfloppy/etc/init.d/rcS << "EOF" &&
421 mount proc /proc -t proc
424 The etc/init.d/rcS file will be the startup script for the floppy. Put
425 there what you want to be done in the beginnig -- eg., syslogd, klogd,
426 loading modules, starting gpm, etc.
428 A very minimal etc directory is used in this setup. Enriching it (with
429 files like passwd, group, fstab, modules.conf, and so on) is up to you
430 -- this minimalist solution works anyway.
432 Installing uClibc for the bootdisk
433 ----------------------------------
435 We copy the necessary libraries of uClibc to the bootdisk.
437 cp -a /usr/i386-linux-uclibc/lib/{ld-uClibc*,libc.so.0,libuClibc-*} \
443 At the moment busybox has two branches: the development branch
444 (1.00-pre* releases) and the stable branch (0.60.* releases), but this
445 situation might change any time by busybox-1.00 being released. The
446 following instructions regard to the 0.60.* versions. The 1.00-pre*
447 versions differ greatly (encorporate much more utilities, eg.), so if
448 you go experimenting with them, these instructions probably need to be
449 changed. When the now-devel branch get stable (1.00 comes out), this
450 document will probably be upgraded to that version of busybox.
452 Before making it, adjust the Config.h file according to your needs. To
453 make busybox work with devfs, be sure that the
455 #define BB_FEATURE_DEVFS
457 line is uncommented (not prefixed with "//"); and it is advised to
458 enable standard Unix utilities, moreover if you want to use network with
459 the floppy, consider uncommenting:
464 #define BB_FEATURE_IFCONFIG_STATUS
468 make CROSS=i386-uclibc- &&
469 make PREFIX=$HOME/rfloppy install
471 If you have troubles with configuring busybox properly, my Config.h file
472 might be of your help:
474 http://www.linuxfromscratch.org/hints/downloads/attachments/uclibc-bootfloppy/
475 http://www.math-inst.hu/~ekho/lowlife/busybox-0.60.5/Config.h
480 Having mouse at the console is not necessary, but very comfortable for a
481 bootfloppy as well. If you want it, install gpm by running the following
485 LDFLAGS="-lm" make &&
487 mkdir -p $HOME/rfloppy/{usr/sbin,var/run} &&
488 cp src/gpm $HOME/rfloppy/usr/sbin &&
489 cp -a /usr/i386-linux-uclibc/lib/{libm-*,libm.so.0} ~/rfloppy/lib
491 [The /var/run directory is needed for gpm at runtime.]
496 Now if there is anything more you want to have on the floppy, compile it
497 and put it to the appropriate place under $HOME/rfloppy. A list of some
502 http://ftp.kernel.org/pub/linux/daemons/devfsd/
504 ) is not necessary for the bootfloppy, devfs work fine without it. So
505 install it only if you know what you are doing. However, it needs to be
506 hacked to get it compiled against uClibc. There is a patch for devfsd at:
508 http://www.linuxfromscratch.org/patches/downloads/devfsd/devfsd-1.3.25-uclibc.patch
512 http://www.math-inst.hu/~ekho/lowlife/patches/devfsd-1.3.25-uclibc.patch
514 (or in the patches directory if you read this hint as a file of the lowlife
515 tarball) and you can find some explanation on it at
517 http://www.math-inst.hu/~ekho/lowlife/
519 Note that devfsd depends on the libdl.so.0 library of uClibc (which is a
520 symlink to libdl-0.9.*.so). You have to put these to the /lib of your
523 * The svnc-thinclient hint tells you how to compile and install svgalib
524 and the svga vncviewer to the floppy, giving the bootfloppy the
525 capabilities of an X terminal.
527 The (functionality of the) following utilities are already encorporated
528 in the development versions of busybox.
530 * You can put tinylogin (
532 http://tinylogin.busybox.net/
534 ) to the floppy if you want a correct login system on it (with the
535 configuration described in this hint you just get a prompt after
538 * You can put utelnetd (
540 http://www.pengutronix.de/software/utelnetd_en.html
542 ) to the floppy if you want to access it remotely. However, don't forget
543 that communication is not encrypted under telnet!
545 * One more useful program is hdparm (
547 http://ftp.ibiblio.org/pub/Linux/system/hardware
549 ): if you boot with this floppy, the harddisk is probably not used, but
550 still is a source of noise by its spinning. You can stop it with
551 hdparm. (See its -y option.)
553 Creating the bootdisk
554 ---------------------
556 Before creating the floppy, you may wish to test the proposed filesystem
557 by chrooting to it; if so, execute as root:
559 chroot $BDISKHOME/rfloppy /bin/sh
561 Typing this you get the prompt of the busybox shell, and you should be
562 able to run those utilities which do not require much I/O (ls, cat,
563 echo,...). Proceed on again as the bootdisk user.
565 Put a floppy to the floppy drive (if you are not sure about its
566 integrity, you might want to run fdformat on it). If you use my
567 mkbootdisk script, check whether the device name of the floppy drive is
568 set correctly in the script (it is set to /dev/fd0 and no option can
569 change it, in order to prevent the bootdisk user in being able to muck
570 up the development platform), and whether the $MKE2FSAPP, $RDEVAPP
571 variables in the script store the correct path to the mke2fs, rdev
572 utilities in your system (they should if you follow standards). If
573 everything is fine, simply run
578 If you don't use the mkbootdisk script, become root, store the name of
579 your floppy device (typically /dev/fd0) in the variable $DISK. Now its
580 time to find out how big the root filesystem of the floppy should be,
581 and how much inodes should it have. Concerning the size, I think the
582 size of the stuff in the rfloppy directory + 150k is enough; concerning
583 the number of inodes, I think the number of files in rfloppy + 100 is
584 enough. But you should know. Store the chosen filesystem size in the
585 variable $SIZE (the number of kilobytes), and the chosen number of
586 inodes in the variable $INODES. Then type the following:
589 # We we create and compress the root filesystem of the floppy:
590 dd if=/dev/zero of=rootfs bs=1k count=$SIZE &&
591 yes | mke2fs -m 0 -N $INODES rootfs &&
593 mount rootfs -o loop loop &&
594 rmdir loop/lost+found &&
595 cp -a rfloppy/* loop &&
596 chown -R 0:0 loop/* &&
598 dd if=rootfs bs=1k | gzip -v9 > rootfs.gz
600 Now check whether rootfs.gz and your kernel image (probably
601 linux-2.4.*/arch/i386/boot/bzImage) fit on a floppy together (a floppy
602 is of 1440k usually but it can be formatted to bigger sizes as well). If
603 everything is fine, go on:
605 # We copy the kernel to the floppy:
606 let KERNELSIZE=`dd bs=1k of=$DISK < linux-2.4.*/arch/i386/boot/bzImage 2>&1 |
607 sed -n '1s%\([0-9][0-9]*\).*%\1%p'`+1 &&
608 # We perform some adjustments on the kernel copied to the floppy:
611 rdev -r $DISK `expr 16384 + $KERNELSIZE` &&
612 # Finally we copy the compressed filesystem to its appropriate place \
614 dd if=rootfs.gz of=$DISK bs=1k seek=$KERNELSIZE
616 [Explanation -- also for those who wonder how the mkbootdisk script
619 "yes | mke2fs -m 0 -N $INODES rootfs":
621 This pipe construct is a common trick for answering stupid questions
624 "# We copy the kernel to the floppy" :
626 In the command after this comment we not only copy the kernel to floppy,
627 but we also store the number of transferred kb's in the variable
630 "# We perform some adjustments on the kernel copied to the floppy" :
632 We won't have a bootloader to tell the kernel where to find its root
633 filesystem. The commands after this comment set some specified bits
634 in the kernel, thus hardwiring the location of the root filesystem to
635 it: firstly, we tell the kernel to seek for the filesystem in the
636 floppy, secondly, we tell the kernel that a ramdisk is to be made and
637 the filesystem is to be decompressed to it, thirdly, we tell the
638 kernel the location of the filesystem within the floppy. The number
639 16384 = 2^14 is used for shifting within the range of bits in the
640 kernel devoted for describing these data. For more information
641 consult with the Bootdisk HOWTO available at tldp.org.
643 "# Finally we copy [...]" :
645 In the dd command after this comment we use the seek option to copy the
646 compressed filesystem nicely after the kernel image.]
648 Now you have the floppy, boot & enjoy!
650 Bugs and weirdnesses, todo
651 --------------------------
653 This hint is co-developed with the svnc-thinclient hint in the framework
654 of the lowlife project. These informations can be found in the svnc-thinclient
659 This hint is co-developed with the svnc-thinclient hint in the framework
660 of the lowlife project. These informations can be found in the svnc-thinclient
665 This hint is co-developed with the svnc-thinclient hint in the framework
666 of the lowlife project. These informations can be found in the svnc-thinclient