#!/bin/bash #Copyright 2002 William Stearns #Based on work by Jeff Dike #GPL'd. VERSION='0.1' usage () { echo mkemptyfs $VERSION echo Creates an empty filesystem in a file. echo echo Usage: echo -e '\tmkemptyfs [fstype] [size]' echo echo Where fstype is ext2, ext3, or reiser, and size is in megabytes. echo You do not need that amount of space in the current directory - echo a sparse file will be created. echo Default is an 1024M ext2 filesystem. echo Reiser isn\'t working at the moment, working on it. } while [ -n "$1" ]; do case "$1" in [Ee][Xx][Tt]2) FSTYPE='ext2' ;; [Ee][Xx][Tt]3) FSTYPE='ext3' ;; [Rr][EeIi][IiEe][Ss][Ee][Rr]) FSTYPE='reiser' ;; -[Hh]|--[Hh][Ee][Ll][Pp]) usage exit 1 ;; #Up to 10TB [0-9]|[0-9][0-9]|[0-9][0-9][0-9]|[0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9][0-9][0-9]) EMPTYMEGS="$1" ;; *) echo Unrecognized command line parameter "$1", exiting usage exit 1 ;; esac shift done #Defaults EMPTYMEGS=${EMPTYMEGS:-1024} FSTYPE=${FSTYPE:-ext2} EMPTYFILE="emptyfs.$FSTYPE.$EMPTYMEGS" if [ -f "$EMPTYFILE" ] || [ -f "$EMPTYFILE.old" ]; then echo Moving old empty filesystem out of the way... if [ -f "$EMPTYFILE.old" ]; then rm -f "$EMPTYFILE.old" ; fi if [ -f "$EMPTYFILE" ]; then mv -f "$EMPTYFILE" "$EMPTYFILE.old" ; fi fi echo Creating a "$EMPTYMEGS" megabyte empty "$FSTYPE" filesystem... #Make a completely sparse file to start with dd if=/dev/zero of="$EMPTYFILE" bs=$((1024 * 1024)) count=0 seek=$EMPTYMEGS || exit 1 #Fully filled file, no sparse usage. #dd if=/dev/zero of="$EMPTYFILE" bs=$((1024 * 1024)) count=$EMPTYMEGS || exit 1 echo Making empty filesystem in it... # $SUDO not necessary, it appears. case $FSTYPE in ext2) mke2fs -m 2 -F "$EMPTYFILE" || exit 1 ;; ext3) mke2fs -j -m 2 -F "$EMPTYFILE" || exit 1 ;; reiser) echo 'y' | mkreiserfs -f "$EMPTYFILE" #mkreiserfs appears to return non-zero (1) for a file. Hmmm. echo $? ;; esac rm -f "$EMPTYFILE.bz2" echo Compressing filesystem... bzip2 -k -9 "$EMPTYFILE" echo 'Done!'