#!/bin/sh

# put here the root device you want to mount at boot time
# e.g /dev/hda1 will mount by default as root fs the first partition 
# on first IDE harddisk
ROOT_DEVICE=/dev/fd0H1722

# RAMDISK size, your floppy capacity or 0
RAM_DISK_SIZE=1722

# put here the kernel you want on boot disk
KERNEL=/vmlinuz

# "read-only" for ext2 fs to allow checking
MOUNT="read-only"

# put here the device from witch you want to boot
# e.g to boot from first HD floppy put /dev/fd0H1440
BOOT_DEVICE=/dev/fd0H1440

echo "WARNING THE FLOPPY WILL BE ERASED"
echo "PRESS ENTER TO CONTINUE, ^c (CONTROL C) TO ABORT"

# low level format, checking for badblocks
fdformat $BOOT_DEVICE
# make filesystem
mke2fs -v -i 1024 -m 0 $BOOT_DEVICE

# mounting directory
if [ ! -d /tmp/lilo ]; then
  mkdir /tmp/lilo
fi

mount -t ext2 $BOOT_DEVICE /tmp/lilo
cp $KERNEL /tmp/lilo/vmlinuz
cp -a /dev /tmp/lilo
mkdir /tmp/lilo/etc

# create lilo.conf
cat << EOF > /tmp/lilo/etc/lilo.conf
boot = $BOOT_DEVICE
message = /etc/lilo.msg
prompt
image = /vmlinuz
        label = emergency
        ramdisk = $RAM_DISK_SIZE
        root = $ROOT_DEVICE
        #
        # append here your parameters or comment the line:
        #
        append = "hdc=cdrom hdd=noprobe ether=5,0x300,eth0"
        vga = normal
        $MOUNT
EOF

# copy boot files and modules /boot/modules
cp -a /boot /tmp/lilo

# create lilo.msg
cat << EOF > /tmp/lilo/etc/lilo.msg

DO NOT SWITCH DISKS YET

Emergency Boot Disk  
===================

Hit ENTER to mount as root dir $ROOT_DEVICE .
To  mount other partition as root dir enter a command similar to this on the 
LILO boot prompt below:

    mount root=/dev/hda1 ro

where "/dev/hda1" is the partition to mount as root dir, "ro" specifies that
the partition should be mounted as read-only and "rw" to mount the partition 
read-write.  You  may  also  add  any other kernel parameters you might need 
depending on your hardware, and which drivers are included in your kernel.

EOF

lilo -r /tmp/lilo
umount /tmp/lilo
rm -rf /tmp/lilo
