Resize AWS EC2 volume
This post will show how to let your ubuntu recognized a new volume size.
- Check current space
df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 788M 1.3M 787M 1% /run
/dev/nvme0n1p1 31G 27G 4.3G 87% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/loop2 18M 18M 0 100% /snap/amazon-ssm-agent/1455
tmpfs 788M 0 788M 0% /run/user/1000
/dev/loop1 18M 18M 0 100% /snap/amazon-ssm-agent/1480
/dev/loop3 90M 90M 0 100% /snap/core/8213
/dev/loop0 90M 90M 0 100% /snap/core/8268
The current size is 31GB
mounted at /dev/nvme0n1p1
.
- (Optional) Check partition:
sudo file -s /dev/nvme?n*
/dev/nvme0n1: DOS/MBR boot sector
/dev/nvme0n1p1: Linux rev 1.0 ext4 filesystem data, UUID=77065d09-78c6-41b4-b46a-b83c9519561c, volume name "cloudimg-rootfs" (needs journal recovery) (extents) (64bit) (large files) (huge files)
- Check current block partition status
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 89.1M 1 loop /snap/core/8268
loop1 7:1 0 18M 1 loop /snap/amazon-ssm-agent/1480
loop2 7:2 0 18M 1 loop /snap/amazon-ssm-agent/1455
loop3 7:3 0 89.1M 1 loop /snap/core/8213
nvme0n1 259:0 0 128G 0 disk
└─nvme0n1p1 259:1 0 32G 0 part /
Device nvme0n1
has 128GB, 32G
of it is assigned to the first (number 1
) partition, named nvme0n1p1
. Now, we will extend this partition.
- Extend the first (
1
) partition of the devicesudo growpart /dev/nvme0n1 1
(notice the number1
at the end of the command). - (Optional) Confirm the extend
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 89.1M 1 loop /snap/core/8268
loop1 7:1 0 18M 1 loop /snap/amazon-ssm-agent/1480
loop2 7:2 0 18M 1 loop /snap/amazon-ssm-agent/1455
loop3 7:3 0 89.1M 1 loop /snap/core/8213
nvme0n1 259:0 0 128G 0 disk
└─nvme0n1p1 259:1 0 128G 0 part /
Now, nvme0n1p1
becomes 128G
, instead of 32G
before the previous command.
- (Optional) Check the file system size
df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 788M 1.3M 787M 1% /run
/dev/nvme0n1p1 31G 27G 4.3G 87% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/loop2 18M 18M 0 100% /snap/amazon-ssm-agent/1455
tmpfs 788M 0 788M 0% /run/user/1000
/dev/loop1 18M 18M 0 100% /snap/amazon-ssm-agent/1480
/dev/loop3 90M 90M 0 100% /snap/core/8213
/dev/loop0 90M 90M 0 100% /snap/core/8268
/dev/nvme0n1p1
's size is still 31G
. In order to make the extended partitioning take effect do the following command
- Resize logical volume size
sudo resize2fs /dev/nvme0n1p1
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/nvme0n1p1 is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 16
The filesystem on /dev/nvme0n1p1 is now 33554171 (4k) blocks long.
- Confirm the result
df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 788M 1.3M 787M 1% /run
/dev/nvme0n1p1 125G 27G 98G 22% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/loop2 18M 18M 0 100% /snap/amazon-ssm-agent/1455
tmpfs 788M 0 788M 0% /run/user/1000
/dev/loop1 18M 18M 0 100% /snap/amazon-ssm-agent/1480
/dev/loop3 90M 90M 0 100% /snap/core/8213
/dev/loop0 90M 90M 0 100% /snap/core/8268
Happy Coding!