today my colleague Geoff told me that he was trying to resize an OpenNebula image. As I had never done that before, I started to review OpenNebula documentation and I found this email in the OpenNebula mail list (please suscribe!, it’s really useful!). It seems that resizing is not yet supported (maybe I’m wrong and there’s another solution!) but thanks to this issue information I found virt-resize.
This is virt-resize description: a tool which can resize a virtual machine disk, making it larger or smaller overall, and resizing or deleting any partitions contained within. Looks promising! The virt-resize information page is full of examples so it has been easy to start using it.
Ok this is what I’ve tested and please remember proceed with caution I’m no responsible of any damage caused by following this steps and try to read the documentation first I’ve just used that info :-D.
- I’ve installed the libguestfs-tools package in my OpenNebula host running CentOS: yum install libguestfs-tools
- I halted one VM as I want to increase the size of its main disk image (the VM can’t be running!)
- Using Sunstone I’ve found where the disk is located inside the datastore: Virtual Machines -> Select the VM -> Template tab -> Disk section (e.g: /var/lib/one/datastores/1/1a8a07d0382566a89afd96a134eb04cf)
- Now I’ve inspected the image file with the virt-filesystems command.
[root@haddock ~]# cd /var/lib/one/datastores/1/ [root@haddock 1]# virt-filesystems --long --parts --blkdevs -h -a 1a8a07d0382566a89afd96a134eb04cf Name Type MBR Size Parent /dev/sda1 partition 83 500M /dev/sda /dev/sda2 partition 8e 20G /dev/sda /dev/sda device - 20G -
- I want to have a 30GB size for my /dev/sda2 partition, so I create a file called newdisk with the truncate command:
truncate -s 30G newdisk
- I create a backup of the OpenNebula image: cp 1a8a07d0382566a89afd96a134eb04cf tmp
- Ok! This is very important I have a logical volume called /dev/vg_moriarty/lv_root, so today I’m not only resizing the /dev/sda2 partition I also want the logical volume to use the new extra space:
virt-resize tmp newdisk --expand /dev/sda2 --LV-expand /dev/mapper/vg_moriarty-lv_root
- This is a screenshot showing the resizing progress.
- Once the resizing progress is finished I substitute the original image with the newdisk file and I change the permissions:
mv newdisk 1a8a07d0382566a89afd96a134eb04cf chown oneadmin:oneadmin 1a8a07d0382566a89afd96a134eb04cf
- I check if the partitions have been modified before running the VM. It seems that the /dev/sda2 is now 30GB.
[root@haddock 1]# virt-filesystems --long --parts --blkdevs -h -a 1a8a07d0382566a89afd96a134eb04cf Name Type MBR Size Parent /dev/sda1 partition 83 500M /dev/sda /dev/sda2 partition 8e 30G /dev/sda /dev/sda device - 30G -
- Ok. I start the VM to check if it boots and the logical volume is fine (28GB!)
- It works!! Thanks to OpenNebula’s mailing list (Simon Boulet, Ricardo Duarte, Ruben S. Montero…) and the libguestfs creators I’ve found a way to resize a Linux image.
Please if you know a better way or OpenNebula has already a way to modify the size please let me know, I want this post to be useful for the community.
P.S: Thanks Geoff!