2012-12-02

Adding disk to Proxmox KVM virtual machine without rebooting


We use Proxmox to run KVM virtual machines. Sometimes VMs end up requiring more disk space than originally planned. You can add a new disk from Proxmox but VM has to be rebooted. Proxmox doesn't do disk hotplug but we can plug the disk in from the qm monitor.

I have a KVM virtual machine with VM ID 178. It is Ubuntu Server installed on LVM to allow extending partitions live. For device hotplugging to work, the VM must have acpiphp module installed. You can modprobe it in, and put it in /etc/modules.

Add the disk from Proxmox web interface and find out where the disk image file or underlying LVM volume is. In this case Proxmox created vm-178-disk-3 on local-lvm storage.

Log on to Proxmox platform with SSH and open qm monitor. Command info block shows the current disks.


kvm7:~# qm monitor 178
qm> info block
ide0-cd0: removable=1 locked=0 [not inserted]
virtio1: removable=0 file=/dev/pve/vm-178-disk-2 ro=0 drv=raw encrypted=0
virtio2: removable=0 file=/dev/pve/vm-178-disk-1 ro=0 drv=raw encrypted=0
virtio0: removable=0 file=/dev/pve/vm-178-disk-3 ro=0 drv=raw encrypted=0
qm>

Hotplug the new disk:

qm> pci_add auto storage file=/dev/pve/vm-178-disk-3,if=virtio

If the disk image is a file:


qm> pci_add auto storage file=/var/vz/images/178/vm-178-disk-3.raw,if=virtio

The disk should show up in VM's dmesg. In this case /dev/vdc appeared. Add the disk to LVM and extend the filesystem.

# pvcreate /dev/vdc
# vgextend vg0 /dev/vdc
# lvextend -L +16G /dev/vg0/root
# resize2fs /dev/vg0/root