To add a disk image to a KVM virtual machine using the virsh
command, you can follow these steps:
- 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 asvdb
. - Verify that the disk has been attached to the virtual machine:
sudo virsh domblklist <vm-name>
- 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.