I want to check the size of my directory.
directory is xen domU image.
directory name is xendisk
du -sh ./xendisk
returns 5.4G.
but xen domU Image size is 10G.
what happened?
You have created a sparse file for your image. If you used a command like truncate -s 10G domU.img
to create the image then this would be the result.
The wiki which I have linked has more information but basically a sparse file is one where the empty parts of the file take no space. This is useful when dealing with VMs because in most cases your VM will only take a fraction of the space available to it so using a sparse file will mean that it takes far less space on your filesystem (as you have observed). The article states that this is acheived using the following mechanism:
When reading sparse files, the file system transparently converts metadata representing empty blocks into "real" blocks filled with zero bytes at runtime. The application is unaware of this conversion.
If you need to check the size with du
you may be interested in the --apparent-size
option, which will include all of the unallocated blocks in the calculation. Therefore you could use this command if you need the output to match what ls
is telling you:
du -sh --apparent-size ./xendisk