21.30. Storage Volume Commands

This section covers commands for creating, deleting, and managing storage volumes. Creating a storage volume requires at least one storage pool. For an example on how to create a storage pool refer to Example 21.79, “How to create a storage pool from an XML file” For information on storage pools refer to Chapter 13, Storage Pools. For information on storage volumes refer to, Chapter 14, Storage Volumes .

21.30.1. Creating Storage Volumes

The virsh vol-create-from pool file vol command creates a volume, using another volume as input. This command requires either a storage pool name or storage pool UUID, and accepts requires the following parameters and options:
  • --pool string - required - Contains the name of the storage pool or the storage pool's UUID which will be attached to the storage volume. This storage pool does not have to be the same storage pool that is associated with the storage volume you are using to base this new storage volume on.
  • --file string - required - Contains the name of the XML file that contains the parameters for the storage volume.
  • --vol string - required - Contains the name of the storage volume you are using to base this new storage volume on.
  • --inputpool string - optional - Allows you to name the storage pool that is associated with the storage volume that you are using as input for the new storage volume.
  • --prealloc-metadata - optional - preallocates metadata (for qcow2 instead of full allocation) for the new storage volume.
For examples, refer to Section 14.2, “Creating Volumes”.

21.30.2. Creating a Storage Volume from Parameters

The virsh vol-create-as pool name capacity command creates a volume from a set of arguments. The pool argument contains the name or UUID of the storage pool to create the volume in. This command takes the following required parameters and options:
  • [--pool] string - required - Contains the name of the associated storage pool.
  • [--name] string - required - Contains the name of the new storage volume.
  • [--capacity] string - required - Contains the size of the storage volume, expressed as an integer. The default is bytes, unless specified. Use the suffixes b, k, M, G, T for byte, kilobyte, megabyte, gigabyte, and terabyte, respectively.
  • --allocation string - optional - Contains the initial allocation size, expressed as an integer. The default is bytes, unless specified.
  • --format string - optional - Contains the file format type. Acceptable types include: raw, bochs, qcow, qcow2, qed, host_device, and vmdk. These are, however, only meant for file-based storage pools. By default the qcow version that is used is version 3. If you want to change the version, refer to Section 24.20.2, “Setting Target Elements”.
  • --backing-vol string - optional - Contains the backing volume. This will be used if you are taking a snapshot.
  • --backing-vol-format string - optional - Contains the format of the backing volume. This will be used if you are taking a snapshot.
  • --prealloc-metadata - optional - Allows you to preallocate metadata (for qcow2 instead of full allocation).

Example 21.89. How to create a storage volume from a set of parameters

The following example creates a 100MB storage volume named vol-new. It contains the vdiskstorage pool that you created in Example 21.79, “How to create a storage pool from an XML file”:
virsh vol-create-as vdisk vol-new 100M


vol vol-new created

21.30.3. Creating a Storage Volume from an XML File

The virsh vol-create pool file command creates a new storage volume from an XML file which contains the storage volume parameters.

Example 21.90. How to create a storage volume from an existing XML file

The following example creates a storage volume-based on the file vol-new.xml, as shown:
<volume>
	<name>vol-new</name>
	<allocation>0</allocation>
	<capacity unit="M">100</capacity>
	<target>
		<path>/var/lib/virt/images/vol-new</path>
		<permissions>
			<owner>107</owner>
			<group>107</group>
            		<mode>0744</mode>
            		<label>virt_image_t</label>
          	</permissions>
        </target>
</volume>

The storage volume is associated with the storage pool vdisk. The path to the image is /var/lib/virt/images/vol-new:
virsh vol-create vdisk vol-new.xml

vol vol-new created

21.30.4. Cloning a Storage Volume

The virsh vol-clone vol-name new-vol-name command clones an existing storage volume. Although the virsh vol-create-from command may also be used, it is not the recommended way to clone a storage volume. The command accepts the --pool string option, which allows you to specify the storage pool that is associated to the new storage volume. The vol argument is the name or key or path of the source storage volume and the name argument refers to the name of the new storage volume. For additional information, refer to Section 14.3, “Cloning Volumes”.

Example 21.91. How to clone a storage volume

The following example clones a storage volume named vol-new to a new volume named vol-clone:
virsh vol-clone vol-new vol-clone


vol vol-clone cloned from vol-new