Mount the file system locally then, find out what is the minimum size it can safely be shrunk to like this:
sudo btrfs inspect-internal min-dev-size /mnt/point/
Check the file system for any errors:
sudo btrfs check /mnt/point
!! Warning, if used incorrectly, this could delete your data !!
Create a loop device for the image file
sudo losetup --show --find --partscan disk.img
Mostly likely the device will be available at
/dev/loop0
and the partition at/dev/loop0p1
While the partition is not mounted, check the file system for any errors
sudo btrfs check '/dev/loop0p1'
Use btrfs tools to get the dimensions (in sectors) of the btrfs file system
sudo btrfs filesystem show --raw /dev/loop0p1
Use Parted command to get the dimensions (in sectors) of the disk image and theits partition on the image(s):
sudo parted -s -a opt /dev/loop0 "unit s print"
!! Warning, if used incorrectly, this could delete your data !!
Use this command to shrink the partition around the btrfs file system
echo -e "resizepart 1 [partition_end_sector]s\nyes\nunit s\nprint\nquit" | sudo parted /dev/loop0 ---pretend-input-tty
Check the file system for any errors
sudo btrfs check '/dev/loop0p1'