FedoraForum.org - Fedora Support Forums and Community
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2004
    Location
    London, UK
    Posts
    4,999

    How To extend root / partition 'on-the-fly', ext3/LVM only

    This turned out to be easier than expected, so I'm posting this short how-to. The restriction to ext3 is due to the man page for resize2fs claiming this is the only fs that can be resized without unmounting.

    The scenario: you have an ext3 partition LogVol00 mounted on / and a swap partition LogVol01 in a logical volume group VolGroup00 (the default install), but you're running out of space in /, there's no room left in the volume group but you have a brand new disk drive with lots of free space. How to add some space to the / partition?

    The usual problem is that / can't be unmounted, there are guides out there which involve using a livecd or dual booting into another os that recognizes logical volumes, but in this case you can do it 'on-the-fly' in Fedora.

    WARNING: If you have important data in any directory under / then backup before attempting this.

    I'll assume the spare disk is called /dev/sdb

    1. Create a new partition of appropriate size using fdisk
    Code:
    fdisk /dev/sdb
    n   (create new partition, select start and end cylinders, all free space is selected by default)
    w  (save partition table and exit)
    At this point you may be told that a reboot is necessary, I found it was unnecessary, but for safety you should probably reboot. Type fdisk -l again to check the new partition, I'll assume /dev/sdb1 was created ~10G in size

    2. Create an ext3 filesystem in the partition (this step is optional, just a quick test that all is well)
    Code:
    mkfs.ext3 /dev/sdb1
    3. Initialise the partition for use as a physical volume in lvm and add it to VolGroup00
    Code:
    pvcreate /dev/sdb1
    vgextend VolGroup00 /dev/sdb1
    4. Extend LogVol00 (use 'df /' to check that / is mounted on LogVol00) as required (by 10G here)
    Code:
    lvextend -L +10G /dev/VolGroup00/LogVol00
    If you receive errors about not enough physical extents, then reduce the size of the extension a little until it fits.

    5. Finally, resize the filesystem (this part normally would require unmounting /, but for ext3 and 2.6 Kernels it works while the partition is mounted)
    Code:
    resize2fs /dev/VolGroup00/LogVol00
    Type 'df -h /', to check it worked, there should be an extra 10G available
    (you can use vgdisplay, pvdisplay and lvdisplay (as root) to see detailed info, pvscan for a summary)



    Note.
    I've seen horror stories with lvm manipulation whereby an 'unknown uuid' error occurs for a partition, and the VolGroup can no longer be found, which prevents booting. This can be due to using e2label, mkfs etc on the partition after it has been initialised as a pv and added to the group. The error is fixable if you haven't rebooted: you need to edit /etc/lvm/backup/VolGroup00 and delete the lines referring to the unrecognized partition (they'll be a few between braces {}, the unknown uuid will be at the beginning, something like:

    Code:
     pv1 {
                            id = "gAMCGW-jdaH-VXse-HR2j-PA24-AIbb-aHMjKl"
                            device = "/dev/sdb1"   # Hint only
    
                            status = ["ALLOCATABLE"]
                            dev_size = 20482812     # 9.76697 Gigabytes
                            pe_start = 384
                            pe_count = 312  # 9.75 Gigabytes
                    }
    Remove all these lines, save the file, then run
    Code:
    vgcfgrestore -f /etc/lvm/backup/VolGroup00 VolGroup00
    vgscan
    vgscan should report all is ok (you can now try reinitialising the 'bad' partition using pvcreate, and then add it back to the VolGroup with vgextend)
    Last edited by sideways; 9th May 2007 at 10:32 PM.

  2. #2
    Join Date
    Mar 2006
    Posts
    11
    thanks for the howto, sideways. worked perfectly for adding a 300GB drive to my existing partition of a single 500GB drive in my mythtv box (i set up the LVM during setup as a partition for all of my media related recordings and videos, knowing that i was going to expand it eventually). I think I found a typo though- right after using fdisk and making the filesystem, mkf2s.ext3 didnt work for me; but mkfs.ext3 did. maybe you confused that command with resize2fs? anyway, great how-to nonetheless!

  3. #3
    Join Date
    Oct 2004
    Location
    London, UK
    Posts
    4,999
    Quote Originally Posted by option
    thanks for the howto, sideways. worked perfectly for adding a 300GB drive to my existing partition of a single 500GB drive in my mythtv box (i set up the LVM during setup as a partition for all of my media related recordings and videos, knowing that i was going to expand it eventually). I think I found a typo though- right after using fdisk and making the filesystem, mkf2s.ext3 didnt work for me; but mkfs.ext3 did. maybe you confused that command with resize2fs? anyway, great how-to nonetheless!
    oops, absolutely right, I edited to correct the typo. ( That section is skippable though )

    Glad it worked for you, I wasn't a fan of lvm, but I had this machine in need of space and was surprisingly impressed how easy this was to do.

    A thumbs up for lvm

  4. #4
    Hobb3s Guest
    Thanks for this! I was just looking how to do this exactly. Worked great. I appreciate your help!

  5. #5
    Join Date
    Jan 2005
    Posts
    5,059
    Are you sure step 2. is needed for an extend.
    I always thoht the pv had to be created first, and the formating is on the lv level.

    The extend operation, I think, just formated the new partition area again.

    EDIT: actually, step 5 formatted the extended lv area.
    SJ
    Last edited by SlowJet; 1st August 2007 at 06:55 PM. Reason: actually, step 5 formatted the extended lv area.
    Do the Math

  6. #6
    Join Date
    Jul 2008
    Posts
    378

    Re: How To extend root / partition 'on-the-fly', ext3/LVM only

    "Online resizing of ext4 works in a similar manner as ext3, using either resize2fs or ext2resize"

    https://ext4.wiki.kernel.org/index.p..._filesystem.3F

  7. #7
    Join Date
    Jul 2009
    Location
    London,England
    Posts
    1,103

    Re: How To extend root / partition 'on-the-fly', ext3/LVM only

    Yes, these instructions still work in latest fedoras with ext4, but the logical volume naming has slightly changed, also I would recommend installing gparted ('yum install gparted') to create the initial ext4 partition.

    I decided to delete the 10G recovery partition /dev/sda2 (which I never use) on a dell laptop, convert it to ext4 and add it to my root partition in F14:

    1. I used gparted to create the ext4 partition in /dev/sda2 (I deleted the fat32 filesystem first)

    2. I used lvscan to find the name of the active volume group and logical volume (this may also include a swap partition, which you can ignore, I don't put swap in an lvm group because I dual boot with Ubuntu and want to share the swap partition)

    Code:
    $ su -
    # lvscan
      ACTIVE            '/dev/VolGroup/LogVol00' [17.34 GiB] inherit
    Now extend the filesystem into the 10G partition

    Code:
    # pvcreate /dev/sda2
    # vgextend VolGroup /dev/sda2
    # lvextend -L +10G /dev/VolGroup/LogVol00
    (gives error not enough physical extents)
     
    # sudo lvextend -L +9.99G /dev/VolGroup/LogVol00 
    # resize2fs /dev/VolGroup/LogVol00 
    #  df -h /
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/VolGroup-LogVol00
                           27G   15G   13G  54% /
    
    # lvscan
      ACTIVE            '/dev/VolGroup/LogVol00' [27.33 GiB] inherit
    (Note that the /dev/sda2 partition wasn't quite 10G, so I had to extend by 9.99G)

    This took just a few minutes. You don't have to create the ext4 filesystem in step 1, but I prefer to do this as it will report any potential problems.

  8. #8
    Join Date
    Mar 2012
    Location
    Austin, TX
    Posts
    1

    Re: How To extend root / partition 'on-the-fly', ext3/LVM only

    An easy way to utilize the entire space instead of guessing is to look at output from the vgdisplay command.

    Here is an example. Look at the 1st column from Free PE / Size. Use that in your lvextend.
    Code:
    lvm> vgdisplay VolGroup01
      --- Volume group ---
      VG Name               VolGroup01
      System ID             
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                1
      Open LV               1
      Max PV                0
      Cur PV                2
      Act PV                2
      VG Size               3.82 TB
      PE Size               32.00 MB
      Total PE              125042
      Alloc PE / Size       85201 / 2.60 TB
      Free  PE / Size       39841 / 1.22 TB
      VG UUID               WEdh4a-kUiH-8Xzx-gMfd-1J88-RxVI-hf85uZ
       
    lvm> 
    
    lvm> lvextend -l+39841 /dev/VolGroup01/lvol0
      Extending logical volume lvol0 to 3.82 TB
      Logical volume lvol0 successfully resized
    lvm>


    Quote Originally Posted by Gödel
    (Note that the /dev/sda2 partition wasn't quite 10G, so I had to extend by 9.99G)

    This took just a few minutes. You don't have to create the ext4 filesystem in step 1, but I prefer to do this as it will report any potential problems.

  9. #9
    Join Date
    Nov 2016
    Location
    Sydney, AU
    Posts
    1

    Re: How To extend root / partition 'on-the-fly', ext3/LVM only

    Note that on new Fedora and Centos releases the default is XFS rather than ext3 or ext4.

    So instead of resize2fs you can use fsam resize /dev/vg_group/lv

    For example on my machine it was

    fsam resize /dev/fedora_octavo/root

Similar Threads

  1. I need to extend my partition... I think.
    By quantumburnz in forum Using Fedora
    Replies: 4
    Last Post: 21st September 2008, 05:55 PM
  2. How To extend an ext3 fs located in an LVM.
    By highc in forum Guides & Solutions (Not For Questions)
    Replies: 0
    Last Post: 23rd October 2005, 02:11 PM
  3. Replies: 6
    Last Post: 27th June 2005, 02:15 PM
  4. Resizing EXT3 root partition safe?
    By alphonsebrown in forum Using Fedora
    Replies: 7
    Last Post: 4th April 2005, 03:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •