Você está na página 1de 5

How to safely remove disk from LVM https://www.printfriendly.

com/p/g/aBWT29

How to safely remove disk from LVM


kerneltalks.com/howto/how-to-safely-remove-disk-from-lvm/

April 17, 2018

Learn how to safely remove disk from LVM. Its useful when you need to free up disks from volume
group and re-use somewhere else or replace faulty disk.

How to safely remove disk from LVM

This article will serve solution for below questions :

How to safely remove disk from LVM


How to remove the disk from VG online
How to copy data from one disk to other at the physical level
How to replace a faulty disk in LVM online
How to move physical extents from one disk to another
How to free up disk from VG to shrink VG size
How to safely reduce VG

We have volume group named vg01 which has 20M logical volume created in it and mounted it
on /mydata mount point. Check lsblk output below –

Shell
How to safely remove disk from LVM https://www.printfriendly.com/p/g/aBWT29

1 root@kerneltalks# lsblk
2 NAME MAJ:MIN RMSIZE RO TYPEMOUNTPOINT
3 xvda202:0010G0disk
4 ├─xvda1202:101M0part
5 └─xvda2202:2010G0part/
6 xvdf202:8001G0disk
7 └─vg01-lvol1253:0020M0lvm/mydata
8
9

Now, attach new disk of same or bigger size of disk /dev/xvdf . Identify new disk on the system
by using lsblk command again and comparing the output to previous one.

Shell

1 root@kerneltalks# lsblk
2 NAME MAJ:MIN RMSIZE RO TYPEMOUNTPOINT
3 xvda202:0010G0disk
4 ├─xvda1202:101M0part
5 └─xvda2202:2010G0part/
6 xvdf202:8001G0disk
7 └─vg01-lvol1253:0020M0lvm/mydata
8 xvdg202:9601G0disk
9
10

You can see new disk has been identified as /dev/xvdg . Now, we will add this disk to current VG
vg01 . This can be done using vgextend command. Obviously, before using it in LVM you need to
run pvcreate on it.

Shell

1 root@kerneltalks# pvcreate /dev/xvdg


2 Physical volume"/dev/xvdg"successfully created.
3 root@kerneltalks# vgextend vg01 /dev/xvdg
4 Volume group"vg01"successfully extended
5
6

Now we have disk to be removed /dev/xvdf and new disk to be added /dev/xvdg in same
volume group vg01 . You can verify it using pvs command

Shell
How to safely remove disk from LVM https://www.printfriendly.com/p/g/aBWT29

1 root@kerneltalks# pvs
2 PV VG Fmt Attr PSize PFree
3 /dev/xvdf vg01 lvm2a--1020.00m1000.00m
4 /dev/xvdg vg01 lvm2a--1020.00m1020.00m
5
6

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

Now, we need to move physical extents from disk xvdf to xvdg . pvmove is command used to
achieve this. You just need to supply disk name from where you need to move out PE. Command
will move PE out of that disk and write them to all available disks in the same volume group. In our
case, only one other disk is available to move PE.

Shell

1 root@kerneltalks# pvmove /dev/xvdf


2 /dev/xvdf:Moved:0.00%
3 /dev/xvdf:Moved:100.00%
4
5

Move progress is shown periodically. If due to any reason operation interrupted in between then
moved PE will remain at destination disks and un-moved PEs will remain on the source disk. The
operation can be resumed by issuing the same command again. It will then move remaining PE out
of the source disk.

You can even run it in background with nohup.

Shell

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


2 [1]1639
3
4

In above command, it will run pvmove in background. It will redirect normal console outputs in
normal.log file under current working directory whereas errors will be redirected and saved in
error.log file in current working directory.

Now if you check pvs output again, you will find all space on disk xvdf is free which means its
not been used to store any data in that VG. This ensures you can remove the disk without any
issues.

Shell
How to safely remove disk from LVM https://www.printfriendly.com/p/g/aBWT29

1 root@kerneltalks# pvs
2 PV VG Fmt Attr PSize PFree
3 /dev/xvdf vg01 lvm2a--1020.00m1020.00m
4 /dev/xvdg vg01 lvm2a--1020.00m1000.00m
5
6

Before removing/detaching disk from server, you need to remove it from LVM. You can do this be
reducing VG and opting that disk out.

Shell

1 root@kerneltalks# vgreduce vg01 /dev/xvdf


2 Removed"/dev/xvdf"from volume group"vg01"
3
4

Now disk xvdf can be removed/detached from server safely.

Few useful switches of pvmove :


Verbose mode prints more detailed information of operation. It can be invoked by using -v switch.

Shell

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


2 Cluster mirror log daemon isnotrunning.
3 Wiping internal VG cache
4 Wiping cache of LVM-capable devices
5 Archiving volume group"vg01"metadata(seqno17).
6 Creating logical volume pvmove0
7 activation/volume_list configuration setting notdefined:Checking only host tags forvg01/lvol1.
8 Moving5extents of logical volume vg01/lvol1.
9 activation/volume_list configuration setting notdefined:Checking only host tags forvg01/lvol1.
10 Creating vg01-pvmove0
11 Loading table forvg01-pvmove0(253:1).
12 Loading table forvg01-lvol1(253:0).
13 Suspending vg01-lvol1(253:0)with device flush
14 Resuming vg01-pvmove0(253:1).
15 Resuming vg01-lvol1(253:0).
16 Creating volume group backup"/etc/lvm/backup/vg01"(seqno18).
17 activation/volume_list configuration setting notdefined:Checking only host tags forvg01/pvmove0.
18 Checking progress before waiting every15seconds.
19 /dev/xvdf:Moved:0.00%
20 /dev/xvdf:Moved:100.00%
21 Polling finished successfully.
22
23
How to safely remove disk from LVM https://www.printfriendly.com/p/g/aBWT29

Interval at which command updates the progress can be changed. -i switch followed by number
of seconds can be used to get updates from command on user defined intervals on progress.

Shell

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


2
3

Você também pode gostar