Created
August 17, 2016 00:26
-
-
Save u8sand/feaec7ca0c99c5d39431744653a8f78e to your computer and use it in GitHub Desktop.
Create a big raw file that can be treated as a disk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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