How to add disk image to KVM virtual machine with virsh command

To add a disk image to a KVM virtual machine using the virsh command, you can follow these steps:

  1. Attach the disk image to the virtual machine:
    sudo virsh attach-disk <vm-name> <disk-image-path> <target-dev> --subdriver qcow2 --cache none --persistent

    where <vm-name> is the name of the virtual machine, <disk-image-path> is the path to the disk image file, and <target-dev> is the target device identifier for the new disk, such as vdb.

  2. Verify that the disk has been attached to the virtual machine:
    sudo virsh domblklist <vm-name>
  3. Start the virtual machine to make the new disk available:
    sudo virsh start <vm-name>

Now, the disk image will be available to the virtual machine and you can use it as you would any other disk.

(https://www.propertyspecialistsinc.com)

Leave a Comment