Bog Roll ::

It's Not Magic, It's Work!

29 Jan 2011

Making a Virtual Machine's Filesystem Larger

We have a remote server at work that is running virtual machines for various web purposes. Alas when originally created the file system of the virtual machines was smaller than we needed. The physical host system has plenty of space, we just have to grow the virtual file systems.

In principle I could have grown the file systems on the server but that would have loaded the server during the working day when the customers use it, plus our corporate network is too slow to do anything significant over the public Internet.

My original plan was top stop the virtual machines for a few seconds, copy the virtual file system, restart the virtual machine then transfer the copy to a machine at work. Once I have it on a fast system with plenty of disk-space I'd then cat some zeros on to the end of the container, boot it up with a live disk and extend the filesystem over the empty space. I'd reboot it with it's own Kernel to make sure it's all okay and happy, then copy the enlarged file back up to the remote server.

I however hit some problems... Though we have a fancy network at work, in practice it's slower than the ADSL network I have at home and not only is it slow but it often hits capacity problems, dropping connections. "Plan B" was to use a test ADSL link to pull the files down, but that still left a slight outage during the working day. Even if I could get the filesystems down to a work machine, our desktop systems all run Windows and have tiny hard drives - which isn't much help. I managed to find an older desktop system and borrow a 1 TB external drive, but in the end I decided it would be easier to do at home on my home systems.

Yesterday I pulled down a development and staging virtual system as Qemu/KVM qcow2 files. On my home server I converted them to raw image files and made them larger. Using a Debian GNU/Linux live image I booted them up, expanded the ext3 filesystem and shut them down. I rebooted them with their own KVM Kernel to test that they were okay, then converted the raw image back into a qcow2 and at the moment I'm scping them back to the server.

It's sad that I couldn't really do this at work, but at least I learnt some new stuff and I know my home infrastructure is better than works. I also found out that as expected a 2 GiB file as qcow2 expands to a 4 GiB raw imaged, which I expanded to 20 GiB, compresses back to a 2 GiB qcow2 - very cool!