Stretching the LVM on a VMware Debian Virtual Appliance – live!

/

Introduction

A common scenario occurs when you have more data to store than the original analysis indicated. How do you expand your storage or shift to a more capable machine without disruption to the site? I always use Logical Volume Manager (LVM), where possible. You never know when you might need to increase the size of your disk.

The problem

OK, we ran out of space. Those pesky image files were large and unoptimized and we needed more space ASAP. We had an extra couple of Gig floating about on the VMware server, currently unallocated.

The solution

Let’s reallocate that free space to the virtual disk and stretch the LVM to make use of it – with the minimum downtime.

Gear

For this crazy experiment (read that as ‘production issue‘) I have :

  • VMware ESX Server 3.5.0 Build 64607
  • Vmware Infratructure Client Version 2.5.0 Build 64192
  • Debian Etch (2.6.18-6-686 SMP)
  • Dogstar my trusty desktop (Win XP)

Let’s get into it…

I don’t usually use VMware ESX (For those of you who know me I am a XEN fan), but here it goes …

Firstly, I have to shutdown the VM and add more space to the virtual machine- its all gui and pretty straightforward. I only added an extra 10GB because, you never know, it might all go pear-shaped. Small fruit is better than big fruit, right?

Time to restart the VM.

Now, I need to let Linux know it has more space to play with and that everything is sitting on the root partition.

If we have a look at the partition table we can see that we have extra space, but it is not currently available:

Time to jump into the fdisk mobile………

fdisk /dev/sda
(then n for new partition,
 then p for primary,
 then 3 for sda3,
 then w to write changes to partition table)

I quickly add a new primary partition allocating the newly free space and write it to the partition table. The kernel of course is using the old table so I will need to reboot.

OK, let’s introduce this new partition to the lvm

lvm pvcreate /dev/sda3

Now let’s add it to the volume group

lvm vgextend media2 /dev/sda3

Let’s see what happened:

or to put it another way:

So far so good. Let’s try and utilize this extra space

lvm lvextend -L+10G /dev/media2/root

Success!

Now like chillies in a bottle of vodka, we need to use this extra space …

We are using ext3 for our file system so the magic lies in a little tool called ext2online which allows us to stretch a partition while it is mounted.

ext2online /dev/media2/root

Cool bananas!!!!

In Summary

So, technically I did have a couple of reboots in there, but I did achieve the minimum of downtime:

  • stop server and stretch virtual disk – 45 seconds,
  • reboot server and reinitialize partition table – 30 seconds

The disk of course was resized while the OS was running – less than 2 minutes downtime.

Mission success!

Author:

Related Articles