Howto extend a ext3 filesystem in RHEL5

In RHEL5 ext2online is no longer available. However, do not despair – you can still grow your ext3 filesystems while online: The functionality has been included in resize2fs so to resize a logical volume, start by extending the volume:

# lvextend -L +2G /dev/systemvg/homelv

And the resize the filesystem:

# resize2fs /dev/systemvg/homelv (by omitting the size argument resize2fs defaults to using the available space in the partition/lv)

3 Comments

  1. Terry Polzin says:

    You solution presumes the ext3 fs resides on a LVM pv and lv. What does one do in the case of a pure ext3 fs say an extended LUN presented from a SAN?

  2. frank says:

    @Terry:
    First scan for the new LUN:

    # echo “- – -” > /sys/class/scsi_host/hostX/scan (where X is your HBA’s ID)

    Check for the device name at the end of dmesg

    # dmesg

    Format the disk using fdisk and choose the partition type “8e” – Linux LVM)
    Then add device to LVM:

    # pvcreate /dev/sdX1 (sdX1 is the partition you created above)

    Add the the PV to the relevant Volume Group:

    # vgextend VGName /dev/sdX1

    And then it’s pretty much just to follow the instructions above

  3. frank says:

    @Terry: Ah, I misread your question. If There’s no LVM involved you can still extend the filesystem. I haven’t thoroughly tested this procedure though, as I always use LVM (IMHO it makes life a whole lot easier). Anyways – here goes:

    1. Expand the device (LUN, vmdk, whatever)
    1a. Make the server aware of the new size:

    If you can’t resize online (e.g. VMware Workstation vmdk files) – no problem the boot will take care of this
    If you resize online (e.g. SAN LUN or VMware ESX vmdk) – issue a

    # echo 1 > /sys/block/sdX/device/rescan

    If you use multipath you may have to do some multipath magic – but I admit this is not my strongest area. In other words: You are on your own :-)

    2. Unmount the disk

    # umount /dev/sdXN

    3. Run a fsck on the partition

    # e2fsck -f /dev/sdXN

    4. Use fdisk (cfdisk and parted may work as well) to delete the current partition and create a new one spanning the entire device

    # fdisk /dev/sdX (“d->1->w” – if fdisk automatically chooses “partition 1”, you only need to do “d->w”)
    # fdisk /dev/sdX (“n->p->1->Return->Return->w”)

    5. Run another fsck

    # e2fsck -f /dev/sdXN

    6. expand the filesystem

    # resize2fs /dev/sdXN

    7. Mount the device – and Voila!

    # mount /dev/sdXN /somemountpoint

    or if it’s listed in /etc/fstab

    # mount -a

    DISCLAIMER: I have only done this procedure on virtual machines running VMware – and I have never done it in a production environment; I’m not entirely sure I would have the guts to do so :-)

Leave a Reply