[Solved] Expand Ubuntu filesystem/partition after growing vdisk

Howdy. I have an Ubuntu Server (18.04) VM that I created quite a while ago. It’s running under vSphere 6.7. I initially created the vdisk to only be 60GB, not knowing how much I would need in the long run. I’m down to about 10% free so I’d like to expand the existing partition/file system.

I expanded the vdisk within vSphere to 100GB no problem. But I’m not familiar enough with the filesystem to understand what’s going on. I followed a guide I found on using fdisk but that didn’t work, as the partition wasn’t usable after.

This is the output of df -h, I don’t understand what the /dev/mapper/hera--vg-root is. (Hera is the hostname).

Filesystem                 Size  Used Avail Use% Mounted on
udev                       5.9G     0  5.9G   0% /dev
tmpfs                      1.2G  824K  1.2G   1% /run
/dev/mapper/hera--vg-root   58G   48G  7.3G  87% /
tmpfs                      5.9G     0  5.9G   0% /dev/shm
tmpfs                      5.0M     0  5.0M   0% /run/lock
tmpfs                      5.9G     0  5.9G   0% /sys/fs/cgroup
/dev/sda1                  470M  135M  311M  31% /boot
tmpfs                      1.2G     0  1.2G   0% /run/user/1000

Output of lsblk:

NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                   8:0    0  100G  0 disk
├─sda1                8:1    0  487M  0 part /boot
├─sda2                8:2    0    1K  0 part
└─sda5                8:5    0 59.5G  0 part
  ├─hera--vg-root   253:0    0 58.6G  0 lvm  /
  └─hera--vg-swap_1 253:1    0  976M  0 lvm  [SWAP]
sr0                  11:0    1 1024M  0 rom

So I want to expand the 58G partition to use the rest of the (now) 100GB vdisk.

Can someone point me in the right direction, please? I’m happy to add any additional details.

Thanks!

Use GParted ?

2 Likes

After you expanded the virtual “physical” disk for your vm, there are two layers of software that need to be adjusted.
First the partition holding your data needs to be expanded, a low level tool of fdisk could do that.
Then the file system needs to be expanded to take advantage of that newly available space. In your case this has two layers by itself: LVM and the file system on top.

I’m just explaining this so that you know why you were not successful, yet. I’d say don’t bother with the low level stuff and follow the advise from @Cizin : use the graphical tool “gparted” that will take care of this for you.
Install it in your vm and on opening you should find a disk that leaves space to expand a partition. Drag the existing partition to fill the space, let gparted do the rest.

2 Likes

Or …

resize drive to maximum capacity using parted

parted /dev/sda
type following commands into parted
list (shows you which partitions are used)
resizepart 5 80G (number 5 was my partition can be different for you)

then exit parted and type following as root (do sudo su if you don't know how to root)

pvresize /dev/sda5
lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
df -H
2 Likes

thanks for the great information everyone. i booted into a live CD to get to GParted, ran it to extend the partition. but got some weird results:

Filesystem                 Size  Used Avail Use% Mounted on
udev                       5.9G     0  5.9G   0% /dev
tmpfs                      1.2G  828K  1.2G   1% /run
/dev/mapper/hera--vg-root   58G   48G  7.0G  88% /
tmpfs                      5.9G     0  5.9G   0% /dev/shm
tmpfs                      5.0M     0  5.0M   0% /run/lock
tmpfs                      5.9G     0  5.9G   0% /sys/fs/cgroup
/dev/sda1                  470M  135M  311M  31% /boot
tmpfs                      1.2G     0  1.2G   0% /run/user/1000

So still at the original size. But the disk shows 200GB now:

root@hera:/# fdisk -l
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 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
Disklabel type: dos
Disk identifier: 0x42976d9f

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sda1  *       2048    999423    997376   487M 83 Linux
/dev/sda2       1001470 419430399 418428930 199.5G  5 Extended
/dev/sda5       1001472 419428351 418426880 199.5G 8e Linux LVM

So I took the second half of what @MadMatt said and that got it working:

root@hera:/# df -h
Filesystem                 Size  Used Avail Use% Mounted on
udev                       5.9G     0  5.9G   0% /dev
tmpfs                      1.2G  828K  1.2G   1% /run
/dev/mapper/hera--vg-root  196G   48G  140G  26% /
tmpfs                      5.9G     0  5.9G   0% /dev/shm
tmpfs                      5.0M     0  5.0M   0% /run/lock
tmpfs                      5.9G     0  5.9G   0% /sys/fs/cgroup
/dev/sda1                  470M  135M  311M  31% /boot
tmpfs                      1.2G     0  1.2G   0% /run/user/1000

I’m not sure if I did something wrong in GParted but it’s working now. Thanks everyone!

1 Like