LVM HDD Replacement/Upgrade – LVM Series #2

While we are on the subject of setting up LVMs and hard drives (see previous post), I thought I’d continue with how to upgrade your NAS by replacing one hard drive with another of a bigger size.Note that you will need to do this while your logical partition has free space equal (or greater) than the size of the drive you are removing. e.g. if you are taking out a 1Tb drive then your partition should have at least this amount free before you start this tutorial. If it doesn’t then copy stuff to a portable drive or something to free up the space and put it back after.

Let’s use /dev/sdc as the example drive to be replaced. Note Webmin can be used for this whole process too if it is installed – we’ll cover Webmin installation in a later post. You’ll also need sufficient free space in the logical volume already to hold all your data while your one drive is removed.

Check the filesystem:

Shrink filesystem in logical volume to lower that the total of all remaining disks:

Reduce size of lv to size of filesystem:

Move everything off sdc1:

Take sdc1 out of the volume group (assuming ‘fileserver’ is your volume group name):

Display new volume group info:

Remove partition from physical volume:

Display new PV info:

You can now remove /dev/sdc from system and replace with bigger disk. This will also be called likely be called /dev/sdc when you next boot so we’ll use than name below. But you can check it first with: fdisk -l (have a look here for some extra disk ID options: http://www.binarytides.com/linux-command-check-disk-partitions/ )

If just replacing like for like (i.e. same size disks) then the vgcfgrestore command can be run – see subsequent part of this series where I describe replacing a failed disk.

Partition new disk*:

Create physical volume:

Extend volume group:

Display VG details:

Extend logical volume – note use the details in the vgdisplay output to get the TOTAL physical extents number to add, you can use no argument to automatically use ALL free physical extents (PEs):

Resize the filesystem to use whole logical volume:

* Note that fdisk only allows partitions created up to 2Tb. If new drive is >2Tb then need to add whole device as a pv, not just an fdisk LVM partition (see extra info: http://askubuntu.com/questions/274382/how-to-create-a-lvm-partition-physical-volume-2tb). So after you insert the new drive do this instead of the fdisk, pvcreate, and vgextend command above:

Useful sources
http://www.lshift.net/blog/2010/01/15/upgrading-your-disk-with-lvm
http://www.frozenindustries.com/2009/03/21/replace-an-lvm-drive-with-a-larger-one/

Leave a Reply

(email optional)