mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
The current way to get the size of a filesystem is to query the size in bytes of the device. However, this gives the whole size of the device where a filesystem is stored, and it does not consider the actual size for which the filesystem is configured (e.g. in case it was shrunk). A simple reproducer for this is: $ guestfish -N test.img=fs:ext4:2G resize2fs-size /dev/sda1 1073741824 As result, try to mount the filesystem, and get its actual statistics to determine its full size. In case mounting fails, fall back to the previous method, which is still a good value in the majority of the cases. Thanks to: Erik Skultety.