Libvirt Storage Volume Renaming: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
m (Ovidiu moved page Libvirt Storage Volume Rename to Libvirt Storage Volume Renaming without leaving a redirect)
 
(4 intermediate revisions by the same user not shown)
Line 24: Line 24:
  <disk type='file' device='disk'>
  <disk type='file' device='disk'>
     <driver name='qemu' type='raw'/>
     <driver name='qemu' type='raw'/>
     <source file='/main-storage-pool/test-volume.raw'/>
     &lt;source file='/main-storage-pool/<b>test-volume.raw</b>'/>
     <target dev='vdb' bus='virtio'/>
     <target dev='vdb' bus='virtio'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
Line 35: Line 35:
  <disk type='file' device='disk'>
  <disk type='file' device='disk'>
     <driver name='qemu' type='raw'/>
     <driver name='qemu' type='raw'/>
     <source file='/main-storage-pool/test-volume-2.raw'/>
     &lt;source file='/main-storage-pool/<b>test-volume-2.raw</b>'/>
     <target dev='vdb' bus='virtio'/>
     <target dev='vdb' bus='virtio'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
     <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
Line 41: Line 41:
  ...
  ...


4. Restart the virtual machine, it should not detect any difference.


3. Optional: Delete the original storage volume from the pool with [[virsh vol-delete]]. Note that [[virsh vol-delete]] will also ''delete the content'' of the underlying storage, not just removes the storage volume definition from the pool.
5. Optional: Delete the original storage volume from the pool with [[virsh vol-delete]]. Note that [[virsh vol-delete]] will also ''delete the content'' of the underlying storage, not just removes the storage volume definition from the pool.


  virsh vol-delete test-volume.img main-storage-pool
  virsh vol-delete test-volume.img main-storage-pool

Latest revision as of 21:43, 30 June 2017

Internal

Overview

There is no virsh command to rename a volume, but it can be achieved via the following sequence of steps:

1. Shutdown all the virtual machines that use the volume:

virsh shutdown test-vm

2. Clone the volume, under a different name.

virsh vol-clone --pool main-storage-pool test-volume.raw test-volume-2.raw

For more details, see virsh vol-clone.

3. Edit the definition of the virtual machines using the volume, and change the name of the logical volume in the definition.

Replace:

...
<disk type='file' device='disk'>
    <driver name='qemu' type='raw'/>
    <source file='/main-storage-pool/test-volume.raw'/>
    <target dev='vdb' bus='virtio'/>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</disk>
...

with

...
<disk type='file' device='disk'>
    <driver name='qemu' type='raw'/>
    <source file='/main-storage-pool/test-volume-2.raw'/>
    <target dev='vdb' bus='virtio'/>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</disk>
...

4. Restart the virtual machine, it should not detect any difference.

5. Optional: Delete the original storage volume from the pool with virsh vol-delete. Note that virsh vol-delete will also delete the content of the underlying storage, not just removes the storage volume definition from the pool.

virsh vol-delete test-volume.img main-storage-pool