How to safely delete PV physical volumes (hard disks or partitions) in Linux LVM

  
Most of the articles described are just adding hard disks and resizing partitions, but there is very little security to completely remove one partition or hard disk. Introduce this.

Situation:

First, because the operation mode of the hard disk or partition is the same, so I will use the partition as an example.

Second, /home partition 2.6G, consists of the following pv:

/dev/sda5 100M

/dev/sda6 200M

/dev/Sda7 300M

/dev/sda8 400M

/dev/sda9 500M

/dev/sda10 600M

/dev/sda11 500M

Very broken right? ^_^ Because of the test.

Third, randomly write a bunch of files into, the amount reached 2G, idle 500M

Fourth, prepare to remove the sda6 200M PV (removed capacity must be less than the free capacity)

Ok, let's get started.

Unmount the partition (the shrink operation must be uninstalled):

umount /home

Reduce the partition:

e2fsck -f /dev/liuhg_disk/home

resize2fs /dev/liuhg_disk/home 2200M

First shrink the partition to 2200M. This is to make room for sda6, sda6 is 200M, and I vacated 400M, so it should be enough of.

Reduce the logical volume:

lvreduce -L 2200M /dev/liuhg_disk/home

The partition is reduced and the logical volume used is also reduced, and the PV is used. Status:

pvdisplay -m

is displayed as follows:

--- Physical volume --- PV Name /dev/sda5 VG Name liuhg_disk PV Size 103.26 MiB /not Usable 3.26 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 25 Free PE 0 Allocated PE 25 PV UUID 5lnx52-b4jc-OOfZ-f2QA-ttdQ-DZeD-Ce3rb3 --- Physical Segments --- Physical extent 0 to 24 : Logical volume /dev/liuhg_disk/home Logical extents 0 to 24 --- Physical volume --- PV Name /dev/sda6 VG Name liuhg_disk PV Size 203.92 MiB /not usable 3.92 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 50 Free PE 0 <-----Too tragedy, sda6 is full of data, there is no left Allocated PE 50 <-----This 50PE data should be removed, otherwise the data will be lost And the place to store must also be at least 50PE PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK --- Physical Segments --- Physi Cal extent 0 to 49: Logical volume /dev/liuhg_disk/home Logical extents 25 to 74 --- Physical volume --- PV Name /dev/sda7 VG Name liuhg_disk PV Size 305.89 MiB /not usable 1.89 MiB Allocatable yes PE Size 4.00 MiB Total PE 76 Free PE 76 <---This partition has 76 spares, so it is expected that there will be no problem with the 50. Allocated PE 0 PV UUID 9CFnlx-CAEw-CSul-Rig9-FiCN-zK0a-oGmTEP - -- Physical Segments --- Physical extent 0 to 75: FREE --- Physical volume --- PV Name /dev/sda8 VG Name liuhg_disk PV Size 407.87 MiB /not usable 3.87 MiB Allocatable yes PE Size 4.00 MiB Total PE 101 Free PE 60 Allocated PE 41 PV UUID X0I8p0-x2xr-2xLG-QQD4-jbtS-3C4i-xPn4Bl --- Physical Segments --- Physical extent 0 to 40: Logical volume /dev/liuhg_disk/home Logical extents 471 to 511 Physical extent 41 To 100: FREE --- Physical volume --- PV Name /dev/sda9 VG Name liuhg_disk PV Size 509.84 MiB /not usable 1.84 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 127 Free PE 0 Allocated PE 127 PVUUID avJQaA-oMKt-NEoJ-ojBK-2Csc-1dca-1mh6Ue --- Physical Segments --- Physical extent 0 to 126: Logical volume /dev/liuhg_disk/home Logical extents 225 to 351 --- Physical volume --- PV Name /dev/sda10 VG Name liuhg_disk PV Size 603.98 MiB /not usable 3.98 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 150 Free PE 0 Allocated PE 150 PV UUID JlMIAF-A49n-M6HA-ZLXf-d8nS-pfZr- YeQsKT --- Physical Segments --- Physical extent 0 to 149: Logical volume /dev/liuhg_disk/home Logical extents 75 to 224 --- Physical volume --- PV Name /dev/sda11 VG Name liuhg_disk PV Size 478.47 MiB /Not usable 2.47 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 119 Free PE 0 Allocated PE 119 PV UUID xnHJNA-tDVx-dryX-KM1x-g96Y-sptI-9iUOcU --- Physical Segments --- Physical extent 0 to 118: Logical volume /dev/liuhg_disk/home Logical extents 352 to 470

Set sda6 to offline:

pvchange -xn /dev/sda6

Use pvdisplay - m

is shown below:

…&helli p;

--- Physical volume --- PV Name /dev/sda6 VG Name liuhg_disk PV Size 203.92 MiB /not usable 3.92 MiB Allocatable NO <----- indicates that the PV PE has been turned off Size 4.00 MiB Total PE 50 Free PE 0 Allocated PE 50 PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK

…… Remove sda6 data:

Pvmove -i 1 /dev/sda6

-i 1 is the progress of data migration reported every 1 second.

[root@liuhg /]# pvmove -i 1 /dev/sda6 /dev/sda6: Moved: 38.0% /dev/sda6: Moved: 84.0% /dev/sda6: Moved: 100.0%

Re-use pvdisplay -m

as shown below:

……

--- Physical volume --- PV Name /dev/sda6 VG Name Liuhg_disk PV Size 203.92 MiB /not usable 3.92 MiB Allocatable NO PE Size 4.00 MiB Total PE 50 Free PE 50 <----Show full idle and Total PE number consistent Allocated PE 0 PV UUID S2ane6-nlFG-uSNR-35NP- Yxa6-cXRb-r8E8mK

……

Remove sda6 from the volume group:

[root@liuhg /]# vgreduce liuhg_disk /dev/sda6 Removed " ;/dev/sda6" from volume group "liuhg_disk"

pvdisplay -m take a look:

--- NEW Physical volume --- <-----also Tell you this is a new PV ^_^ PV Name /dev/sda6 VG Name <-----empty PV Size 203.92 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID S2ane6- nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK

At this point vgdisplay -v can see that there is no /dev/sda6. Remount /home

[root@liuhg /]# mount /dev/liuhg_disk/home /home [root@liuhg /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 2.0 G 546M 1.3G 30% /tmpfs 504M 0 504M 0% /dev/shm /dev/mapper/liuhg_disk-home 2.2G 1.8G 42M 98% /home

Go in and see the data, one is not lost.

Copyright © Windows knowledge All Rights Reserved