Learn to cross happiness and sorrow on the long river of ups and downs life.
0%
LVM expansion and recovery of deleted LV or VG
Posted onEdited onInlinux
,
services
,
lvmSymbols count in article: 5.9kReading time ≈5 mins.
Two new hard disks were added to NAS, and one LV was deleted due to an operation error when expanding the capacity of LVs. I took some time to find it back. So this article is a memo.
The difference between LVM2 and RAID
Simply RAID is a method to store your data safely whereas LVM is a software which can extend the performance of a RAID.
RAID
RAID is a combination of multiple disks to form a single module which can store data on one or more disk to improve redundancy and also to reduce the risk of data loss. RAID can be achieved either using physical device or a software.
LVM2
LVM is a method of logically partitioning your memory device over multiple disks in order to have a single or multiple partition over multiple disks. LVM is purely a software which manages multiple disks. LVM can be made to work over RAID for achieving improved DATA speeds.
File: /etc/lvm/archive/shares_00001-1927234942.vg/shares_00001-1927234942.vg VG name: shares Description: Created *before* executing 'lvcreate -L 200G -n public shares' Backup Time: Thu Jan 5 08:40:52 2023
File: /etc/lvm/archive/shares_00003-1430114073.vg/shares_00003-1430114073.vg VG name: shares Description: Created *before* executing 'lvremove /dev/shares/public' Backup Time: Sun Jan 15 15:32:54 2023
File: /etc/lvm/backup/shares/shares VG name: shares Description: Created *after* executing 'lvremove /dev/shares/public' Backup Time: Sun Jan 15 15:32:54 2023
Look at this paragraph in the information above
1 2 3 4
File: /etc/lvm/archive/shares_00003-1430114073.vg/shares_00003-1430114073.vg VG name: shares Description: Created *before* executing 'lvremove /dev/shares/public' Backup Time: Sun Jan 15 15:32:54 2023
In the Description line, there is a command to delete LV[public], also there is a keyword before to indicate that the file shares_ 00003-1430114073.vg is the state of LV[public] before deleting, so we need to recover LVM to this step.
1 2 3 4 5 6 7 8 9 10 11
:~$ vgcfgrestore -f /etc/lvm/archive/shares_00003-1430114073.vg shares Volume group shares has active volume: haven200. WARNING: Found 1 active volume(s) in volume group "shares". Restoring VG with active LVs, may cause mismatch with its metadata. Do you really want to proceed with restore of volume group "shares", while 1 volume(s) are active? [y/n]: y Restored volume group shares.
:~$ lvscan ACTIVE '/dev/media/movies' [<2.64 TiB] inherit ACTIVE '/dev/shares/haven200' [400.00 GiB] inherit inactive '/dev/shares/public' [200.00 GiB] inherit
Now, the deleted LV[public] has been recovered, but its status is inactive, so we need to activate it manually.
1 2 3 4 5 6 7 8 9 10 11 12
:~$ lvchange -ay /dev/shares/public :~$ lvscan ACTIVE '/dev/media/movies' [<2.64 TiB] inherit ACTIVE '/dev/shares/haven200' [400.00 GiB] inherit ACTIVE '/dev/shares/public' [200.00 GiB] inherit
:~$ mount /dev/shares/public /mnt/public :~$ ll /mnt/public drwxr-xr-x 2 nas nas 4.0K Jun 18 2019 pure-ftpd/ drwxr-xr-x 2 root root 4.0K Jun 19 2019 rsyncd/ drwxr-xr-x 2 nas nas 4.0K Feb 22 2020 server/ drwxr-xr-x 2 nas nas 4.0K Jun 18 2019 transmission-daemon/
Here, the deleted LV [public] is recovered and can be mounted and used normally.
Expand LV/VG
Expand VG:Each PV can only join one VG, so when there is not enough VG space, you can only add PV for this VG.
Expand LV: as follows
VG has free space: simply expand this LV.
VG has no free space: Reduce the space of other LVs on this VG and add this space to the LV that needs to be expanded.
LV[movies] ran out of space, so a new hard drive was added. The following is the expansion record.
# format new disk :~$ gdisk /dev/sdk ... ... Command (m forhelp): n Partition number (1-?): 1 First cylinder (1-xxxx, default 1): Last cylinder, +cylinders or +size{K,M,G} (1-xxxxx, default xxxxx): Command (m forhelp): t Selected partition 1 Hex code (type L to list codes): lvm Changed system type of partition 1 to 43 (Linux LVM) ... ... # create pv :~$ pvcreate /dev/sdk1 # add pv to vg :~$ vgextend media /dev/sdk1 :~$ vgs VG #PV #LV #SN Attr VSize VFree media 2 1 0 wz--n- <4.64t 3.77g shares 1 2 0 wz--n- <1024.00g <424.00g
VG[media] has been expanded. Next, we will start to expand the capacity of LV[movies].