How to Add a Virtual Disk to KVM?
Adding a virtual disk to KVM may be necessary when you run out of space on the current disk or to store additional information. In this article, we will look at how to do this.
First of all, you need to create a new file, which will be the virtual disk. To do this, use the command:
qemu-img create -f qcow2 /path/to/disk.dsk 20G
Where /path/to/disk.dsk
is the path to the new disk, and 20G
is the size of the disk (in this case, 20 gigabytes).
Next, you need to add the created disk to the Virtual Machine Templates: A Step-by-Step Guide" class="internal-post-link">Virtual Machine Backup in 2 Steps: A Quick Guide" class="internal-post-link">virtual machine. To do this, open the configuration file of your virtual machine (usually located at /etc/libvirt/qemu/your_virtual_machine_name.xml
) and find the <devices>
section.
Add the following line before the closing tag </devices>
:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' />
<source file='/path/to/disk.dsk'/>
<target dev='vdb' bus='virtio'/>
</disk>
Where /path/to/disk.dsk
is the path to the created disk.
After making changes to the configuration file, restart your virtual machine. Now you will have an additional virtual disk that you can use at your discretion.
Don’t forget to also create a file system on the new disk and mount it in your virtual machine to start using it.
Thus, you have learned how to add a virtual disk to KVM. We hope this article was helpful for you!