0

I just expanded my 1G "homefile" which is mounted to /home/user by another GB using truncate -s +1G homefile, and while it changed the size of homefile shown with df to 2GB, when mounted it is still only 1GB. Am I missing something? I dont have to use mkfs.etx4 again do I?.. as that would wipe the data and defeat the purpose of me using truncate over fallocate, with which I have to use resize2fs after expanding, but doesnt change the data. I tried using resize2fs after truncate, but it had an error on the filesystem type (I'll have to reboot my VM if that is pertinent).

If there is no way for me to expand with truncate, is there another way to mount a dynamically expanding file? I know qcow2 can do that, but it seems a little heavy handed for this. I'm aware of squashfs in things like PuppyOS and PorteuOS, but it had more steps involved to set up when I looked. I like the simplicity of truncate if it will work.

alchemy
  • 537
  • 5
  • 16

1 Answers1

2

You just resized the underlying storage, not the file system. So, this is perfectly expected!

resize2fs is the tool you need; resize2fs homefile does not yet work (DON'T DO IT YET), because you first will have to tell the loop device through which its mounted that the underlying storage has changed.

So, the whole process is this:

  1. Increase image size (truncate/fallocate...)
  2. Tell the loopdev that its size changed: losetup -c $(losetup -j homefile)
  3. Resize the filesystem: resize2fs $(losetup -j homefile)
alchemy
  • 537
  • 5
  • 16
Marcus Müller
  • 21,602
  • 2
  • 39
  • 54
  • Thanks Marcus! So, I used resize2fs on the /dev/loop0 when it was mounted. I thought that was the same as using losetup. – alchemy Apr 10 '22 at 19:05
  • Thanks again! This worked. It makes contributing that much more rewarding when I get solutions to things Im stumped on. ..command #2 didnt work right away I think because `losetup -j homefile` had 3 column output for me, but I just used the /dev/loop# output. So happy I can open both browsers now, thanks! – alchemy Apr 10 '22 at 22:47
  • oneliner using df instead of `losetup -j` which needs to be cut/trimmed. `umount /home/user && truncate -s +1G /home/homefile && mount /home/homefile /home/user && dev=$(df --output=source /home/user | grep -v Filesystem) && losetup -c $dev && resize2fs $dev`. so basically when using truncate expand instead of fallocate `losetup -c` need to "-c, --set-capacity resize the device" – alchemy Apr 13 '22 at 17:51