bootdisk.txt
[email protected]:
linux bootdisk
hello i wanna tel you how to make a one disk linux bootdisk
info herein is stolen and refreshed from /usr/src/ramdisk.txt
and marten den braber @ twister.cx
and bootdisk-howto (which helped quite not)
i will put together a bootdisk with kernel redhat 6.2, all
network drivers, and svncviewer to turn every 486 with 4 mb ram
into a X-terminal (a vnc terminal, that is)
the information in this document is incorrect and incomplete.
if you use it, blame yourself, not me.
you must be root for this to run. as root, you can break a lot.
get a second computer going, and work on that if you feel unsafe.
and: feel unsafe!
intro
a bootdisk must contain a kernel and some files to work with, say
a shell.
the files are smashed together in a ramdisk. a ramdisk is a piece of
ram, behaving like a disk - think /dev/ram instead of /dev/hda1
at boot time, the kernel will load and ungzip itself, then look for
a ramdisk (if you rdev it accordingly), then load a compressed
filesystem, gunzip it, mount it on /, and try to start
/sbin/init
/bin/init
/ (something i forgot)
/bin/sh
preparing the root
the root must contain the files
/dev/ram
/dev/mem
/dev/kmem
/dev/console
/dev/tty
/dev/tty1
/bin
/bin/ash.static
ln -s ash.static sh
/lib/
/proc/
/mnt/
/tmp/
/var/
=======================snip=======================
#!/bin/sh
# in case i forgot
umount /mnt
# first, we create a ramdisk in ram
# zero it out so it compresses well
# lets start with 2 MByte
dd if=/dev/zero of=/dev/ram bs=1k count=2000
# make a filesystem
mke2fs /dev/ram count=2000
# mount that filesystem
mount /dev/ram /mnt
# populate that filesystem ###########################
cd /mnt
mkdir bin
mkdir dev
mkdir etc
mkdir home
mkdir lib
mkdir mount
mkdir proc
mkdir root
mkdir sbin
mkdir tmp
mkdir usr
mkdir var
# cp dpR see man cp
cp -dpR /dev/fd0 /mnt/dev
cp -dpR /dev/mem /mnt/dev
cp -dpR /dev/kmem /mnt/dev
cp -dpR /dev/console /mnt/dev
cp -dpR /dev/tty /mnt/dev
cp -dpR /dev/tty1 /mnt/dev
# either copy your libs, or use a statically linked shell
# find out which libs are necessary on PROG by
# ldd PROG
cp -dpR /bin/ash.static /mnt/bin
cd /mnt/bin
ln -s ash.static sh
# end of # populate that filesystem ###########################
# leave the ramdisk alone
cd /
umount /mnt
# cp the ramdisk into a ramdisk image, and pipe it through gzip
dd if=/dev/ram bs=1k | gzip -v9 > /tmp/myinitrd.gz
# now we have a zipped rootdisk image in myinitrd.gz.
# dd the zipped kernel to the floppy. $SIZE is the amount of blocks
# this is magic: the kernel is dd'ed to the first SIZE blocks of the
# floppy. dd says how much block that were - we grep and cut that
# and destill the size. see man dd, man cut, man grep.
# if you dunnow which kernel to use, use /boot/vmlinuz the smaller file
SIZE=``dd if=/usr/src/linux/arch/i386/boot/zImage \
of=/dev/fd0 bs=1k 2>&1 | grep out | cut -f 1 -d" "
# tell the kernel that the rootdisk is from fd0
# now tell the kernel (which is /dev/fd0) that its boot device is
# in fact /dev/fd0
echo rootdisk = fd0
/sbin/rdev /dev/fd0 /dev/fd0
# tell the kernel that it can be mounted read/write (it's a ramdisk ;-)
# so it can#t be broken - see man rdev
echo mount read/write
/sbin/rdev -R /dev/fd0 0
# tell the kernel where the ramdisk is
echo ramdisk starts at block $[ $SIZE ]
# lets say the kernel owns 400 kB (just an example). so we must
# a) write the ramdisk to 401 (or higher, to waste space)
# b) tell the kernel that its gziped ramdisk starts at 401
# c) tell the kernel not to prompt for a second diskette
# d) tell the kernel to load a ramdisk
# b) to d) is done in one swoop in the following line
/sbin/rdev -r /dev/fd0 $[ 16384 + $SIZE ]
# copy rootdisk to floppy
# see a)
echo copy rootdisk to floppy
dd if=/tmp/myinitrd.gz of=/dev/fd0 bs=1k seek=$[ $SIZE ]
sync
echo Done!
echo Now go to another computer and try to boot it from this diskette
echo After a while it should prompt you with a flashing_cursor
rm -f /tmp/myinitrd.gz