Root problem
I’ve been running Debian 12 for a while on my Linux desktop and recently ran into a big issue: My root volume ran out of space. Never good.
In the past I would’ve taken the path of least discomfort (for me): Clean install, repartition differently, start fresh. Because I’d used LVM when installing, however, I had another option this time:
On small systems (like a desktop), instead of having to estimate at installation time how big a partition might need to be, LVM allows filesystems to be easily resized as needed.
Wikipedia
Goal
I want to expand the root volume by shrinking the home volume a little bit. Let’s see how easy it really is with LVM!
Prerequisites
My environment was an x64 box running Debian 12 containing a single 1TB SSD. I didn’t add any physical drives, I only adjusted the space allotted to the LVM volumes.
Live image
I used a live install image to boot Linux without installing anything. After downloading the image I used dd
to copy it to a USB flash drive. When booting on Debian, you’ll need to select the “Rescue mode” and follow the menus to get to a shell. When asked about using a root filesystem, tell it not to mount anything.
Figure out paths and numbers
To make this tutorial generic, we’re going to define four variables. Two for the volume paths, one for the amount we’re going to grow the smaller volume, and one for the amount we’re going to shrink the bigger volume.
Paths
There are plenty of ways to figure out the paths to the volumes you’ll be using, but lvdisplay
works well.
shrinkPath
= path of volume to want to shrinkgrowPath
= path of volume to want to grow
Numbers
We’ll also need to define the growth amount of the growing volume and the new size of the shrinking volume.
growthAmount
= how much we want the volume at growPath
to grownewShrinkSize
= current size of the volume at shrinkPath
– growthAmount
Example
We have a root volume we want to grow by 30GB as well as a home volume (currently 900GB) that we need to shrink.
shrinkPath
= /dev/debian-vg/home
growPath
= /dev/debian-vg/root
growthAmount
= 30G
newShrinkSize
= 870G
(which is 900-30)
Note: Gigabyte units are assumed in this example, hence the G
after the 30 and 870.
Steps
⚠️ Complete these at your own risk! Any time you change filesystems you run the risk of data loss, so backup your stuff!
- Boot into a recovery mode without mounting any filesystems.
e2fsck -f {shrinkPath}
to check for errors.- Example:
e2fsck -f /dev/debian-vg/home
- Example:
resize2fs {shrinkPath} {newShrinkSize}
to shrink the filesystem.- Example:
resize2fs /dev/debian-vg/home 870G
- Important: Be sure to include the appropriate size unit after the new shrink size, like
G
for gigabytes. See theresize2fs
man page.
- Example:
lvreduce -L -{growthAmount} {shrinkPath}
to shrink the LVM volume.- Example:
lvreduce
-L -30G /dev/debian-vg/home - Note: Some tutorials accomplish steps 4 and 5 in one go via
lvreduce --resizefs
but this did not work for me, so I had to break it out into two steps. - Important: Be sure to include the appropriate size unit after the growth amount, like
G
for gigabytes. See thelvreduce
man page.
- Example:
resize2fs {shrinkPath}
to extend the partition to fit the volume.- Example:
resize2fs /dev/debian-vg/home
- Example:
vgdisplay -C
should show{growthAmount}
free.e2fsck -f {growPath}
to check for errors.- Example:
e2fsck -f /dev/debian-vg/root
- Example:
lvextend -l +100%FREE {growPath}
to grow the volume to 100% of the available Volume Group size.- Example:
lvextend -l +100%FREE /dev/debian-vg/root
- Example:
resize2fs {growPath}
to grow the filesystem to the available space.- Example:
resize2fs /dev/debian-vg/root
- Example:
vgdisplay -C
should show no free space- You should be all done and free to reboot!