#!/bin/sh # makerd --- creates an initrd ramdisk file from an existing directory tree. # Copyright © 2001 Jamie Zawinski # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that # the above copyright notice appear in all copies and that both that # copyright notice and this permission notice appear in supporting # documentation. No representations are made about the suitability of this # software for any purpose. It is provided "as is" without express or # implied warranty. # # Created by jwz, 23-Dec-2000 verbose= dir= target= # Increase this if you get "No space left on device" errors. IMAGESIZE=700 make_ramdisk() { IMAGE=$target.tmp dd if=/dev/zero of=$IMAGE bs=1k count=$IMAGESIZE 2> /dev/null for devnum in 0 1 2 3 4 5 6 7 8; do if losetup /dev/loop$devnum $IMAGE 2>/dev/null ; then break; fi done if [ "$devnum" = "8" ]; then rm -rf $IMAGE echo "All of your loopback devices are in use!" >&2 exit 1 fi LODEV=/dev/loop$devnum if [ -n "$verbose" ]; then echo "Using loopback device $LODEV" fi echo y | mke2fs $LODEV $IMAGESIZE >/dev/null 2>/dev/null MNTPOINT=$target.mnt rm -rf $MNTPOINT mkdir $MNTPOINT mount -t ext2 $LODEV $MNTPOINT || { echo "Can't get a loopback device" exit 1 } rmdir $MNTPOINT/lost+found cpio_v="" if [ -n "$verbose" ]; then echo "Copying $dir..." dash_v="-v" fi cwd=`pwd` ( cd $dir; find . -depth -print | cpio $dash_v --quiet -pdm $cwd/$MNTPOINT ) \ 2>&1 | sed "s@$cwd/$MNTPOINT/\./@/@g" | sed 's@^@ @' umount $MNTPOINT losetup -d $LODEV ( gzip $dash_v -9 < $IMAGE > $target ) 2>&1 | sed 's@^@Compression:@' rmdir $MNTPOINT rm -rf $IMAGE if [ -n "$verbose" ]; then echo "Wrote $target:" ls -ldGF $target fi } usage() { echo "usage: `basename $0` [-v] input-directory output-ramdisk-file" exit 1 } main() { while [ $# -gt 0 ]; do case $1 in -v) verbose=1 ;; *) if [ -z "$dir" ]; then dir=$1 elif [ -z "$target" ]; then target=$1 else usage fi ;; esac shift done if [ -z "$dir" -o -z "$target" ]; then usage fi make_ramdisk } main "$@" exit 0