Expanding LVM to Full Capacity

Linux
2021-02-01 11:17 (4 years ago) ytyng

After building a PC and installing Ubuntu, I noticed that the logical partition in LVM was not utilizing the entire storage capacity, so I decided to extend it.

$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 16G 0 16G 0% /dev
tmpfs 3.2G 1.8M 3.2G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 196G 75G 112G 41% /

Even though I was using 1TB of storage, only a 196GB partition was created.

$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
...
nvme0n1 259:0 0 931.5G 0 disk
├─nvme0n1p1 259:1 0 1M 0 part
├─nvme0n1p2 259:2 0 1G 0 part /boot
└─nvme0n1p3 259:3 0 930.5G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 200G 0 lvm /

The physical partition is 930GB, but the logical partition is 200GB.

Use lvextend -l +100%FREE to extend it to the maximum capacity.

$ lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 200.00 GiB (51200 extents) to <930.51 GiB (238210 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
...
nvme0n1 259:0 0 931.5G 0 disk
├─nvme0n1p1 259:1 0 1M 0 part
├─nvme0n1p2 259:2 0 1G 0 part /boot
└─nvme0n1p3 259:3 0 930.5G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 930.5G 0 lvm /

It has been extended.

$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 16G 0 16G 0% /dev
tmpfs 3.2G 1.8M 3.2G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 196G 75G 112G 41% /

Since it has not yet been reflected in the file system, proceed with resize2fs.

$ sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
[sudo] password for xxxxx:
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 25, new_desc_blocks = 117
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 243927040 (4k) blocks long.

$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 16G 0 16G 0% /dev
tmpfs 3.2G 1.7M 3.2G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 915G 75G 802G 9% /
...

It has been extended.

Note: For Non-LVM Partitions

Memo for cases when extending EBS on EC2. For non-LVM partitions.

Case of extending EBS from 100GB to 200GB. Since it's not LVM, lvextend cannot be used. Instead, use growpart.

$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
...
nvme0n1     259:0    0  200G  0 disk
└─nvme0n1p1 259:1    0  100G  0 part /

$ sudo growpart /dev/nvme0n1 1
CHANGED: partition=1 start=16065 old: size=209699102 end=209715167 new: size=419414302 end=419430367

$ sudo resize2fs /dev/nvme0n1p1
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/nvme0n1p1 is mounted on /; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 13
The filesystem on /dev/nvme0n1p1 is now 52426787 (4k) blocks long.

$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
...
nvme0n1     259:0    0  200G  0 disk
└─nvme0n1p1 259:1    0  200G  0 part /
Current rating: 4.7
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Archive

2025
2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011