Linux How-To

safely take away disk from LVM

SEOClerks

Discover ways to safely take away disk from LVM. Its helpful when it’s worthwhile to unlock disks from quantity group and re-use some place else or exchange defective disk.

How to safely remove disk from LVM safely take away disk from LVM

 

This text will serve answer for beneath questions :

safely take away disk from LVMHow to take away the disk from VG onlineHow to repeat knowledge from one disk to different on the bodily levelHow to switch a defective disk in LVM onlineHow to maneuver bodily extents from one disk to anotherHow to unlock disk from VG to shrink VG sizeHow to securely scale back VG

We have now quantity group named vg01 which has 20M logical quantity created in it and mounted it on /mydata mount level. Test lsblk output beneath –

root@kerneltalks # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:zero zero 10G zero disk
├─xvda1 202:1 zero 1M zero half
└─xvda2 202:2 zero 10G zero half /
xvdf 202:80 zero 1G zero disk
└─vg01-lvol1 253:zero zero 20M zero lvm /mydata

 

root@kerneltalks # lsblk

NAME         MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

xvda         202:zero    zero  10G  zero disk

├─xvda1      202:1    zero   1M  zero half

└─xvda2      202:2    zero  10G  zero half /

xvdf         202:80   zero   1G  zero disk

└─vg01lvol1 253:zero    zero  20M  zero lvm  /mydata

 

Now, connect new disk of identical or greater dimension of disk /dev/xvdf. Establish new disk on the system by utilizing lsblk command once more and evaluating the output to earlier one.

root@kerneltalks # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:zero zero 10G zero disk
├─xvda1 202:1 zero 1M zero half
└─xvda2 202:2 zero 10G zero half /
xvdf 202:80 zero 1G zero disk
└─vg01-lvol1 253:zero zero 20M zero lvm /mydata
xvdg 202:96 zero 1G zero disk

 

root@kerneltalks # lsblk

NAME         MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

xvda         202:zero    zero  10G  zero disk

├─xvda1      202:1    zero   1M  zero half

└─xvda2      202:2    zero  10G  zero half /

xvdf         202:80   zero   1G  zero disk

└─vg01lvol1 253:zero    zero  20M  zero lvm  /mydata

xvdg         202:96   zero   1G  zero disk

 

You possibly can see new disk has been recognized as /dev/xvdg. Now, we are going to add this disk to present VG vg01. This may be executed utilizing vgextend command. Clearly, earlier than utilizing it in LVM it’s worthwhile to run pvcreate on it.

root@kerneltalks # pvcreate /dev/xvdg
Bodily quantity “/dev/xvdg” efficiently created.
root@kerneltalks # vgextend vg01 /dev/xvdg
Quantity group “vg01” efficiently prolonged

 

root@kerneltalks # pvcreate /dev/xvdg

  Bodily quantity “/dev/xvdg” efficiently created.

root@kerneltalks # vgextend vg01 /dev/xvdg

  Quantity group “vg01” efficiently prolonged

 

Now we’ve got disk to be eliminated /dev/xvdf and new disk to be added /dev/xvdg in identical quantity group vg01. You possibly can confirm it utilizing pvs command

root@kerneltalks # pvs
PV VG Fmt Attr PSize PFree
/dev/xvdf vg01 lvm2 a– 1020.00m 1000.00m
/dev/xvdg vg01 lvm2 a– 1020.00m 1020.00m

 

root@kerneltalks # pvs

  PV         VG   Fmt  Attr PSize    PFree

  /dev/xvdf  vg01 lvm2 a  1020.00m 1000.00m

  /dev/xvdg  vg01 lvm2 a  1020.00m 1020.00m

 

Observe above output. Since we created 20M mount level from disk /dev/xvdf it has 20M much less free dimension. The brand new disk /dev/xvdg is completly free.

Now, we have to transfer bodily extents from disk xvdf to xvdg. pvmove is command used to realize this. You simply want to provide disk identify from the place it’s worthwhile to transfer out PE. Command will transfer PE out of that disk and write them to all obtainable disks in the identical quantity group. In our case, just one different disk is offered to maneuver PE.

root@kerneltalks # pvmove /dev/xvdf
/dev/xvdf: Moved: zero.00%
/dev/xvdf: Moved: 100.00%

 

root@kerneltalks # pvmove /dev/xvdf

  /dev/xvdf: Moved: zero.00%

  /dev/xvdf: Moved: 100.00%

 

Transfer progress is proven periodically. If resulting from any purpose operation interrupted in between then moved PE will stay at vacation spot disks and un-moved PEs will stay on the supply disk. The operation might be resumed by issuing the identical command once more. It would then transfer remaining PE out of the supply disk.

You possibly can even run it in background with nohup.

root@kerneltalks # pvmove /dev/xvdf 2>error.log >regular.log &
[1] 1639

 

root@kerneltalks # pvmove /dev/xvdf 2>error.log >regular.log &

[1] 1639

 

In above command, it is going to run pvmove in background. It would redirect regular console outputs in regular.log file underneath present working listing whereas errors can be redirected and saved in error.log file in present working listing.

Now in the event you examine pvs output once more, you’ll find all house on disk xvdf is free which suggests its not been used to retailer any knowledge in that VG. This ensures you may take away the disk with none points.

root@kerneltalks # pvs
PV VG Fmt Attr PSize PFree
/dev/xvdf vg01 lvm2 a– 1020.00m 1020.00m
/dev/xvdg vg01 lvm2 a– 1020.00m 1000.00m

 

root@kerneltalks # pvs

  PV         VG   Fmt  Attr PSize    PFree

  /dev/xvdf  vg01 lvm2 a  1020.00m 1020.00m

  /dev/xvdg  vg01 lvm2 a  1020.00m 1000.00m

 

Earlier than eradicating/detaching disk from server, it’s worthwhile to take away it from LVM. You are able to do this be lowering VG and opting that disk out.

root@kerneltalks # vgreduce vg01 /dev/xvdf
Eliminated “/dev/xvdf” from quantity group “vg01”

 

root@kerneltalks # vgreduce vg01 /dev/xvdf

  Eliminated “/dev/xvdf” from quantity group “vg01”

 

Now disk xvdf might be eliminated/indifferent from server safely.

Few helpful switches of pvmove :

Verbose mode prints extra detailed data of operation. It may be invoked by utilizing -v change.

root@kerneltalks # pvmove -v /dev/xvdf
Cluster mirror log daemon is just not operating.
Wiping inner VG cache
Wiping cache of LVM-capable units
Archiving quantity group “vg01” metadata (seqno 17).
Creating logical quantity pvmove0
activation/volume_list configuration setting not outlined: Checking solely host tags for vg01/lvol1.
Shifting 5 extents of logical quantity vg01/lvol1.
activation/volume_list configuration setting not outlined: Checking solely host tags for vg01/lvol1.
Creating vg01-pvmove0
Loading desk for vg01-pvmove0 (253:1).
Loading desk for vg01-lvol1 (253:zero).
Suspending vg01-lvol1 (253:zero) with gadget flush
Resuming vg01-pvmove0 (253:1).
Resuming vg01-lvol1 (253:zero).
Creating quantity group backup “/and so on/lvm/backup/vg01” (seqno 18).
activation/volume_list configuration setting not outlined: Checking solely host tags for vg01/pvmove0.
Checking progress earlier than ready each 15 seconds.
/dev/xvdf: Moved: zero.00%
/dev/xvdf: Moved: 100.00%
Polling completed efficiently.

1

2

three

four

5

6

7

eight

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

 

root@kerneltalks # pvmove -v /dev/xvdf

    Cluster mirror log daemon is not operating.

    Wiping inner VG cache

    Wiping cache of LVMsuccesful units

    Archiving quantity group “vg01” metadata (seqno 17).

    Creating logical quantity pvmove0

    activation/volume_list configuration setting not outlined: Checking solely host tags for vg01/lvol1.

    Shifting 5 extents of logical quantity vg01/lvol1.

    activation/volume_list configuration setting not outlined: Checking solely host tags for vg01/lvol1.

    Creating vg01pvmove0

    Loading desk for vg01pvmove0 (253:1).

    Loading desk for vg01lvol1 (253:zero).

    Suspending vg01lvol1 (253:zero) with gadget flush

    Resuming vg01pvmove0 (253:1).

    Resuming vg01lvol1 (253:zero).

    Creating quantity group backup “/and so on/lvm/backup/vg01” (seqno 18).

    activation/volume_list configuration setting not outlined: Checking solely host tags for vg01/pvmove0.

    Checking progress earlier than ready each 15 seconds.

  /dev/xvdf: Moved: zero.00%

  /dev/xvdf: Moved: 100.00%

    Polling completed efficiently.

 

Interval at which command updates the progress might be modified. -i change adopted by variety of seconds can be utilized to get updates from command on consumer outlined intervals on progress.

root@kerneltalks # pvmove -i 1 /dev/xvdf

 

root@kerneltalks # pvmove -i 1 /dev/xvdf

 

 

Source link

Related Articles

Back to top button