How do I resize a Linux filesystem data .bin file?
We will try to make your two MB root.bin
file to a 12 MB to demonstrate the steps.
Create a copy of your file (just in case for backup purpose):
cp root.bin 12mb.bin
Run this command to add 10M to the file size:
dd if=/dev/zero of=12mb.bin bs=1MiB count=10 conv=notrunc oflag=append
Now 12mb.bin is not 2M any more, actually its size is 12M.
Run:
e2fsck -f 12mb.bin
to check the filesystem on the file, then run:
resize2fs 12mb.bin
Done. mount it somewhere:
sudo mount 12mb.bin /mnt
check the size:
df -h --output=size /mnt/
Size
12M
And the existence of files:
ls /mnt
We can also use losetup
to act with the file like a block device:
sudo losetup -f 12mb.bin
then:
sudo losetup -l | grep -i "12mb.bin" | awk '{print $1}'
/dev/loop0
and we can resize /dev/loop0
.