O'Reilly logo

KVM Virtualization Cookbook by Konstantin Ivanov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

To attach a new block device to a KVM guest, run the following:

  1. Create a new 1 GB image file:
root@kvm:~# dd if=/dev/zero of=/tmp/new_disk.img bs=1M count=10241024+0 records in1024+0 records out1073741824 bytes (1.1 GB) copied, 0.670831 s, 1.6 GB/sroot@kvm:~#





 

 

  1. Attach the file as a new disk to the KVM instance:
root@kvm:~# virsh attach-disk kvm1 /tmp/new_disk.img vda --liveDisk attached successfullyroot@kvm:~#
  1. Connect to the KVM instance via the console:
root@kvm:~# virsh console kvm1Connected to domain kvm1Escape character is ^]Debian GNU/Linux 8 debian ttyS0debian login: rootPassword:...root@debian:~#
  1. Print the kernel ring buffer and check for the new block device:
root@debian:~# dmesg | grep vda[ 3664.134978] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required