Procedure to Remove LVM disk

  1. Make a note of all partitions and disks first
  2. Add new disk and rescan the OS
  3. Add the new Physical Volumes to a Volume Group
  4. Move data from old disk to new disk
  5. Remove disk from VG
  6. Remove disk as physical volume
  7. Run partprobe
  8. Rescan the system

Counting number of existing disks on a system

fdisk -l 2> /dev/null | egrep '^Disk' | grep -v mapper | grep -v identifier | wc -l

Lists disks in scan

ls/sys/class/scsi_host

Scanning new disks on a system

for host in /sys/class/scsi_host/*; do echo "- - -" | sudo tee $host/scan; ls /dev/sd* ; done

RUN A PVSCAN TO CHECK ERRORS ON LVM

pvscan

attach a new disk to volume group

pvcreate /dev/sdd

Extend the volume group (VG ) with above pvdisk

vgextend ubuntu-data /dev/sdd

Move data from old disk to new disk

pvmove /dev/sdb /dev/sdd -v

reduce volume group size

vgreduce ubuntu-data /dev/sdc && vgreduce ubuntu-data /dev/sdb

Remove disks from pv

pvremove /dev/sdb &&pvremove /dev/sdc

rescan scsi bus adapter

for host in /sys/class/scsi_host/*; do echo "- - -" | sudo tee $host/scan; ls /dev/sd* ; done

In this exercise, we attach a new 70GB disk and remove all the existing disks /dev/sdb and /dev/sdc from the system.

root@wiki:~# pvcreate /dev/sdd
  Physical volume “/dev/sdd” successfully created.

root@wiki:~# pvs
  PV         VG          Fmt  Attr PSize   PFree   
  /dev/sda3  ubuntu-vg   lvm2 a–   <9.00g       0 
  /dev/sda4  ubuntu-vg   lvm2 a–  <10.00g 1016.00m
  /dev/sdb   ubuntu-data lvm2 a–  <20.00g       0 
  /dev/sdc   ubuntu-data lvm2 a–  <30.00g    1.99g
  /dev/sdd               lvm2 —   70.00g   70.00g

root@wiki:~# vgextend ubuntu-data /dev/sdd
  Volume group “ubuntu-data” successfully extended

root@wiki:~# pvs
  PV         VG          Fmt  Attr PSize   PFree   
  /dev/sda3  ubuntu-vg   lvm2 a–   <9.00g       0 
  /dev/sda4  ubuntu-vg   lvm2 a–  <10.00g 1016.00m
  /dev/sdb   ubuntu-data lvm2 a–  <20.00g       0 
  /dev/sdc   ubuntu-data lvm2 a–  <30.00g    1.99g
  /dev/sdd   ubuntu-data lvm2 a–  <70.00g  <70.00g

root@wiki:~# pvmove /dev/sdb /dev/sdd -v

    Cluster mirror log daemon is not running.
    Wiping internal VG cache
    Wiping cache of LVM-capable devices
    Archiving volume group “ubuntu-data” metadata (seqno 5).
    Creating logical volume pvmove0
    Moving 5119 extents of logical volume ubuntu-data/ubuntu-lvdata.
    activation/volume_list configuration setting not defined: Checking only host tags for ubuntu-data/ubuntu-lvdata.
    Setting up pvmove in on-disk volume group metadata.
    Creating ubuntu–data-pvmove0
    Loading ubuntu–data-pvmove0 table (253:2)
    Loading ubuntu–data-ubuntu–lvdata table (253:0)
    Suspending ubuntu–data-ubuntu–lvdata (253:0) with device flush
    activation/volume_list configuration setting not defined: Checking only host tags for ubuntu-data/pvmove0.
    Resuming ubuntu–data-pvmove0 (253:2)
    Loading ubuntu–data-pvmove0 table (253:2)
    Suppressed ubuntu–data-pvmove0 (253:2) identical table reload.
    Resuming ubuntu–data-ubuntu–lvdata (253:0)
    Creating volume group backup “/etc/lvm/backup/ubuntu-data” (seqno 6).
    Checking progress before waiting every 15 seconds.
  /dev/sdb: Moved: 0.37%
  /dev/sdb: Moved: 8.22%
  /dev/sdb: Moved: 15.73%
  /dev/sdb: Moved: 23.23%
  /dev/sdb: Moved: 30.26%
  /dev/sdb: Moved: 37.47%
  /dev/sdb: Moved: 85.64%
  /dev/sdb: Moved: 92.40%
  /dev/sdb: Moved: 98.63%
  /dev/sdb: Moved: 100.00%
    Polling finished successfully.

root@wiki:~# pvs
  PV         VG          Fmt  Attr PSize   PFree   
  /dev/sda3  ubuntu-vg   lvm2 a–   <9.00g       0 
  /dev/sda4  ubuntu-vg   lvm2 a–  <10.00g 1016.00m
  /dev/sdb   ubuntu-data lvm2 a–  <20.00g  <20.00g
  /dev/sdc   ubuntu-data lvm2 a–  <30.00g    1.99g
  /dev/sdd   ubuntu-data lvm2 a–  <70.00g   50.00g

root@wiki:~# pvmove /dev/sdc /dev/sdd -v
    Cluster mirror log daemon is not running.
    Wiping internal VG cache
    Wiping cache of LVM-capable devices
    Archiving volume group “ubuntu-data” metadata (seqno 8).
    Creating logical volume pvmove0
    Moving 7169 extents of logical volume ubuntu-data/ubuntu-lvdata.
    activation/volume_list configuration setting not defined: Checking only host tags for ubuntu-data/ubuntu-lvdata.
    Setting up pvmove in on-disk volume group metadata.
    Creating ubuntu–data-pvmove0
    Loading ubuntu–data-pvmove0 table (253:2)
    Loading ubuntu–data-ubuntu–lvdata table (253:0)
    Suspending ubuntu–data-ubuntu–lvdata (253:0) with device flush
    activation/volume_list configuration setting not defined: Checking only host tags for ubuntu-data/pvmove0.
    Resuming ubuntu–data-pvmove0 (253:2)
    Loading ubuntu–data-pvmove0 table (253:2)
    Suppressed ubuntu–data-pvmove0 (253:2) identical table reload.
    Resuming ubuntu–data-ubuntu–lvdata (253:0)
    Creating volume group backup “/etc/lvm/backup/ubuntu-data” (seqno 9).
    Checking progress before waiting every 15 seconds.
  /dev/sdc: Moved: 0.13%
  /dev/sdc: Moved: 5.40%
  /dev/sdc: Moved: 10.09%
  /dev/sdc: Moved: 84.56%
  /dev/sdc: Moved: 89.64%
  /dev/sdc: Moved: 94.63%
  /dev/sdc: Moved: 99.29%
  /dev/sdc: Moved: 100.00%
    Polling finished successfully.

root@wiki:~# pvs
  PV         VG          Fmt  Attr PSize   PFree   
  /dev/sda3  ubuntu-vg   lvm2 a–   <9.00g       0 
  /dev/sda4  ubuntu-vg   lvm2 a–  <10.00g 1016.00m
  /dev/sdb   ubuntu-data lvm2 a–  <20.00g  <20.00g
  /dev/sdc   ubuntu-data lvm2 a–  <30.00g  <30.00g
  /dev/sdd   ubuntu-data lvm2 a–  <70.00g  <22.00g

root@wiki:~# vgreduce ubuntu-data /dev/sdb 
  Removed “/dev/sdb” from volume group “ubuntu-data”

root@wiki:~# vgreduce ubuntu-data /dev/sdc
  Removed “/dev/sdc” from volume group “ubuntu-data”

root@wiki:~# pvs
  PV         VG          Fmt  Attr PSize   PFree   
  /dev/sda3  ubuntu-vg   lvm2 a–   <9.00g       0 
  /dev/sda4  ubuntu-vg   lvm2 a–  <10.00g 1016.00m
  /dev/sdb               lvm2 —   20.00g   20.00g
  /dev/sdc               lvm2 —   30.00g   30.00g
  /dev/sdd   ubuntu-data lvm2 a–  <70.00g  <22.00g

root@wiki:~# pvremove /dev/sdb
  Labels on physical volume “/dev/sdb” successfully wiped.
root@wiki:~# pvremove /dev/sdc
  Labels on physical volume “/dev/sdc” successfully wiped.

root@wiki:~# pvs
  /dev/sdc: read failed after 0 of 4096 at 0: Input/output error
  /dev/sdc: read failed after 0 of 4096 at 32212189184: Input/output error
  /dev/sdc: read failed after 0 of 4096 at 32212246528: Input/output error
  /dev/sdc: read failed after 0 of 4096 at 4096: Input/output error
  PV         VG          Fmt  Attr PSize   PFree   
  /dev/sda3  ubuntu-vg   lvm2 a–   <9.00g       0 
  /dev/sda4  ubuntu-vg   lvm2 a–  <10.00g 1016.00m
  /dev/sdd   ubuntu-data lvm2 a–  <70.00g  <22.00g

root@wiki:~# partprobe

root@wiki:~# pvs
  PV         VG          Fmt  Attr PSize   PFree   
  /dev/sda3  ubuntu-vg   lvm2 a–   <9.00g       0 
  /dev/sda4  ubuntu-vg   lvm2 a–  <10.00g 1016.00m
  /dev/sdd   ubuntu-data lvm2 a–  <70.00g  <22.00g

root@wiki:~# df -H
Filesystem                               Size  Used Avail Use% Mounted on
udev                                     2.6G     0  2.6G   0% /dev
tmpfs                                    509M  2.3M  507M   1% /run
/dev/mapper/ubuntu–vg-ubuntu–lv         19G   14G  5.0G  73% /
tmpfs                                    2.6G     0  2.6G   0% /dev/shm
tmpfs                                    5.3M  4.1k  5.3M   1% /run/lock
tmpfs                                    2.6G     0  2.6G   0% /sys/fs/cgroup
/dev/loop0                                99M   99M     0 100% /snap/core/9066
/dev/loop1                                99M   99M     0 100% /snap/core/8935
/dev/sda2                                1.1G  160M  794M  17% /boot
/dev/mapper/ubuntu–data-ubuntu–lvdata   51G   49G  298M 100% /data
tmpfs                                    509M   29k  509M   1% /run/user/120
tmpfs                                    509M   46k  509M   1% /run/user/1000
/dev/loop2                                58M   58M     0 100% /snap/core18/1754
/dev/loop3                                99M   99M     0 100% /snap/mpv/1
/dev/loop4                               306M  306M     0 100% /snap/vlc/1620
root@wiki:~#  

(Visited 494 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.

Leave a Reply