Is it possible to extend a ubuntu 12.04 disk in vmware?

10,672

If you are willing to risk your live data, you can edit the partition table online with fdisk. However, as you have more than one partition, you need to first delete your second partition to get it out of the way. Once this is done, you can resize the original partition, reboot, resize the filesystem, reboot again, and then have more space. A quick example would look like this (everything must be done as root, use sudo -i to get a root terminal):

Step 0: BACK UP ALL YOUR DATA. This is very risky. If you don't know what you're doing you will probably destroy all your data. Continue at your own risk.

Step 1: unmount your second partition, which appears to be just swap

swapoff /dev/sda5

Step 2: Modify the partition table, deleting the swap and extended partition

fdisk /dev/sda
d
5
d
2
w

Step 3: Find which block your first partition starts on, this needs to be exact

fdisk -l /dev/sda

Output looks like:

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003301e

   Device Boot      Start         End      Blocks   Id  System
  /dev/sda1   *        2048    39845887    19921920   83  Linux

Step 4: Delete and recreate your primary partition

fdisk /dev/sda
d
1
n
p
1
2048
[however large you want the filesystem to be]
w

Step 5: Recreate your swap partition

fdisk /dev/sda
n
p
2
[default option, beginning of free space]
[default option, end of free space]
t
2
82
w

Step 6: Reboot. Your server might not come back online. You may have ruined everything. This is why you took that backup.

Step 7: Resize the filesystem. For ext2/3/4, use resize2fs.

resize2fs /dev/sda1

Step 8: Reboot again.

After the last reboot, you should have all the space you added. You will need to edit your fstab to update the UUID on the swap partition.

Share:
10,672

Related videos on Youtube

Scott
Author by

Scott

Updated on September 18, 2022

Comments

  • Scott
    Scott over 1 year

    I am trying to extend the disk on a Ubuntu server running as a vmware esxi guest. I have extended the disk in the settings of the guest in esx. How do I go about extending the disk to allow more free space for the os/user data? I have been searching for the answer on this and have read many posts, but none seem to address my actual needs. I am pretty new to linux/ubuntu but am catching on, so please dont beat me up too badly here. Thanks.

  • Scott
    Scott over 11 years
    Thanks for the link. I had already tried that one. When I extend my disk, it shows up in gparted as /dev/sda2 with a file system of extended. Under that are file systems of unallocated and linux-swap. When I highlight /dev/sda and then click on resize/move, I am only shown the space on /dev/sda which is already 100% used.