Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 6 down vote accepted
  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 or cfdisk or parted. Set the type of the new partition to 8e (“Linux LVM”).

  2. Create a new LVM physical volume in that new partition.

    pvcreate /dev/sda5
    
  3. Add the new physical volume to your volume group.

    vgextend VolGroup /dev/sda5
    
  4. Extend the logical volume containing the filesystem you want to extend.

    lvextend -l +100%FREE VolGroup/name_of_logical_volume
    
  5. 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.

share|improve this answer
    
You 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 ). –  psusi Feb 20 '12 at 2:18
    
How do I add give my new partition the 0x8E flag? See update. –  sj755 Feb 20 '12 at 2:34
1  
@seljuq70 You still need to create a logical partition on the extended partition (with fdisk, use the n command and select l for logical, and use all the available space; then use the t command to set the type of the newly created logical partition). –  Gilles Feb 20 '12 at 2:42
    
Could you elaborate on that last part, about resize2fs. I managed to unify the logical volumes, but physical volumes are still separate. –  sj755 Feb 20 '12 at 3:01
2  
@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). –  Gilles Feb 20 '12 at 3:06

You're using LVM, the logical volume manager. This gives you a lot more flexibility than you would get with simple partitions, but you need to understand how everything fits together. I would start first at the LVM page on Wikipedia, paying special attention to the diagram that shows all the parts.

LVM is a stack, with your physical block devices -- usually disks or disk partitions -- at the bottom, and logical volumes at the top. Your root filesystem is on a logical volume, and you have increased the size of the underlying physical block device. There are some intermediate steps you need to take:

  • Because you're using disk partitions instead of whole disks, your new space is effectively "invisible" to Linux, because the existing partition for /dev/sda2 stops at the boundary of the disk prior to adding the new space. So you'll first have to extend the partition.

  • Now that you've extended the partition, you need to make the LVM subsystem aware of the additional space. Run pvresize /dev/sda2. This will allocate the additional space to the physical volume, making it available to your VolGroup volume group.

  • Now that the volume group has additional space, you can run our lvextend or lvresize command to grow the logical volume and extend the filesystem.

Read the LVM HOWTO for more information.

share|improve this answer

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 disk in VMware and you have Fedora installed.

  1. 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.

  1. 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 executing df -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.

  1. 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)
  2. 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)
  3. Once you boot into Gparted, merge /dev/sda2 and the free space you just created in step 3 and apply the changes.

  4. Reboot in Fedora and excute the following: sudo lvextend -l +100%FREE fedora/root Recall, the pattern of the above command is lvextend -l +100%FREE VolGroup/VolName. If your VolGroup and VolName from step 2 were different, you will have to change accordingly.

  5. Execute sudo resize2fs /dev/fedora/root. Again the template is resize2fs /dev/VolGroup/VolName.

  6. Lastly, execute df -h to see the changes.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.