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:
- Use DD or whatever disk imaging to copy the disk to the new disk
- Boot from the new disk
- Download the CFDisk RPM
- Download ncurses-4 and ncurses-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)
- Run cfdisk /dev/device (probably /dev/sda or sdb .. you should know the device!)
- Create new partition and write changes – reboot.
- Create pv (pvcreate /dev/sda6) this creates the pv on sda6
- Add pv to volume group (vgextend VolGroup00 /dev/sda6) this
- vgdisplay will show volume group’s total size, now we can extend our lv
- Unmount the mount being used (in our case it was /home) umount /home
- lvextend -L+100GB /dev/mapper/VolGroup00/LogVol00-Home – This extends the current lv by 100GB
- Mount the partition back to it’s mountpoint (as specified in fstab) mount /home
- 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!
- 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.