• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux & scripts.

  • How-to guides
    • Howto
    • Disk management
    • Configurations
  • OS
    • HPUX
    • Linux
  • Commands & tools
    • Commands
    • Software & Tools
    • System services
  • Cloud computing
    • AWS CSA associate quiz
    • AWS CSA preparation guide!
    • Cloud Services
  • Tips & Tricks
  • Linux commands
You are here: Home / Howto

How to safely remove disk from LVM

Published: April 17, 2018 | Modified: April 17, 2018 | 2859 views




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
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
1
2
3
4
5
6
7
8
9
 
root@kerneltalks # lsblk
NAME         MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda         202:0    0  10G  0 disk
├─xvda1      202:1    0   1M  0 part
└─xvda2      202:2    0  10G  0 part /
xvdf         202:80   0   1G  0 disk
└─vg01-lvol1 253:0    0  20M  0 lvm  /mydata
 

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
2
3
4
5
6
7
8
9
10
 
root@kerneltalks # lsblk
NAME         MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda         202:0    0  10G  0 disk
├─xvda1      202:1    0   1M  0 part
└─xvda2      202:2    0  10G  0 part /
xvdf         202:80   0   1G  0 disk
└─vg01-lvol1 253:0    0  20M  0 lvm  /mydata
xvdg         202:96   0   1G  0 disk
 

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
2
3
4
5
6
 
root@kerneltalks # pvcreate /dev/xvdg
  Physical volume "/dev/xvdg" successfully created.
root@kerneltalks # vgextend vg01 /dev/xvdg
  Volume group "vg01" successfully extended
 

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
1
2
3
4
5
6
 
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 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
2
3
4
5
 
root@kerneltalks # pvmove /dev/xvdf
  /dev/xvdf: Moved: 0.00%
  /dev/xvdf: Moved: 100.00%
 

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
2
3
4
 
root@kerneltalks # pvmove /dev/xvdf 2>error.log >normal.log &
[1] 1639
 

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
1
2
3
4
5
6
 
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
 

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
2
3
4
 
root@kerneltalks # vgreduce vg01 /dev/xvdf
  Removed "/dev/xvdf" from volume group "vg01"
 

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
2
3
4
5
6
7
8
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 running.
    Wiping internal VG cache
    Wiping cache of LVM-capable devices
    Archiving volume group "vg01" metadata (seqno 17).
    Creating logical volume pvmove0
    activation/volume_list configuration setting not defined: Checking only host tags for vg01/lvol1.
    Moving 5 extents of logical volume vg01/lvol1.
    activation/volume_list configuration setting not defined: Checking only host tags for vg01/lvol1.
    Creating vg01-pvmove0
    Loading table for vg01-pvmove0 (253:1).
    Loading table for vg01-lvol1 (253:0).
    Suspending vg01-lvol1 (253:0) with device flush
    Resuming vg01-pvmove0 (253:1).
    Resuming vg01-lvol1 (253:0).
    Creating volume group backup "/etc/lvm/backup/vg01" (seqno 18).
    activation/volume_list configuration setting not defined: Checking only host tags for vg01/pvmove0.
    Checking progress before waiting every 15 seconds.
  /dev/xvdf: Moved: 0.00%
  /dev/xvdf: Moved: 100.00%
    Polling finished successfully.
 

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
2
3
 
root@kerneltalks # pvmove -i 1 /dev/xvdf
 


 

⇠ Previous article
Boot SUSE Linux from old kernel after kernel upgrade
Next article ⇢
How to change UID or GID safely in Linux

Related stuff:

  • How to identify current boot disk in HPUX
  • How to install sar in SUSE Linux
  • How to setup domain name in Linux server
  • Hyperthreading in HPUX
  • How to find process using high memory in Linux
  • How to save top command output in file
  • Everything you need to know about zombie process
  • How to establish passwordless ssh between two servers
  • How to run your script with system boot in HPUX
  • How to remove password expiry in HPUX HP Unix
  • Execute command at shutdown and boot in Suse Linux
  • 5 steps guide for SMTP configuration in Linux

Filed Under: Howto Tagged With: move PE in VG, pvmove command, remove disk from lv, remove disk from VG, remove faulty disk from LVM

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Follow our Google+ page.
  • Add our RSS feed to your feed reader.

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • Google+
  • RSS
  • Twitter

Popular posts

  • mount.nfs: requested NFS version or transport protocol is not supported
  • How to reset iptables to default settings
  • How to rescan disk in Linux after extending vmware disk
  • 4 ways to check size of physical memory (RAM) in Linux
  • How to setup domain name in Linux server
  • 5 steps guide for SMTP configuration in Linux
  • How to remount filesystem in read write mode under Linux
  • How to enable repository using subscription-manager in RHEL
  • Difference between /etc/passwd and /etc/shadow
  • How to configure login banners in Linux (RedHat, Ubuntu, CentOS, Fedora)

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2017 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.

  • RHEL6 boot process
  • Install and configure check_mk server on Linux
  • How to execute command inside Docker container
  • How to rename volume group
  • How to find process using high memory in Linux
  • The complete guide : logrotate utility on Linux
  • Host to guest disk mapping in HP iVM
  • Network routes in Linux
  • How to list open ports on Linux/Unix server
  • Create access keys in AWS