Tuesday, July 17, 2012

Add additional drive or storage to a KVM guest

Ever needed to attach an additional virtual drive or storage drive to your KVM guest?

Heres how you can.

Firstly, I recommend that you backup your data!

On the KVM host, create the 'drive' with either of the following two commands

qemu-img create -f qcow2 /path/moredrivespace.img 10G
or
dd if=/dev/zero of=/path/moredrivespace2.img bs=1 seek=10G count=0

This is where it gets interesting.

Now to add your new 'drive', to your KVM guest.

Run the command 'virsh'
Welcome to virsh, the virtualization interactive terminal.
Type:  'help' for help with commands
       'quit' to quit
virsh # attach-disk KvmGuestDomainName /path/moredrivespace
.img vdo

By default or by specifying the target of vdo, the default driver will be
Virtio. If you are a FreeBSD user like I am. You will struggle, for FreeBSD will not see the device. I find you need to use a SCSI device. And inorder to use / do so, you need to run this command.


attach-disk KvmGuestDomainName /space/moredrivespace.img sda

I also found for FreeBSD, its best to use the dd command. 

As per usual, Linux guests just work.
;)

And then reboot your VM.

HTH
Brent 




No comments:

Post a Comment