How to replace a disk in linux LVM volume group

root's picture

In this tutorial we want to replace /dev/sdc1 with /dev/sdd1. Read on.

1. prepare the disk for lvm:

jupiter:~# pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created

2. add the disk in the volume group:

jupiter:~# vgextend squidvg /dev/sdd1
  Volume group "squidvg" successfully extended
jupiter:~# pvscan | grep squidvg
  PV /dev/sdc1   VG squidvg   lvm2 [30.00 GiB / 5.00 GiB free]
  PV /dev/sdd1   VG squidvg   lvm2 [30.00 GiB / 30.00 GiB free]

3. Now we need to move the data from one disk to another and we can do with pvmove command.

jupiter:~# lvscan | grep squidvg
  ACTIVE            '/dev/squidvg/cache' [25.00 GiB] inherit
jupiter:~# pvmove -n cache /dev/sdc1 /dev/sdd1
  /dev/sdc1: Moved: 0.0%
  /dev/sdc1: Moved: 2.3%
  /dev/sdc1: Moved: 3.8%
  /dev/sdc1: Moved: 5.3%
[..cut useless output..]
  /dev/sdc1: Moved: 98.0%
  /dev/sdc1: Moved: 98.9%
  /dev/sdc1: Moved: 100.0%
jupiter:~# pvscan | grep squidvg
  PV /dev/sdc1   VG squidvg   lvm2 [30.00 GiB / 30.00 GiB free]
  PV /dev/sdd1   VG squidvg   lvm2 [30.00 GiB / 5.00 GiB free]

4. Remove the disk from volume group and lvm:

jupiter:~# vgreduce squidvg /dev/sdc1
  Removed "/dev/sdc1" from volume group "squidvg"
jupiter:~# pvremove /dev/sdc1 
  Labels on physical volume "/dev/sdc1" successfully wiped

And that is it!

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content