df
and ls
report different sizes on my host machine because of the difference between the allocated size and the amount of space that's actually used in the EXT4 filesystem.The problem is that both report the wrong size. qemu-img
also doesn't report the actual space that's used inside the guest's filesystem (also EXT4).
On the host:
# qemu-img info sdb.rawimage: sdb.rawfile format: rawvirtual size: 2.0T (2173253451776 bytes)disk size: 1.9T# ls -larth sdb.raw -rw-r--r-- 1 hypervisor hypervisor 2.0T Mar 6 13:47 sdb.raw# du -sh sdb.raw 1.9T sdb.raw# fdisk -l sdb.raw Disk sdb.raw: 2 TiB, 2173253451776 bytes, 4244635648 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: E6242A7E-1253-E74A-9389-68654A21E4F4Device Start End Sectors Size Typesdb.raw1 2048 4244635614 4244633567 2T Linux filesystem
On the guest (/dev/vdb1):
# df -hFilesystem Size Used Avail Use% Mounted ondev 32G 0 32G 0% /devrun 32G 496K 32G 1% /run/dev/vda2 220G 100G 111G 48% /tmpfs 32G 0 32G 0% /dev/shmtmpfs 32G 0 32G 0% /sys/fs/cgrouptmpfs 32G 26M 32G 1% /tmp/dev/vdb1 2.0T 761G 1.2T 41% /roottmpfs 6.3G 0 6.3G 0% /run/user/1002
As you can see, I'm only using 761G on the guest system and there's still 1.2T available. Despite that, qemu-img
says that I'm using 1.9T. What's the reason? Is there a way to fix this? I'd like to see the actual used space on the host machine. I know it can be achieved because it worked correctly before I filled sdb.raw
with data - qemu reported the correct disk size based on the space used inside the disk. Unfortunately, it worked only one way - when the used space was gradually increasing. After I deleted some files and reduced the used space from 1.9T to 761G, the size reported by qemu-img
didn't change to a smaller value, it remained at 1.9T.