- Published on
Resizing an ext4 Partition in Ubuntu
- Authors
- Name
- Bryan Thode
A high level overview of the steps:
Recently I found an Ubuntu install I preformed had only allocated 100GB of a 1TB drive. Annoyed at either the installer or myself, I wanted to get it back.
1. Create a LiveCD
The Ubuntu install media can double as our LiveCD, and Etcher can write it to a thumb drive. Etcher supports Windows/MacOS/Linux, although Ubuntu's Startup Disk Creator can be used without requiring any 3rd party tools.
After you've booted into the LiveCD, ensure GParted is installed. If for some reason it's missing, use apt-get to install it.
2. Resize the Partition
Launching GParted, select the partition in question and resize it to fully utilize all available space. Be sure to "Apply All Operations", and once done you can boot back into your installed OS.
3. Resize the Logical Volume
Find the logical volume name. I only have one so it's rather obvious.
sudo vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz--n- 928.46g 0
We need to ensure there is available disk space to extend the logical volume.
sudo vgdisplay ubuntu-vg
--- Volume group ---
VG Name ubuntu-vg
...
VG Size 928.46 GiB
PE Size 4.00 MiB
Total PE 237686
Alloc PE / Size 25600 / 100.00 GiB
Free PE / Size 212086 / 828.46 GiB
VG UUID wPiQTr-NEDl-fZwd-j5xA-psey-MHce-EBaaia
There's my missing 826GB's.
Now lvs
can give us the logical volume path.
sudo lvs -o "lv_path,lv_dm_path"
Path DMPath
/dev/ubuntu-vg/ubuntu-lv /dev/mapper/ubuntu--vg-ubuntu--lv
With the DMPath /dev/mapper/ubuntu--vg-ubuntu--lv
being the value we need.
Now we can resize it. As I want to make use of all the space, I'm providing +100%FREE
.
sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Repeating the check from earlier, we should now see zero free space.
sudo vgdisplay ubuntu-vg
...
Alloc PE / Size 237686 / 928.46 GiB
Free PE / Size 0 / 0
...
4. Resize the Filesystem
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Finally let's verify the space.
df -h
/dev/mapper/ubuntu--vg-ubuntu--lv 914G 53G 824G 6% /
Success.