We're evaluting KVM for Linux virtualization on a few projects. All is going well so far. But one of our requirements is the ability to add disk space to a running guest without rebooting or taking it offline. Is this possible with KVM?
The only thing I've found so far (but have not tested yet) is the ability to hotplug disks into the machine. If I go this route, then I could always add the new disk to an LVM volume group on the guest and then extend the chosen logical volume. The biggest downside to this approach is that over time we might end up with guests having variable numbers of virtual disks. The "real" disk space would be provided to the host over a SAN, so we can always add more space to the host whenever.
I know that's an old question but I've found it while googling for the solution and hope it may help someone else.
As for today it is possible to resize the hard drive on the machine. I've found a working way here:
https://bugzilla.redhat.com/show_bug.cgi?id=648594
The following steps must be performed:
Find out a file name and KVM device name of the hard drive you want to resize:
The one interesting for us is disk. You should look for
source
andalias
blocks. For me file name istest.img
and alias name isvirtio-disk0
. To this name, you need to prependdrive-
to get qemu drive name.Now we actually resize the drive using qemu monitor:
Note that filename was used without .img extension and drive- was added to disk alias. The 100G is the resulting size of the drive we want to have
Login to the machine and check that actual size was changed:
That's it! Now you can either create new partitions or resize existing ones.
AFAIK, this is not possible -- you can add new disk images, and as you point out you could also add new images to an LVM volume, but in order to resize an active, bootable disk image you need to be able to shut it down and edit the partitions.
Here's a good explanation for expanding an image. Although it requires shutdown, you could probably get away with only a couple of minutes of downtime, especially if you avoid the --nonsparse image option and dd the gparted disk to an iso file and mount in your KVM guest in advance. Hope this helps.
I think you're stuck doing what you've mentioned if you want to do it without taking the machine down.
Why not just give the virtual machines LUNs right off the SAN and manage the space there? This works better if you want to use features like live migration anyhow.
KVM is based on QEMU so all it's image format support comes from that project. Here's a good how-to resize the various formats that Qemu/KVM support. But the Qemu forum would be a good place to ask this question if you don't get any solid answers here.
Another option which may not be ideal is to use really large qcow2 or other sparse image format for the drives. So you could give each machine a small drive for the OS and a large sparse image for data under LVM. This would at least keep the number of virtual drives/images that you're having to manage. But this thin provisioning could be a problem though if you do this to 1000 machines and everyone takes you up on the free space that they see.
XEN I believe has the same limitations currently.
It is possible to move a Linux system between disks while it's running. The limitation is that you cannot alter partitions on a disk that has partitions in use.
To do this your root filesystem must be on an LVM, this often means that you have to have a separate boot filesystem (this is not, however, essential, it just makes things easier)
After plugging in the new disk, you add it to the LVM with vgextend, use pvmove to move the rootfs to the new disk, use lvextend and resize2fs to expand the logical volume and filesystem respectively then use vgreduce to remove the old disk from the volume group. Once removed the old volume can be unplugged.
For the simple case you have a tiny disk for the boot filesystem that you never have to touch. But if it's on it's own it's easy to unmount it unplug it, plug in a new one and rebuild the boot disk without stopping the system. (just don't crash while you're doing it)
Note: resize2fs can also shrink filesystems.
Not possible atm, but afaik it's a feature under development. What you can do instead is to connect to an iSCSI target from the VM and manage the space on that target on the SAN side.