I have btrfs image file set as backend for LXD (2.18) but I would like to shrink it's size. What I did:

  • mounted image to loop device losetup /dev/loop1 /home/btrfs.img
  • mounted device to /mnt dir mount /dev/loop1 /mnt/brtfs
  • resized btrfs partition with btrfs filesystem resize -100G /mnt/btrfs

And after that df correctly shows partition size of /mnt/btrfs:

root@host:/mnt/btrfs# df -k .
Filesystem      1K-blocks       Used Available Use% Mounted on
/dev/loop1     1614807040 1563273068  48426164  97% /mnt/btrfs

but file is still with the same size

root@host:/home# ls -al
total 1848321632
drwx------ 2 root root          4096 Nov 11 10:19 .
drwxr-xr-x 4 root root          4096 Nov 11 10:19 ..
-rw------- 1 root root 1932735283200 Nov 11 06:29 btrfs.img

Later I've tried btrfs filesystem resize -100GB /home/btrfs.img and it didn't work according to documentation:

Warning: If path is a file containing a BTRFS image then resize does not work as expected and does not resize the image. This would resize the underlying filesystem instead.

My question is: how can I shrink whole file without loosing data?


truncate -s100G /home/btrfs.img

  • And if I run across a file where the embedded btrfs filesystem isn't occupying all the file space, how do I "shrink-wrap" the file to match the filesystem? I.e., where do I find the exact parameter to use with truncate? – rickhg12hs Aug 28 '18 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.