Creating a loopback filesystem

2014/02/11

Tags: linux mount loopback lfs

Create a sparse file for the fs using fallocate. As per the man page:

“fallocate is used to preallocate blocks to a file. For filesystems which support the fallocate system call, this is done quickly by allocating blocks and marking them as uninitialized, requiring no IO to the data blocks. This is much faster than creating a file by filling it with zeros.”

[ed@orinoco lfs]$ fallocate -l 20G root.image

Create the filesystem:

[ed@orinoco lfs]$ mkfs.ext4 -F root.image

Mount the file via loop

[ed@orinoco lfs]$ sudo mount root.image ./work/root -o loop