Is it possible to do so with above partition? I read somewhere resize2fs can extend the root partition automatically with unallocated space for lvm partition. Is it possible without losing data?
Yes and yes. The resize2fs
part doesn't need much explanation, but let me provide a concrete recipe for the LVM part.
LVM works like this: partitions are turned into physical volumes (PV), which are then grouped into volume groups (VG), which can then be partitioned into logical volumes (LV). The latter get formatted and are used just like DOS partitions are.
Right now, you have a partition /dev/sda11 which holds one physical volume, which is grouped into one volume group (called "fedora"), on top of which you seem to have at least two logical volumes ("root" and "home").
All you need to do is:
- add another physical volume;
- extend your volume group with this new volume;
- extend your "root" logical volume to use the space;
- resize the filesystem in the "root" LV.
CAUTION! Root partition is one of those things that shouldn't be messed with while the system is running. Boot from a LiveUSB and perform all operations from there. SystemRescueCD is a good option, but you can use anything as long as it has parted
(or equivalent), lvm2
, e2fsck
and resize2fs
.
First, turn your unallocated 20 gigs into a partition. You seem to have GParted or something; do it there, it's intuitive and easy. I'll assume the resulting partition is called /dev/sda12
.
Now create a PV on top of that partition:
# pvcreate /dev/sda12
That's step one done. Now on to step two:
# vgextend fedora /dev/sda12
(note how PVs don't have their own names—they're named after the partitions they reside on. But VGs have their own names; I found out how yours is called from the GParted screenshot and the name of the /dev/mapper
entries.)
With volume group ready, it's time to execute step three. This will resize the "root" LV on "fedora" VG to use all the available space. You can use -L
to specify a concrete size (in megabytes, gigabytes etc.) instead.
# lvextend -l+100%FREE /dev/fedora/root
Finally, resize the partition to actually use all that free space:
# e2fsck -f /dev/fedora/root
# resize2fs /dev/fedora/root
# e2fsck -f /dev/fedora/root
e2fsck
ensures your filesystem isn't corrupted to begin with, and it's not corrupted afterwards. You can omit the second invocation, but the first one is essential—I believe resize2fs
won't run unless you have your filesystem checked.
Best Answer
LVM is great, but it works best when you have a lot of free space, and you can create small logical volumes that can grow as needed.
Your suggested layout would probably be fine, but I would make a separate /boot partition as well. (You could also make your swap partition smaller. You never want to be more than a couple of GB into swap since performance suffers badly past that. Plus you can always add a swap file if you absolutely have to.)