Partition Manipulation (LVM … yum.)

A while back I faced a difficult issue concerning a full partition that needed to be expanded – logical volume management was in use but there was no extra physical disk space to be partitioned. Here’s what I did… The solution/information below pertains to a CentOS/Redhack EL box. Release 4 or higher. BACK UP YOUR DATA! :-)

Real World Problem:
Server "foo" has 50KB free on /home and has no additional disks to grow to. This server has all slots full and is running RAID5.

Real World Solution:
Copy the partition to another new disk (or disk array) pop into cfdisk, create a new partition on the extra free space, grow the logical volume. Resize with ext2online. Here’s a step-by-step:

  1. Use DD or whatever disk imaging to copy the disk to the new disk
  2. Boot from the new disk
  3. Download the CFDisk RPM
  4. Download ncurses-4 and ncurses-5
  5. Install above mentioned RPM’s
    (rpm -ivh cfdisk-glibc-0.8g-1.i386.rpm; rpm –force -ivh ncurses4-5.0-12.i386.rpm; rpm –force -ivh ncurses-devel-5.4-13.i386.rpm)
  6. Run cfdisk /dev/device (probably /dev/sda or sdb .. you should know the device!)
  7. Create new partition and write changes – reboot.
  8. Create pv (pvcreate /dev/sda6) this creates the pv on sda6
  9. Add pv to volume group (vgextend VolGroup00 /dev/sda6) this
  10. vgdisplay will show volume group’s total size, now we can extend our lv
  11. Unmount the mount being used (in our case it was /home) umount /home
  12. lvextend -L+100GB /dev/mapper/VolGroup00/LogVol00-Home – This extends the current lv by 100GB
  13. Mount the partition back to it’s mountpoint (as specified in fstab) mount /home
  14. Use ext2online to grow the partition to it’s full size – yes, while it’s mounted! (ext2online /home &)
    "df -h" will show the partition growing before your eyes!
  15. Enjoy a cool beverage.

The reason for using CFDisk and not FDISK is because fdisk will not recognize the disk size change because DD copies everything – all structures – cfdisk is the only utility (at least that I found) that can resize in this type of situation.

Leave a Reply

Your email address will not be published / Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.