nav
Yahoo! Movies Exclusive
nav
Today at Yahoo! Movies

exclusive film clips
[Close]
nav
Today at Yahoo! Movies

exclusive film clips
[Close]
Compacting Linux in A Floppy
HomeEssays
.

Compacting Linux in A Floppy

This document desribes the require steps to create your own Linux mini-distribution that fit to a floppy disk. I assume that you have a Linux system running (based on kernel 2.2.x), understand the basics of Linux and have an experience of compiling the kernel.

To create a mini-distribution, you must have:

The last file is in this document.

Login first as root.

Make sure you have your Linux kernel source. You can verify this by the following command:

# ls /usr/src/linux

If this directory doesn't exist, you must install kernel source first. Please refer to the KERNEL-HOWTO

Ensure that your kernel has support for ramdisk. Otherwise, configure the kernel and recompiler it. (Refer to the Kernel-HOWTO).

Install the loopback device as necessary. You might have already this, check for losetup.

You must create a custom kernel which is basically a stripped-down version of Linux. To do this, copy the example .config file to your /usr/src/linux, and then:

# cd /usr/src/linux
# make menuconfig

Customize your kernel as necessary. Only checkmark ('Y') the required options as you have to pack the kernel as small as possible. After finishing this process, you can build the kernel by the following commands:

# make deps
# make zImage

If an error occurs because the image file is too large, do this:

# make bzImage

NOTE: If the same error still happens, it means that your kernel is too large. You must do make menuconfig again and disable support for many unnessary things.

If you add support for loadable module for the kernel, you must also perform this:

# make modules

Now, switch to your home directory and create a sub-directory named 'flop' (this is only an example, use whatever name you like):

# cd ~
# mkdir flop

Copy the newly created kernel to this directory:

# cp /usr/src/linux/arch/i386/boot/zImage .

NOTE: If you did make bzImage, copy the /usr/src/linux/arch/i386/zImage file then.

Copy install script file to your home directory.

Create a sub-directory named 'tree'.

# mkdir tree

Under this directory, create another directory tree which resembles a normal Linux partition. Therefore you need at least the following directories:

/bin
/dev
/etc
/etc/rc.d
/lib
/lib/modules
/mnt
/proc
/sbin
/tmp
/usr
/usr/bin
/var

Now we need some libraries, mostly glibc2. To do this, copy the following libraries for your main Linux system to ~/flop/tree/lib :

ld-2.1.2.so
ld-linux.so.1.9.9 
libtermcap.so.2.0.8

(The names may vary depend on your kernel version).

Since those files are too large to fit on a floppy (even in a compressed), you must strip debugging information from the file when copying those libraries. To do this, using the following command

# objcopy --strip-debug from target

Subsitute from and target to the above libraries (e.g: /lib/ld-2.1.2.so and ~/flop/tree/lib/ld-2.1.2.so).

If you add support for modules for your kernel, also copy the modules to  ~/flop/tree/lib/modules.

Under ~/flop/tree/lib, make sure you have the following symbolic links:

ld-linux.so -> ld-linux.so.1
ld-linux.so.1 -> ld-linux.so.1.9.9
ld-linux.so.2 -> ld-2.1.2.so
libc.so.6 -> libc-2.1.2.so
libtermcap.so.2 -> libtermcap.so.2.0.8

You also need standard devices (node) in your ~/flop/tree/dev. The easiest way to do this is to copy those devices from your main Linux system and then strip down any unnecessary ones.

If later you want to mount a floppy drive or hard disks, create the mount point in ~/flop/tree/mnt. Again, the simple way is to copy from your system.

Directory ~/flop/tree/etc requires some file. Copy the following files from your system and then customize them as necessary:

fstab
host.conf
inittab
profile
rc.d
services
group
hosts
issue
passwd
protocols
securetty
termcap

Create ~/flop/tree/etc/rc.d/rc.reboot as follow:

PATH=/sbin:/bin:/usr/bin:/usr/sbin
[ "${BASH+bash}" = bash ] && enable kill
halt -w
echo "Turning off swap and accounting"
swapoff -a
echo "Unmounting file systems"
umount -a
mount -n -o remount,ro /
echo -n "Rebooting..."
/sbin/reboot -d -f -i

Also, create ~/flop/tree/etc/rc.d/rc.sysinit as follow:

mount -a
echo "flop" > /proc/sys/kernel/hostname
/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0
/sbin/route add 127.0.0.1 lo

Then come the hardest (and yet funniest) part. Copy the necessary applications to   ~/flop/tree/bin and  ~/flop/tree/sbin. Please copy the most important things only (cause space is limited!). The following files are starting-point for you:

for ~/flop/tree/bin:

bash
cp
dmesg
mkdir
mv
rmdir
touch
cat
date
echo
ls
mount
rm
sleep

and for ~/flop/tree/sbin:

halt
ifconfig
insmod
reboot
route

You don't need login or mingetty because there won't be any login prompt :)

NOTE: Surely you need insmod if you add module support for the kernel.

Create a symbolic link ~/flop/tree/sbin/init to point to /bin/bash. The kernel expects to find this file, so if you don't have one, system will be halted.

Installation to the floppy is performed using install-flop script (provided in the next section). The script assumes you want to create the floppy in /dev/fd0 .If this is not what you want, modify the script as necessary.

NOTE: Even though you can do it manually, I find the script is very handy.

Your Linux in a floppy is ready !

install-flop

This is the installation script. Create the file using your own favorite editor, save it, and don't forget to make it executable.

#!/bin/sh
#
# FLOP 0.3.0 installation script
# a modification of MakeImage and Write Disk
# (C) 2000 Ariya Hidayat 
#
# MakeImage 1.1 (C) 1999 FBW from Cosmic Chaos 
# Original by Erich Boehm
#
# WriteDisk 1.1 (C) 1999 FBW from Cosmic Chaos
# Original by Erich Boehm
#

# define here the size of the ramdisk
# note: 100k of the rd should be left unused, so that you can use
# vi and other prgs which need space in /tmp

RD_SIZE=2600

# define here the nescessary directories

CCHOME=.
RD_KERNEL=$CCHOME/zImage
RD_SCRIPTS=$CCHOME/scripts/*
RD_SOURCE=$CCHOME/tree/*
RD_IMAGE=$CCHOME/Image.gz

MNTDIR=/mnt/loop # where should the temporary fs be mounted ?
LOOPDEV=/dev/loop0 # loop device which should be used
TMPFILE=/tmp/loop_tmp # tmpfile which should be used with losetup
FLOPPYDEV=/dev/fd0 # floppy device to use

mkdir $MNTDIR 2>/dev/null

echo "creating ramdiskimage, please wait ..."

# make a file of $RD_SIZE and use loop device on it

dd if=/dev/zero of=$TMPFILE bs=1k count=$RD_SIZE > /dev/null
if ! `losetup $LOOPDEV $TMPFILE`; then
echo "losetup did NOT run correctly."
echo "Please make sure that you are root and that the losetup binary is in the path."
echo "Also make sure that you have the loop device compiled in the kernel or the modul
e loaded."
exit 0
fi

# make ext2 fs on loopdev and mount it
mke2fs -m 0 $LOOPDEV 2> /dev/null >/dev/null
mount $LOOPDEV $MNTDIR -t ext2

# copy ramdisk contents to loopdev
cp -a $RD_SOURCE $MNTDIR
# copy runtime scripts for DLX to /usr/bin/scripts
cp -a $RD_SCRIPTS $MNTDIR/usr/bin

# umount & undo loop 
umount $MNTDIR
rmdir $MNTDIR 2>/dev/null
losetup -d $LOOPDEV

# create gziped rd image
dd if=$TMPFILE | gzip -9 > $RD_IMAGE
rm -f $TMPFILE

# wait until everthing is written
sync

# use this to trick the script to create an image file
# and not write it to a floppy. The result is usable with RAWRITE.
#FLOPPYDEV=flop.img

# here we make some calculations
KERNELSIZE=`ls -s $RD_KERNEL | cut -f2 '-d '`
IMAGESIZE=`ls -s $RD_IMAGE | cut -f2 '-d '`
BOOTSTART=$[$KERNELSIZE + 1]

# if you want the kernel to ask for the boot dev
# add 32768 to the RAMDISKFLAG
RD_FLAG=$[$BOOTSTART + 16384]

echo "writing to floppy disk ..."
echo "kernelsize: $KERNELSIZE"
echo "bootstart : $BOOTSTART"
echo "`du -c $RD_KERNEL $RD_IMAGE |grep total`, the total should not exeed 1445"
echo

# write kernel
rdev $RD_KERNEL $FLOPPYDEV # set boot device
rdev -r $RD_KERNEL $RD_FLAG # set start of ramdisk
rdev -R $RD_KERNEL 0 # default VGA !
dd bs=1k if=$RD_KERNEL of=$FLOPPYDEV

# write image
dd if=$RD_IMAGE of=$FLOPPYDEV bs=1k seek=$BOOTSTART

echo " done !"

Resources

Please take a look at Bootdisk-HOWTO. This is very useful. You can find it in /usr/doc/HOWTO/Bootdisk-HOWTO within your Linux system.

Check also Kernel-HOWTO. This is necessary it you want to peek at the kernel.

Some pointers to website which might be useful: