an example for ram file system

#!/bin/sh
#this script can only be executed by root, check it first

id=`id -u`
if [ $id -ne 0 ]; then
        echo "You must be root to run this script."
        exit 1
else
        build_dir=$1
        initrd_gz=$2
fi

initrd=initrd_build
initrd_mnt=initrd_build_mnt

umount $initrd_mnt >& /dev/null
rm -rf $initrd $initrd_mnt

dd if=/dev/zero of=$initrd bs=1048576 count=256 || exit $?
/sbin/mkfs.ext3 -F -m 0 $initrd || exit $?
mkdir -p $initrd_mnt || exit $?
mount -o loop $initrd $initrd_mnt || exit $?
chown -R root.root $build_dir
#chown will clear setuid bit of sudo, restore it.
chmod u+s $build_dir/usr/bin/sudo
cp -a $build_dir/* $initrd_mnt || exit $?
umount $initrd_mnt
`gzip -c1 $initrd > $initrd_gz` || exit $?

#
#cleanup
#
rm -rf $initrd $initrd_mnt

你可能感兴趣的:(an example for ram file system)