3

I'm creating a new virtual disk using the following command*:

$ virsh vol-create-as --format=qcow2 guest-disks disk_instid.24_diskid.30 8192M
Vol disk_instid.24_diskid.30 created

The "guest-disks" pool is a simple "dir"-Type pool. As you see, the command succeeds, but when I'm trying to install an operating system in the new domain, it only shows up as a fraction of a megabyte in size:

# fdisk -l /dev/sda 

Disk /dev/sda: 0 MB, 262144 bytes
1 heads, 1 sectors/track, 512 cylinders, total 512 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sda doesn't contain a valid partition table

As you see, the size is completely wrong. Any idea why this is?

*Don't mind the numbers - it's part of a tool that creates domains automatically.

Dave Vogt
  • 257
  • 2
  • 12

2 Answers2

7

Okay, I figured it out on my own. If you don't specify the format in the domain XML, Libvirt expects it to be of the "raw" format by default, which does not expand with usage, but needs to be fully allocated (see answer by dyasny). The ~200KB are the initial data structure of the qcow2 format.

What needs to be done is this: You must add a "driver" element to the "disk" part of the domain xml, explicitly mentioning the qcow2 format, like so:

<disk type="file" device="disk">
    <driver name="qemu" type="qcow2" />
    <source file="/var/lib/virt/guest-disks/disk_instid.24_diskid.30" />
    <target dev="sda" />
</disk>

After this change, the domain OS sees the disk as expected.

Dave Vogt
  • 257
  • 2
  • 12
  • +1: please set this as the answer for the question. If the vm was created with `virt-install`, `,format=qcow2` has to be added after the filename of the image used. Some keywords for google searches: 202.2 kB ATA QEMU HARDDISK. – ceztko Apr 19 '12 at 11:43
0

try with --allocation 8192M this will allocate the disk size

dyasny
  • 18,482
  • 6
  • 48
  • 63