HowTo: Replace an LVM2 disk with a bigger one
23 08 2007This is a repost of one of my old Blog Postings from 2005, It’s still current and applies to linux logical volume management. After the jump is the instructions on how to replace a member disc of an LVM2 volume group with a larger one..
I’ve performed this replacement more than a few times, getting rid of small, dying, or poorly performing disks, over the past few years I’ve gotten rid of any disks that aren’t Seagate. I’ve been really impressed with the Seagate drives, they’ve been fast, reliable, and I haven’t had any issues with them.
- Add the new drive to the system, without removing any of the existing drives.
- Check the new disk, ensure it’s working, and create a test filesystem to ensure it’s not going to die as soon as we start moving PE’s to it.
- Check the device filter line in /etc/lvm/lvm.conf to ensure the new drive is included and available to LVM.
dd if=/dev/zero of=/dev/[NewDrive] bs=1024 count=1
(double-check and don’t screw this up — will wipe out the partition table created when we tested the disk earlier)blockdev --rereadpt /dev/[NewDrive]
(rescans the drive for the nodes in /dev)pvcreate /dev/[NewDrive]- Check pvdisplay and vgdisplay to look for the new drive, and the additional free PEs.
- vgextend [VolGroupName] /dev/[NewDrive]
(add the new disk to the main volume group) - Select the target disk you want to move the data off of (will be referred to as the [OldDrive]).
pvmove -v /dev/[OldDrive]
(moves the PEs on the OldDrive to the NewDrive — May take a while)vgreduce [VolGroupName] /dev/[OldDrive]
(removes the OldDrive from the LVM Volume Group)- Assuming the new drive is a larger disk, the next steps will add the remaining space to the LVM Volume Group.
- Run vgdisplay and note the number of free PEs (you’ll need it for the next step)
lvextend -l +[FreePEs] /dev/[VolGroupName]/[LVName]
(adds the free PEs to the current logical volumes)- Check the status of the LVM volume with vgdisplay and lvdisplay
resize_reiserfs /dev/[VolGroupName]/[LVName]
(will resize the filesystem living in the Logical Volume to use up all the new space)- Assuming everything went correctly, mount the volume and enjoy your new space.
If you have any comments, alternatives, or ideas, feel free to drop me a line here..





