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.

umount /dev/fileserver/shared

Check the filesystem:

e2fsck -f /dev/fileserver/shared

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

resize2fs /dev/fileserver/shared 3000G

Reduce size of lv to size of filesystem:

lvreduce -L 3000G /dev/fileserver/shared

Move everything off sdc1:

pvmove /dev/sdc1

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

vgreduce fileserver /dev/sdc1

Display new volume group info:


Remove partition from physical volume:

pvremove /dev/sdc1

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: )

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*:

fdisk /dev/sdc
-> n,
-> press {Enter} four times
-> t
-> 8e
-> w

Create physical volume:

pvcreate /dev/sdc1

Extend volume group:

vgextend fileserver /dev/sdc1

Display VG details:

vgdisplay fileserver

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):

lvextend –l 12345 /dev/fileserver/shared

Resize the filesystem to use whole logical volume:

resize2fs /dev/fileserver/shared

* 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: So after you insert the new drive do this instead of the fdisk, pvcreate, and vgextend command above:

pvcreate /dev/sda
vgextend fileserver /dev/sda

Useful sources

Leave a Reply

(email optional)

Warning: Undefined array key "rerror" in /home/public/blog/wp-content/plugins/wp-recaptcha/recaptcha.php on line 291