Wednesday, February 19, 2014

Increase Ubuntu Hard Drive Size in VMWare ESXi

I have only done this with my Ubuntu virtual machine so far, so I can't tell you if this works for any other form of linux.  I will have to test it some time to find out.

My situation:  Koha library system loaded on a Ubuntu Server 13.10.  I had originally set it up as a test server so I only gave it 2Gb of ram and a 30 Gb hard drive.

Logs can fill up fairly quickly with everything going on, and the database takes space when you have 20,000 book records and 500 student records.

I followed these instructions to increase the hard drive size of my server, on the fly and it worked perfectly, now I have storage space again and the system is working again!

http://www.joomlaworks.net/blog/item/168-resizing-the-disk-space-on-ubuntu-server-vms

First step is to increase the hard drive to the virtual machine.  I had lots of space, and could add more, but I thought 80Gb would be a good amount for now.  So I increased it by 50Gb to make it 80Gb in total size.

Then access the machine with PuTTy.

List all partitions
$ ls -la /dev/sda*

Create new partition using fdisk:
$ sudo fdisk /dev/sda
p - to list all partitions
n - to create a new partition
l - for "logical"
Accept the default start and end blocks, as that is the new section that has been allocated.
t - to change the partition type
8e - set the type to Linux LVM
p - to list the new partition table
w - to write the changes

A warning message will say that the new drive won't be available until you restart, or use this command:
$ sudo partprobe


Now it is time to create the partition, extend the current volume and reprobe the partition table.

Create partition on new disk - (mine was /dev/sda4, yours might be different)
$ sudo pvcreate /dev/sda4

Display the current volume group and get the name
$ sudo vgdisplay - "VG Name" is what you are looking for here

Extend the volume group with the new partition
$ sudo vgextend VGName /dev/sda4

Get the name of the main logical volume
$ sudo lvdisplay - "LV Name" is what you are looking for here

Extend the logical volume by X Gbs
$ sudo lvextend -l -XG LVName

Resize the file system to account for the new space
$ sudo resize2fs LVName

You can now check to see if the total space is much larger
$ sudo df -hT

This should be all that you need, I did another
$ sudo partprobe
to verify that the system was aware of all the space.

I had some services crash and wouldn't start because of the lack of hard drive space, Apache2 and MySql5 wouldn't start.  After this process I was able to sudo service start and they both came up fine.

No comments:

Post a Comment