#!/bin/sh # Create a compressed ramdisk file, based on the directory $REF. # If $1 (first argument) is "debug", the final filesystem will # be left in place at $MNT. # 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. # It calls make_minimal_dev, you should look at that too. # The filesystem handling half of this script is almost # straight out of the losetup man page. # Larry Doolittle September 2000 # configuration: REF=root RDSIZE=2400 # RAM disk size in units of kBytes FILE=image # final output is $FILE.gz LOOP=/dev/loop1 # kernel must support loopback MNT=/mnt/junk # mount point for loopback device # No more configuration should be needed below. # Proofread at will. HERE=$PWD PATH=/sbin:/usr/sbin:${PATH} if [ ! -d $REF ]; then echo "$REF is not a directory; check $0 configuration" exit 1 fi if [ ! -d $MNT ]; then echo "$MNT is not a directory; check $0 configuration" exit 1 fi dd if=/dev/zero of=$FILE bs=1k count=$RDSIZE || exit losetup $LOOP $FILE || exit # Small filesystems tend not to have enough nodes for a # "standard" /dev. See make_minimal_dev invocation below. mke2fs -m 0 -i 2048 $LOOP || exit mount $LOOP $MNT || exit # Copy and take ownership of all files that an unprivileged # (development) user can create. See make_root. cp -a $REF/* $MNT chown -R root:root $MNT chown -R 100:100 $MNT/home/mortal chmod -R g-w $MNT/home/mortal # Create the device files (cd $MNT/dev || exit; sh $HERE/make_minimal_dev) || \ echo "Warning: Can't make devices in $MNT/dev" # Use ldconfig to set up $MNT/etc/ld.so.cache cp -a /sbin/ldconfig $MNT/sbin (echo /lib; echo /usr/lib) >$MNT/etc/ld.so.conf chroot $MNT ldconfig # You could rm $MNT/sbin/ldconfig if you were desperate for space, # and were sure you'd never want to add libraries at runtime. # Doing that properly would require zeroing the file contents first. test "$1" != "debug" && echo "Unmounting and gzipping $FILE" && \ umount $MNT && losetup -d $LOOP && gzip -f -9 $FILE && \ echo "Compressed filesystem $FILE.gz complete, ready for make_floppy"