Like every hypervisor kvm also supports both block type and file based storage to attach to kvm guests, in this post i'm attaching only block device which means i'm attaching physical hdd to a kvm guest which is already connected to my host machine.
Attaching disk to guest can be dowe in two ways , using virsh command line which is just a command and is temporary, you'll loose it after a reboot.
here is the command
Attaching disk to guest can be dowe in two ways , using virsh command line which is just a command and is temporary, you'll loose it after a reboot.
here is the command
ubuntu@kvm:~$ virsh attach-disk node1 /dev/sdb1 vda
node1 is my kvm guest name which you'll get using "virsh list" , "/dev/sdb1" is hard drive partition which is connected to kvm host, and "vda" is the hdd name i given to appear with in kvm guest.
let's log into ivm guest and type 'lsblk' to see if '/dev/vda' present or not.
ubuntu@node1:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 8G 0 disk |-sda1 8:1 0 243M 0 part / vda 53:0 0 100.5G 0 disk
see ... now as usual format it and mount , in case it's not formatted, if data present on this disk it will be show
but but this setup lasts till guest reboot. To make it permanent guest config has to be modified and guest has to be rebooted.
edit guest config file with virsh which uses vim editor, search for 'disk', you'll find entry like below,
disk type='file' device='disk'>
Add below lines immediately to above entry which means after "</disk>"
after modification it should look like below
disk type='file' device='disk'>
If there is any syntax error, you'll be prompted to re edit so don't worry. Note: To avoid data corruption don't use this drive or partition on the kvm host.
0 Comments