Repartition Disk and Expand File System on Amazon Linux 2 EC2 Instance – How to Guide

amazon-linux-2centos7diskmanagementfdisk

I have expanded the disk of my VM.
How do I now repartition the disk and expand the file system on the guest?
Which is Amazon Linux 2
Kernel 4.14.252-195.483.amzn2.x86_64 on an x86_64

$> sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 52G 0 disk
├─sda1 8:1 0 25G 0 part /
└─sda128 259:0 0 1M 0 part
sr0 11:0 1 1024M 0 rom

$> sudo fdisk -l
GPT PMBR size mismatch (52428799 != 109051903) will be corrected by w(rite).
Disk /dev/sda: 52 GiB, 55834574848 bytes, 109051904 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: gpt
Disk identifier: B5D4B016-37AF-4CFE-A37B-2B3B6F23154F

Device Start End Sectors Size Type
/dev/sda1 4096 52428766 52424671 25G Linux filesystem
/dev/sda128 2048 4095 2048 1M BIOS boot

Partition table entries are not in disk order.

sudo cfdisk (sorted) gives;

                            Disk: /dev/sda
                            Size: 52 GiB, 55834574848 bytes, 109051904 sectors
                            Label: gpt, identifier: B5D4B016-37AF-4CFE-A37B-2B3B6F23154F

Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 52428766 52424671 25G Linux filesystem
Free space 52428800 109051870 56623071 27G


Based on the cfdisk output I'm guessing that I need to

  1. create a new partition sda3 from the "Free Space"
  2. add sda1, sda2 and the new sda3 to the same LVM

Can someone confirm the steps and let me know how this can be done from the CLI it would be much appreciated?
Cheers
Chris

Best Answer

This shouldn't be a problem ... follow this procedure and you'll have it done!

https://repost.aws/knowledge-center/extend-linux-file-system

PLEASE!?! Do NOT skip the first step, where you take a snapshot of the volume BEFORE you start screwing around with data storage.