How to Expand LVM2 Partition in Fedora Linux
Solution 1
Create an extended partition spanning the new free space, and create a logical partition inside it. (You could create a primary partition, but that would reduce your options later, because of the limit of 4 primary partitions or 3 primary and one extended.) You can do this with
fdisk
orcfdisk
orparted
. Set the type of the new partition to 8e (“Linux LVM”).-
Create a new LVM physical volume in that new partition.
pvcreate /dev/sda5
-
Add the new physical volume to your volume group.
vgextend VolGroup /dev/sda5
-
Extend the logical volume containing the filesystem you want to extend.
lvextend -l +100%FREE VolGroup/name_of_logical_volume
Extend the filesystem inside the volume. Use the command designed for that filesystem, e.g.
resize2fs
.
Instead of steps 1–3, you can extend the existing sda2
partition with Parted, then call pvresize /dev/sda2
to enlarge the existing physical volume. This may make management slightly easier afterwards, but it's more error-prone.
Solution 2
Gilles answer was great, but it wasn't detailed enough for newbies.
Thus, I will attempt to describe everything in details.
Scenario: You want to increase the size of your Fedora virtual machine in VMware. VMware is probably installed on Windows, the host system but this is not important.
-
In the Fedora VM, find out the names of the partitions. You execute
sudo fdisk -l
and look for the section as below. You can see that/dev/sda2
is the partition that needs to be increased.
Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 52428799 25701376 8e Linux LVM
I prefer using GParted
to visually see the partitions. This is nicer for people new to Linux. If you want to install Gparted, sudo yum install gparted
and launch the GUI application from the application list.
- As you can see under System in the table above,
/dev/sda2
is of the type LVM (Logical Volume Manager). Under LVM, the partitions are categorised by VolumeGroup/VolumeName. Let's find out the VolumeGroup/VolumeName for/dev/sda2
One way of doing that is executingdf -h
and looking at the/dev/mapper/VolGroup-VolName
pattern.
Example: .
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora-root 24G 16G 6.6G 71% /
devtmpfs 1.5G 0 1.5G 0% /dev
tmpfs 1.5G 140K 1.5G 1% /dev/shm
Here, /dev/mapper/fedora-root
corresponds to /dev/sda2
by checking the disk sizes. Unfortunately, this requires paying some attention to the details as there is not straight-forward way of doing that.
Thus, the VolumeGroup of /dev/sda2
is fedora
and the VolumeName is root
.
Note these information on paper.
- Shutdown the Fedora VM and download GParted Live ISO from (http://gparted.org/download.php) from the host system. In the VM settings, increase the size of the disk (Settings>Harddisks>Utilities>Expand)
- Still in the settings, connect the Gparted ISO file as CD/DVD drive. Boot into Gparted live (you will probably have to modify the BIOS settings of the VMmachine to boot into the ISO file)
Once you boot into Gparted, resize
/dev/sda2
by right-clicking on the/dev/sda2
partition (should be pale yellow) and clicking Resize/Move. Increase New Size (MiB) until Free space following (MiB) is 0 (or drag the slider completely to the right). Apple the changes.Reboot in Fedora and excute the following:
sudo lvextend -l +100%FREE fedora/root
Recall, the pattern of the above command islvextend -l +100%FREE VolGroup/VolName
. If your VolGroup and VolName from step 2 were different, you will have to change accordingly.Execute
sudo resize2fs /dev/fedora/root
. Again the template isresize2fs /dev/VolGroup/VolName
.Lastly, execute
df -h
to see the changes.
Related videos on Youtube
sj755
Updated on September 18, 2022Comments
-
sj755 over 1 year
I've been using Fedora 15 on a VMWare virtual machine. Over time, the disk space I initially allocated for the file system began to run out, only 12GB left. I've expanded the disk space an extra 25GB.
Problem is, I need to expand the file system to take what is now 25GB of free space on the virtual disk.
I tried GParted, but it doesn't support LVM2. Does anyone know of any utilities or the commands needed to expand my filesystem?
Disk info: ![Logical Volume Group][1]
![Hard Disk][2]
![GParted][3]
Just tried this command:
[root@localhost /]# lvextend -L+10G /dev/VolGroup/lv_root Extending logical volume lv_root to 54.38 GiB Insufficient free space: 320 extents needed, but only 0 available
Obviously it didn't work. How do I get at that unallocated disk space?
-
psusi about 12 yearsYou want to expand the existing pv, not make a new one on another partition, and parted doesn't resize filesystems, just partitions ( it used to be able to resize hfs, fat and ext2, but that support was removed in parted 3 since it had been rotting for years ).
-
sj755 about 12 yearsHow do I add give my new partition the 0x8E flag? See update.
-
Gilles 'SO- stop being evil' about 12 years@seljuq70 You still need to create a logical partition on the extended partition (with
fdisk
, use then
command and selectl
for logical, and use all the available space; then use thet
command to set the type of the newly created logical partition). -
Gilles 'SO- stop being evil' about 12 years@seljuq70 Once you have one big logical volume, the last step is to make the filesystem use all of it. If the filesystem is ext2/ext3/ext4, call
resize2fs /dev/VolGroup/name_of_logical_volume
, and the filesystem will be extended to occupy the whole volume that contains it (i.e. the LVM logical volume). -
Shailen over 9 yearsWell, I'm glad I wrote this answer down here. I just come back here gain to refer to these notes now that I have to expand my Fedora VM :) I hope this helps many people out there.
-
D-rk almost 6 yearsstep 5 can be skipped if you provide
-r
parameter tolvextend
in step 4 -
Victor Ian over 4 yearsWorks perfectly with my setup - Fedora 31 on VMWare, thank you for writing this. IMO this should be the correct answer.