Skip to content

Instantly share code, notes, and snippets.

@u8sand
Created August 17, 2016 00:26
Show Gist options
  • Save u8sand/feaec7ca0c99c5d39431744653a8f78e to your computer and use it in GitHub Desktop.
Save u8sand/feaec7ca0c99c5d39431744653a8f78e to your computer and use it in GitHub Desktop.
Create a big raw file that can be treated as a disk
fs=ext4
function create {
fallocate -L $1 "$fs"
mount
dev=$(cat "$fs.lock")
mkfs -t ext4 $dev
fsck -t ext4 $dev
umount
}
function grow {
dd if=/dev/zero of="$fs" iflag=count_bytes oflag=append conv=notrunc bs=4K count=$1
e2fsck -f "$fs"
resize2fs "$fs"
e2fsck -f "$fs"
}
function mount {
if [ ! -f "$fs.lock" ]; then
sudo losetup -f --show "$fs" > "$fs.lock";
else
echo "Already mounted or $fs.lock exists.";
fi
}
function umount {
if [ -f "$fs.lock" ]; then
sudo losetup -d $(cat "$fs.lock");
sudo rm "$fs.lock";
else
echo "$fs doesn't seem to be mounted.";
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment