#!/bin/sh # Creates a bootable (LILO) floppy for embedded Linux usage. # This script has to be run as root, and has therefore been # kept short and legible, so security conscious people can # read it and confirm that it only does what it should. # Larry Doolittle September 2000 # What you need before running this script (as root): # KERNEL pointed to actual kernel # IMAGE pointed to actual compressed filesystem image # both of these will be installed on the floppy. # See make_image for help on the latter. I trust you know # how to make a kernel, otherwise see /usr/src/linux/README. # If you want to run this process without a real floppy # in hand (and dd the result to a floppy later), set # DEV=/dev/loop0, where /dev/loop0 has been losetup to # a regular 1.44 Meg file. See "man losetup". DEV=/dev/fd0 # target device FSYS=/mnt/floppy # device is mounted here during installation KERNEL=./bzImage # suggest bz2 compression IMAGE=./image.gz # Compressed ramdisk image MESSAGE=./message # Displayed at boot time BOOTBLK=/boot/boot.b # LILO bootblock stolen from your running system PATH=/sbin:${PATH} test -r $KERNEL || exit test -r $IMAGE || exit test -r $BOOTBLK || exit echo; echo "Setting up bootable filesystem on $DEV" mke2fs -m 0 $DEV || exit mount $DEV $FSYS || exit echo; echo "Blank filesystem now mounted on $FSYS" umask 022 # otherwise LILO complains that /etc/lilo.conf should be writable only for root mkdir $FSYS/{etc,boot,dev} cat <$FSYS/etc/lilo.conf boot=/dev/fd0 map=/boot/map install=/boot/boot.b message=/boot/message compact # linear prompt timeout=5 image=/boot/vmlinuz label=linux root=/dev/ram0 initrd=/boot/ramdisk_image.gz read-only EOF # Note the consistency of the following literal target filenames # with the above literal lilo.conf. cp $KERNEL $FSYS/boot/vmlinuz cp $IMAGE $FSYS/boot/ramdisk_image.gz cp $BOOTBLK $FSYS/boot/boot.b if [ -r $MESSAGE ]; then cp $MESSAGE $FSYS/boot/message else cat < $FSYS/boot/message Single floppy boot setup courtesy Larry Doolittle EOF fi # Have to set up enough devices on the floppy that # the chroot'ed LILO knows what it's doing. ( cd $FSYS/dev mknod -m 660 fd0 b 2 0; chown root:floppy fd0 mknod -m 660 hda b 3 0; chown root:disk hda mknod -m 660 hdb b 3 64; chown root:disk hda for part in 1 2 3 4 5 6 7 8; do mknod -m 660 hda$part b 3 $part; chown root:disk hda$part mknod -m 660 hdb$part b 3 $((64+$part)); chown root:disk hdb$part done for ix in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do mknod -m 660 ram$ix b 1 $ix; chown root:disk ram$ix done ) # ... and the rubber meets the road. echo "Everything (virtually) done except LILO" lilo -v -r $FSYS echo "Unmounting $FSYS" umount $FSYS echo "Done! $DEV should now be bootable."