In this recipe, we are going to examine a few different ways of adding new block devices to a KVM instance. The new block device can then be partitioned, formatted, and used as a regular block device inside the guest OS. We can add disks to live running instances, or we can attach them persistently by creating XML definitions for the individual block devices offline. From the host OS, we can present any type of block device file to the guest, including iSCSI targets, LVM logical volumes, or image files.
To attach a new block device to a KVM guest, run the following:
- Create a new 1 GB image file:
root@kvm:~# dd if=/dev/zero of=/tmp/new_disk.img bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 0.670831 s, 1.6 GB/s root@kvm:~#
- Attach the file as a new disk to the KVM instance:
root@kvm:~# virsh attach...