How to add a physical disk to KVM based Virtual machine

Kernel-based virtual machines have the option to provide an additional hard disk. In this post, we will describe how to add a hard disk on the host physical machine to the guest operating system.

1 – Create the additional disk

There is two way to create additional storage, either we can create through graphical or command-line utility. The default storage location is /var/lib/libvirt/images . Let’s create a new additional disk through the command below.

The below example command creates a RAW image with a maximum size of 5 GB named techtransit-disk1.img .

# qemu-img create -f raw /var/lib/libvirt/images/techtransit-disk1.img 5G 
Output : Formatting '/var/lib/libvirt/images/techtransit-disk1.img', fmt=raw size=5368709120
Qemu-image Creating Disk

2. Attach the disk to the virtual machine

The virsh utility is a management that is managed virtual machines on the command line. To view the currently running virtual machines, execute the below command. This command will show only running machines. Before attaching the disk, the virtual machine should be in a running state.

# virsh list

Below the command is the syntax to attach the disk to a virtual machine. so you can use the below command syntax to add disk in your VM. Here in my machine there is vda disk already and I am attaching the next disk on the VM, I prefer this disk will be vdb.

# virsh attach-disk {running-vm-name} /var/lib/libvirt/images/{disk-image} vdb --cache none

3. Verify Disk in Virtual Machine

After attaching the physical disk to a virtual machine, go to your machine and Run lsblk utility to check to attach disk should be visible for further use.

# lsblk

About Sachin G

I am a professional freelance contributor and founder of tech transit. Love to write and lover of education, culture, and community. I have been using it, setting, supporting, and maintaining it since 2009.Linux rocks!

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *