Sunday, June 16, 2013

Extending the size of a virtual disk in VirtualBox + resizing Linux LVM partitions

Wow, this was complicated.

As part of the OLPC development I've been doing on a Virtualized Fedora machine running from Windows 7, I figured I'd be smart and let VirtualBox manage my disk size. Seems appropriate. But... I set the initial disk size to 8 Gb or something too small to use for Linux and all the stuff I am doing.

So no worries, I should just need to extend the size of the VirtualBox disk up to 20Gb, right? Well, sortof.

That works, but then the Virtual Linux machine has a bunch of unpartitioned space you need to partition. That's cool, and I managed to do that in an active Linux session open. The problem is, I actually want to increase the size of the main "running" partition -- and you can't do that while a disk is running of course.

Enter something fancy called GParted, a partition manager you can boot into using an iso disk image. Pretty sweet: http://gparted.sourceforge.net/download.php

From here, you can get a fancy partition window and it looks great, but wait a sec, my disk is locked!

Darn you, LVM partitions
Apparently these LVM partitions are "locked" and hard to extend. Weird.

But after reading for an hour or so on various Google sites, I found this one which explained very well how to extend an LVM partition. Instead of extending it, I just need to take my new space (that 12Gb drive /dev/sda3), format it to be LVM2 PV format as well, and then "connect" it to the existing drive (/dev/sda2).

This is a great explanation, from this site: http://www.ibm.com/developerworks/library/l-resizing-partitions-2/
LVM is a disk allocation technique that supplements or replaces traditional partitions. In an LVM configuration, one or more partitions, or occasionally entire disks, are assigned as physical volumes in a volume group, which in turn is broken down into logical volumes. File systems are then created on logical volumes, which are treated much like partitions in a conventional configuration. This approach to disk allocation adds complexity, but the benefit is flexibility. An LVM configuration makes it possible to combine disk space from several small disks into one big logical volume. More important for the topic of partition resizing, logical volumes can be created, deleted, and resized much like files on a file system; you needn't be concerned with partition start points, only with their absolute size.
Strangely, I actually get what's happening after this explanation. I just need to "connect" these 2 drives together, after formatting the unallocated space into LVM2 PV format to match my existing 100% full /dev/sda2 drive.

GParted can't connect the drives, so I need to open up a terminal in the booted GParted window, and run something called vgextend. This allows me to take the existing "Volume Group" called "fedora" and extend it out to include the new /dev/sda3 drive as well. Wahoo!!

Wahoo!
Now the /dev/sda3 drive is also part of the same mount point as /dev/sda2. Now I should stop getting these annoying drive empty errors on my Virtualized Fedora machine... hmm maybe not quite yet. But looks like I'm close ;)

>>Edit: Ok, I figured it out. That excellent IBM page suggested I install something called system-config-lvm. First, I had to uninstall something big (firefox, and deleted some icons and media files). Then I could install it.


This allowed me to see the logical disk setup. There was 12Gb unused space that I could extend my logical drive into. This program also "extended the file system" into this space as well as just extending the logical drive volume. Whew!!!!!!!!!! What a lot of work :)

First, extend the logical volume into the remaining space.
Ahh, that looks better! Now the root area is much larger, and actually has some space!

And now when I look at the Disks utility, I can see the filesystem has increased from 5Gb to 19Gb. Woot!

Back in business
Man that was hard and interesting and also it's 4:30am and I'm going to sleep. Back to the OLPC software development another day. But for now, it was nice to get the system functioning again, and learn a little more about Linux filesystem management (more than I ever thought I'd want or need to know) at the same time :)

2 comments:

  1. That's what you get for stacking virtual volumes on virtual devices ;)

    ReplyDelete