Kernel-based virtual machines have the option to provide an additional hard disk. Here, we delve into the step-by-step process of adding a physical disk to a KVM-based virtual machine, empowering administrators to effectively manage their virtual infrastructure.

Steps to Add a Physical Disk to a KVM-based Virtual Machine

1 – Create the additional disk

There are two ways 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 kvm
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

Here is one more post regarding KVM installation on Ubuntu, click here to read more.

Integrating a physical disk with a KVM-based virtual machine extends its storage capabilities and enhances its performance, enabling administrators to accommodate growing workloads and data requirements. By following the steps outlined in this guide, administrators can seamlessly add physical disks to virtual machines in their KVM environments, thereby optimizing resource utilization and facilitating efficient virtualized workflows.

By 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! Sachin G Follow me on LinkedIn and x formerly twitter