Monday, February 1, 2010

New HDD, enlarging Red Hat/Centos ext3/lvm partition

SkyHi @ Monday, February 01, 2010

Suddenly, I’ve run out of space on one of my servers at home. Solution, add a new harddisk, extend existing partition onto the new harddisk.. Simple right? Right…

Firstly, fix the new harddisk onto the machine. Fdisk it like thus -

# fdisk /dev/sdb

Create a new ’sdb1′ partition using type 8, which is Linux LVM.

Next, we need to create a Physical Volume within the newly created sdb1 partition.

# pvcreate /dev/sdb1

After that we will extend the existing volume ‘VolGroup00′ onto the newly created physical volume.

# vgextend VolGroup00 /dev/sdb1

Once done, the next step is to extend the Logical Volume within the volume group to use the free space newly made available when you extend the volume group previously.

# lvextend -L 40G /dev/VolGroup00/LogVol00

And finally, we’ll enlarge the ext3 partition to make use of the newly available free space in the logical volume.

# ext2online /dev/VolGroup00/LogVol00

I hope you guys read this below before proceeding..

# man ext2online
Note that resizing a mounted filesystem is inherently dangerous and may corrupt filesystems, although no errors resulting in data loss have ever been reported to the author. In theory online resizing should work fine with arbitrarily large filesystems, but it has not yet been tested by the author on a filesystem larger than 11GB. Use with caution. Backups are always a good idea, because your disk may fail at any time, you delete files by accident, or your computer is struck by a meteor.

It is a good idea to ‘e2fsck -f /dev/VolGroup00/LogVol00′ before doing anything.