21.30. Storage Volume Commands
21.30.1. Creating Storage Volumes
virsh vol-create-from pool file volcommand 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.
21.30.2. Creating a Storage Volume from Parameters
virsh vol-create-as pool name capacitycommand 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
virsh vol-create-as vdisk vol-newvol vol-new created
21.30.3. Creating a Storage Volume from an XML File
virsh vol-create pool filecommand 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
<volume> <name>vol-new</name> <allocation>0</allocation> <capacity unit="M">100</capacity> <target> <path>/var/lib/libvirt/images/vol-new</path> <permissions> <owner>107</owner> <group>107</group> <mode>0744</mode> <label>virt_image_t</label> </permissions> </target> </volume>
virsh vol-create vdisk vol-new.xmlvol vol-new created
21.30.4. Cloning a Storage Volume
virsh vol-clone vol-name new-vol-namecommand clones an existing storage volume. Although the
virsh vol-create-fromcommand may also be used, it is not the recommended way to clone a storage volume. The command accepts the
--pool stringoption, 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
virsh vol-clone vol-new vol-clonevol vol-clone cloned from vol-new