Extend a partition in Ubuntu

I recently upgraded one of my CloudAtCost servers from Developer 1 to Developer 3 because I needed more disk space. The upgrade got off to a rocky start. It took a week for the work to actually get done and then I was informed that I needed to extend my partition. I had no idea how to do that, and if CloudAtCost’s tech support did, they weren’t sharing.

As it turns out, this is all pretty easy. This document simply condenses the instructions I found here for my own future reference.

0. Back up your work!

I like rsync. The following

1
rsync -azP daniel@example.com:/opt/git .

copies everything out of the hypothetical git repositories on my server to my local machine.

1. Take a look at the partition table

Login to your server.

1
ssh daniel@example.com

You’ll need to know where the new partition lives:

1
sudo fdisk -l /dev/sda

After the next step is complete, there will be a new device in the list (probably at /dev/sda6)

Also, make note of the file system’s current size:

1
df -hT

This will be helpful in verifying that the following steps actually worked.

2. Create a new logical partition

1
sudo cfdisk

From the interface provided:

  1. Select the unallocated space
  2. Select New
  3. Select Logical and allocate all the available space (shown by default)
  4. Select Type and enter 8E
  5. Select Write, type yes, and hit Enter
  6. Quit cfdisk
  7. Reboot the server (sudo reboot)

3. Take another look at the partition table

Once rebooted and re-logged in, run

1
sudo fdisk -l /dev/sda

and verify that there is, in fact, a new device that wasn’t there before (again, probably mounted at /dev/sda6). If there isn’t, you’re out of luck, because this is all just magic to me.

4. Create a new physical volume

Assuming the new device lives at /dev/sda6

1
sudo pvcreate /dev/sda6

5. Extend the existing volume group

1
sudo vgdisplay

Make note of the name associated with VG Name. Mine was called ubuntu1204-vg even though I’m running Ubuntu 14.04.

1
sudo vgextend ubuntu1204-vg /dev/sda6

6. Extend the logical volume

1
sudo lvdisplay

Make note of the path associated with LV Name used for the root filesystem (mine was /dev/ubuntu1204-vg/root)

1
sudo lvextend -l 100%FREE /dev/ubuntu1204-vg/root

6. Extend the file system

1
sudo resize2fs /dev/ubuntu1204-vg/root

7. Verify

1
df -hT

should reveal a file system much bigger than what you say in Step 1.

The preceding steps were ripped off from these guys, who, in turn, ripped off their info from here.