Redhat resize a LVM partition

This is a bit fiddly but I was in the following situation.

I had a bootable 4GB USB drive running Oracle Unbreakable Linux installation. It was installed on an LVM parition on the USB drive.

Now it came time to move this to an 8G drive which was achieved with the command

dd if=/dev/sda of=/dev/sdb conv=notrunc

Where the original 4G drive was /dev/sda and the replacement 8G drive was /dev/sdb.

All good so far. Now however how do I extend the LVM parition to use this new space. Here is where some hoop jumping comes in.

The basic steps are

  • Create a new LVM parition
  • Extend the volume to use this new parition as well
  • Extend the logical volume to use the new space
  • Now extend the filesystem to use the remainder of the space
  • Your done

Now for the steps required. You will want to boot from any Linux live CD
ie http://gparted.sourceforge.net/livecd.php

Here we go. Remember to take out your old USB stick and only have your new one in place

 

  • Boot to the Live CD and get to a terminal
  • fdisk /dev/sda
  • to see physical volumes with
    pvdisplay
  • to see volumes with
    vgdisplay
  • to see logical volumes with
    lvdisplay
  • create new patition for the remaining space on the drive
    fdisk /dev/sda
    p
    n
    t
    give it code 8e
    w
  • reload all partitions with – 
    partprobe
  • vgextend /dev/VGNameFromVgDisplayCommand /dev/sda3
  • Now extend the logical volume
    lvextend -l +100%FREE /dev/
    VGNameFromVgDisplayCommand/LVNameFromLvDisplayCommand

  • Now we need to extend the filesystem on the logical volume with the command
    e2fsck -f /dev/VGNameFromVgDisplayCommand/LVNameFromLvDisplayCommand
    resize2fs /dev/VGNameFromVgDisplayCommand/LVNameFromLvDisplayCommand
    e2fsck -f /dev/VGNameFromVgDisplayCommand/LVNameFromLvDisplayCommand

Ref: http://www.howtoforge.com/logical-volume-manager-how-can-i-extend-a-volume-group
Ref: http://www.linuxquestions.org/questions/linux-software-2/extend-lvm-partition-360056/

Tags: , , , ,

Leave a Reply