Assuming that we have VMware VM with Ubuntu 20 on it and we need to extend partition on which it is installed.
Let’s login to this VM by ssh and check disk space on this partition bu running df -h:
root@va:/home/user# df -h
Filesystem Size Used Avail Use% Mounted on
udev 950M 0 950M 0% /dev
tmpfs 199M 812K 198M 1% /run
/dev/sda2 20G 7.9G 11G 43% /
tmpfs 994M 0 994M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 994M 0 994M 0% /sys/fs/cgroup
tmpfs 994M 0 994M 0% /run/shm
/usr/tmpDSK 994M 0 994M 0% /tmp
tmpfs 199M 0 199M 0% /run/user/1001
In this partition we have 20G.
Now let’s run command fdisk -l:
root@va:/home/user# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: Virtual disk
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: gpt
Disk identifier: F4E29267-1507-4625-9B78-C3536833769A
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 41940991 41936896 20G Linux filesystem
We have 2 partitions located on this disk.
Now let’s go to vSphere and extend this disk. You don’t need to shut down the VM for this operation.
Just open VM’s hardware settings and enter new size for the disk. In my case i specified 50 GB as new size.
Let’s reboot VM and check if Ubuntu got new disk size by running fdisk -l again:
root@va:/home/user# fdisk -l
GPT PMBR size mismatch (41943039 != 104857599) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: Virtual disk
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: gpt
Disk identifier: F4E29267-1507-4625-9B78-C3536833769A
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 41940991 41936896 20G Linux filesystem
Now size is 50 GB and it shows warning about size mismatch.
To increase partition size we need to remove information about partition and create new partition with new size and save it.
To do it you will need to run fdisk /dev/sda
:
root@va:/home/user# fdisk /dev/sda
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (41943039 != 104857599) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
After running fdisk you need to run command d and specify partition number (2 in my case).
Now we need to create new partition by running command n, entering default choices and running command w to save the changes:
Command (m for help): n
Partition number (2-128, default 2):
First sector (4096-104857566, default 4096):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (4096-104857566, default 104857566):
Created a new partition 2 of type 'Linux filesystem' and of size 50 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
Command (m for help): w
The partition table has been altered.
Syncing disks.
Now we need to reboot VM:
root@va:/home/user# reboot
But still Ubuntu will not see new space, we need to run resize2fs command to resize it:
root@va:/home/user# resize2fs /dev/sda2
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 7
The filesystem on /dev/sda2 is now 13106683 (4k) blocks long.
And now let’s check it by running df -h
and we will see that partition has new size 50GB:
root@va:/home/user# df -h
Filesystem Size Used Avail Use% Mounted on
udev 950M 0 950M 0% /dev
tmpfs 199M 812K 198M 1% /run
/dev/sda2 50G 7.9G 39G 17% /
tmpfs 994M 0 994M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 994M 0 994M 0% /sys/fs/cgroup
tmpfs 994M 0 994M 0% /run/shm
/usr/tmpDSK 994M 0 994M 0% /tmp
tmpfs 199M 0 199M 0% /run/user/1001