Monday, March 13, 2017

Create and attach the disk image to qemu-kvm VM

Create and attach the disk image

Execute these steps on the KVM hypervisor host.

cd to the folder where you store your disk images:
cd /var/lib/libvirt/images/

Create the new disk image:
qemu-img create -f raw example-vm-swap.img 1G

We use qemu-img to create a new raw disk image with a size of 1 GB.
Attach the disk to the example virtual machine using virsh:

virsh attach-disk example-vm --source /var/lib/libvirt/images/example-vm-swap.img --target vdb --persistent

We use virsh to attach the disk image /var/lib/libvirt/images/example-vm-swap as a virtio (/dev/vdb) disk to the domain (vm) example-vm.
The --persistent option updates the domain xml file with an element for the newly attached disk.

Note that if you already have a /dev/vdb disk you need to change vdb to a free device like vdc or vdd.


Source:
https://raymii.org/s/tutorials/KVM_add_disk_image_or_swap_image_to_virtual_machine_with_virsh.html#Create_and_attach_the_disk_image




No comments:

Post a Comment