[virt-tools-list] sparse files and ls

Richard W.M. Jones rjones at redhat.com
Wed Jun 8 16:39:12 UTC 2011


On Wed, Jun 08, 2011 at 11:19:32AM -0400, Gary Scarborough wrote:
> Not sure if this is a bug or in inconsistency so I figured I would post this
> here before filing a bug.  When I create a qcow2 image file using qemu-img,
> the default is a sparse file.  'ls -lash' shows that the file only has a
> small size.  However, when I create a raw file, the same ls command shows
> the size to be the full size of the image file, not just the size of the
> contents.  At first I thought I just wasn't getting a sparse file, but
> things like df show the drive to have the size actually in use.  I also
> wonder if when I transfer the file using scp, am I sending a lot of zeroes
> through the network needlessly?

I use 'truncate' to create sparse files, eg:

$ df -h .
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/lvroot     45G   27G   19G  59% /
$ truncate -s 100G sparse
$ ls -lh sparse
-rw-rw-r--. 1 rjones rjones 100G Jun  8 17:36 sparse
$ ls -lash sparse
0 -rw-rw-r--. 1 rjones rjones 100G Jun  8 17:36 sparse
$ du -sh sparse 
0		  sparse

Both 'ls -lash' and 'du' are showing the correct (sparse) size for me.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the virt-tools-list mailing list