Last active
April 21, 2023 03:52
-
-
Save CMCDragonkai/97c800ba2dad704ef989 to your computer and use it in GitHub Desktop.
CLI: Creating Sparse Files (Can be used for virtual loopback block devices)
This file contains 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
#!/usr/bin/env bash | |
# seems to work on any filesystem | |
# final size is (bs * seek) in bytes | |
# this creates a 4MB sparse file | |
dd if=/dev/zero of=/tmp/file bs=1 count=0 seek=4194304 | |
# or | |
dd if=/dev/zero of=/tmp/file bs=1 count=0 seek=4M | |
# linux specific | |
# this doesn't work on some filesystems like FAT32 and ZFS, but easier to remember | |
# its unique feature is that it does actually reserve the space | |
# preventing the space from being used by other things | |
fallocate -l 4M /tmp/file | |
# so you could create a sparse file larger than the amount of space you really have | |
# seems equivalent to the dd command, doesn't actually reserve the space | |
truncate -s 4M /tmp/file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment