Managing Disks on KVM¶
Use the qemu-img command to manage your disks.
For the full documentation on qemu-img, refer to https://www.qemu.org/docs/master/tools/qemu-img.html.
Viewing Disk Properties¶
To view the properties of a disk file, use the following command, specifying the name of your disk file:
qemu-img info disk-file-name.qcow2 Note
If the disk file is in use by the virtual machine, you must turn it off first or add the -U argument on the qemu-img command. However, using this argument is not considered safe, because it forces the image to be shared between processes.
The output will look similar to the following:
image: disk.qcow2
file format: qcow2
virtual size: 1 GiB (1073741824 bytes)
disk size: 1 GiB
cluster_size: 65536
Format specific information:
compat: 1.1
compression type: zlib
lazy refcounts: false
refcount bits: 16
corrupt: false
extended l2: false
Child node '/file':
filename: disk.qcow2
protocol type: file
file length: 1 GiB (1074135040 bytes)
disk size: 1 GiB
Format specific information:
extent size hint: 1048576
Note the difference between virtual size and disk size. The virtual size is the size that the file is allowed to expand to, whereas disk size specifies the actual space it takes up on the host machine.
If your disk is not fully allocated/thick-provisioned, the virtual size value is likely higher than the disk size value.
Restriction
VSI OpenVMS does not support thin-provisioned disks, so you must always check that your disk is thick-provisioned.
Creating Disks¶
Before you create a disk, check the Recommended KVM Virtual Machine Settings for your version of VSI OpenVMS.
Restriction
VSI OpenVMS does not support disks larger than 1.98 TB.
Below is an example of a command that creates a thick-provisioned 20 GB disk.
qemu-img create -f qcow2 -o preallocation=full disk-name.qcow2 20G The arguments used in this command, along with the recommended options, are explained in the table below.
| Arguments | Argument options | Description | Recommended options |
|---|---|---|---|
-f | The file format for the disk. | It is recommended that you use qcow2 or raw.
| |
-o | Specifies the path to the target file. | You must specify preallocation=full when creating a new disk for OpenVMS. |
Increasing Disk Size¶
To resize a hard drive, use the qemu-img resize command. In the following example, the disk size is expanded by 10 GB.
qemu-img resize --preallocation=full -f qcow2 disk-name.qcow2 +10G Notice the difference in syntax compared to creating a disk. Instead of using the -o switch, --preallocation=full is specified. This is necessary to keep the disk thick-provisioned, as by default, the resize command only extends the virtual size of the disk, it does not pre-allocate the space for it, effectively converting the disk to thin-provisioned, which is not supported on OpenVMS.
Warning
VSI does not recommend using the resize utility to shrink the disk as this can lead to data loss.
Attaching Disks to an Existing Virtual Machine¶
To attach a disk to an existing VM, you must first identify what device is next available for mounting.
-
Execute the following command on your host system to list the devices used by your virtual machine:
sudo virsh domblklist vm-nameThe output will be similar to the following:
Target Source -------------------------------------- sda /home/user/X86E924OE.ISO sdb /home/user/disk.qcow2The
Targetcolumn shows the virtual device names that are already in use. In this case,sdccan be the next available virtual device name.Tip
The letters
a,b,c, etc. in the virtual device (target) name correspond to theunitvalue in the disk device configuration and theindexvalue in the assigned SCSI controller configuration.acorresponds to the value0,bcorresponds to1, etc. -
Run the following command, replacing
vm-name,/path/to/disk/disk-name.qcow2, andtarget-device-namewith appropriate values:
sudo virsh attach-disk vm-name /path/to/disk/disk-name.qcow2 target-device-name --driver qemu --subdriver qcow2 --cache writethrough --persistent
By default, the disk is attached to the VM as a SCSI device. In order to attach the disk as a SATA device, add --targetbus sata to the command line above.
The arguments used in this command, along with the recommended options, are explained in the table below.
| Arguments | Argument options | Description | Recommended options |
|---|---|---|---|
--driver | qemu | ||
--subdriver | This should be the same format as the disk, i.e. if your disk is .qcow2, specify qcow2. | ||
--cache | writethrough | The cache mode to be used by the disk. | This is required to be writethrough. |
--persistent | This makes the disk a permanent attachment. |
For the full documentation on the virsh attach-disk command, refer to the attach-disk usage description.
Important
In certain scenarios, adding more than five Virtio-SCSI disks may result in KVM generating an additional controller using the lsilogic model name. This must be fixed by remapping the additional devices to a Virtio-SCSI controller as described in Virtio-SCSI Controllers.
Converting Images¶
It is possible to convert images from one format to another using the qemu-img convert command.
For the full documentation on the qemu-img convert command, refer to the Converting between image formats article.
For information on how to convert raw/qcow2 disks to vmdk disks supported on VMware ESXi, refer to the Converting Hypervisor Images section.