How To Extend GPT Drive on Ubuntu Server
How To Extend GPT Drive on Ubuntu Server
Recently ran into an issue with adding space to GPT RAW formatted disk on Ubuntu Server 22.04 LTS. The drive was not a standard LVM format. The steps below describe the process to extend the GPT drive.
Step By Step
Login to the server and become root. If you do not or cannot become root just add sudo in front of all the commands in the post.
Type sudo su –
Run the command fdisk -l to force a scan of the disk for the added space will see an error like below. If you do not get the error you may have to reboot the server.
Next we need to find where our root drive “/” lives. Run lsblk -fs
We see that ubuntu–vg-ubuntu–lv is the root partition on /dev/sda3 which has “/”
Update the GPT / MBR partition table using fdisk. I will use an emulated disk /dev/loop3 to demonstrate the whole process. Don’t worry, you won’t loss your data under normal circumstances. These commands will only modify the partition table, but make sure DO NOT remove the LVM’s signature, otherwise the system may no longer recognize your LVM PV.
Next update size by running fdisk /dev/sda
Next display the partitions type p
Partition 3 is the drive we are now going to delete. type d when prompted for the partition type 3
Now create a new partition. Type n and press enter to accept 3 for the partition.
You will get a warning that this is LVM2_member answer n.
Check to see if the partition looks good. Type p
Write the changes, type w
Next we need to inform the OS of partition table changes. Type partprobe
Next resize the physical volume. Type pvresize /dev/sda3
Check the physical volume and we see it knows about the size change. Type vgs
Next step is to extend the LVM to use all the free space. Type lvextend -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu—lv
Check the volume group and see no free space. type vgs
Next we need to resize the filesystem. Type resize2fs /dev/mapper/ubuntu–vg-ubuntu—lv
We are now complete, type df -h to see the new drive and size.
Leave a Reply