Tag Archives: lvm

Import and rename duplicated volume group

If you like to use a cloned volume with a volume group on it, then normally you will have a problem with the VG UUID and the VG Name. The good answer there is a nice solution for the problem and you can import and rename duplicated volume groups.

To rename and generate a new UUID for the volume group on the volume use the program vgimportclone.

sudo gimportclone -n old /dev/sdb1
WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
WARNING: Activation disabled. No device-mapper interaction will be attempted.
WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
Physical volume "/tmp/snap.cozRdFdC/vgimport0" changed
1 physical volume changed / 0 physical volumes not changed
WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
WARNING: Activation disabled. No device-mapper interaction will be attempted.
WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
Volume group "system" successfully changed
WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!
Volume group "system" successfully renamed to "old"
Reading all physical volumes. This may take a while...
Found volume group "system" using metadata type lvm2

After the successfully rename of the volume group activate it.

sudo vgchange -a y

Now you can use the renamed volume group old normally as other volume groups.

Move logical Volumes to other volume group and remove the physical volume.

At the beginning, it look like:

~# lvs
  LV         VG         Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  log        system     -wi-ao----  1.86g
  root       system     -wi-ao----  2.79g
  swap       system     -wi-ao----  1.86g
  tmp        system     -wi-ao----  1.86g
  usr        system     -wi-ao----  1.86g
  var        system     -wi-ao---- 31.72g
  testlv     systemtest -wi-------  5.00g
  testlv2    systemtest -wi------- 20.00g
~# pvs
  PV         VG         Fmt  Attr PSize   PFree
  /dev/md0   systemtest lvm2 a--  884.63g 859.63g
  /dev/sdk3  system     lvm2 a--  147.61g 105.66g

Now we begin to merge the two volume groups to one.

vgsplit -n systemtest/testlv systemtest system

Now it look like:

~# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/md0   system lvm2 a--  884.63g 859.63g
  /dev/sdk3  system lvm2 a--  147.61g 105.66g
~# lvs
  LV         VG         Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  log        system     -wi-ao----  1.86g
  root       system     -wi-ao----  2.79g
  swap       system     -wi-ao----  1.86g
  tmp        system     -wi-ao----  1.86g
  usr        system     -wi-ao----  1.86g
  var        system     -wi-ao---- 31.72g
  testlv     system     -wi-------  5.00g
  testlv2    system     -wi------- 20.00g

Now we want to remove md0, but before we must move the data to the other physical volume.

~# pvmove /dev/md0
  /dev/md0: Moved: 0.0%
  /dev/md0: Moved: 5.5%
  /dev/md0: Moved: 10.6%
  /dev/md0: Moved: 14.1%
  /dev/md0: Moved: 17.6%
  /dev/md0: Moved: 21.8%
  /dev/md0: Moved: 25.3%
  /dev/md0: Moved: 28.9%
  /dev/md0: Moved: 32.4%
  /dev/md0: Moved: 36.2%
  /dev/md0: Moved: 39.8%
  /dev/md0: Moved: 43.6%
  /dev/md0: Moved: 47.4%
  /dev/md0: Moved: 50.7%
  /dev/md0: Moved: 54.6%
  /dev/md0: Moved: 58.1%
  /dev/md0: Moved: 62.0%
  /dev/md0: Moved: 65.9%
  /dev/md0: Moved: 69.1%
  /dev/md0: Moved: 72.9%
  /dev/md0: Moved: 76.9%
  /dev/md0: Moved: 80.0%
  /dev/md0: Moved: 83.7%
  /dev/md0: Moved: 87.2%
  /dev/md0: Moved: 90.8%
  /dev/md0: Moved: 95.0%
  /dev/md0: Moved: 98.6%
  /dev/md0: Moved: 100.0%

Now we can remove the md0 from the system volume group.

~# vgreduce system /dev/md0
  Removed "/dev/md0" from volume group "system"

Removing lost physical volumes from a volume group

Removing lost physical volumes from a volume group

LVM
LVM

If you get this crazy message and you are lucky that all data are on the other disk, then you can use this steps.

Get the status of the physical volumes:

pvs
  Couldn't find device with uuid Lxx4Mu-37Ie-3Y2d-kXJe-hd6v-ynUI-pa1zxc.
  PV             VG        Fmt  Attr PSize   PFree  
  /dev/sda2      vg_system lvm2 a--u  99.61g   2.93g
  unknown device vg_system lvm2 a-mu 100.00g 100.00g

Get the status of the volume groups:

vgs
  Couldn't find device with uuid Lxx4Mu-37Ie-3Y2d-kXJe-hd6v-ynUI-pa1zxc.
  VG        #PV #LV #SN Attr   VSize   VFree  
  vg_system   2   5   0 wz-pn- 199.60g 102.92g

Get the status of the logical volumes and the devices:

lvs -a -o +devices
  Couldn't find device with uuid Lxx4Mu-37Ie-3Y2d-kXJe-hd6v-ynUI-pa1zxc.
  LV      VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert Devices         
  lv_home vg_system -wi-ao---- 53.71g                                                     /dev/sda2(0)    
  lv_root vg_system -wi-ao---- 14.65g                                                     /dev/sda2(13750)
  lv_swap vg_system -wi-ao----  3.91g                                                     /dev/sda2(17500)
  lv_tmp  vg_system -wi-ao----  4.88g                                                     /dev/sda2(18500)
  lv_var  vg_system -wi-ao---- 19.53g                                                     /dev/sda2(19750)

Now you can use the test option to try to remove the unknown device from the volume group:

vgreduce --test vg_system --removemissing
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
  Couldn't find device with uuid Lxx4Mu-37Ie-3Y2d-kXJe-hd6v-ynUI-pa1zxc.
  Wrote out consistent volume group vg_system

Now remove it and write the change:

vgreduce vg_system --removemissing
  Couldn't find device with uuid Lxx4Mu-37Ie-3Y2d-kXJe-hd6v-ynUI-pa1zxc.
  Wrote out consistent volume group vg_system

You can see the error message is away:

root@tvhvma-psz111: [~]# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_system   1   5   0 wz--n- 99.61g 2.93g

Now you can add the device again.

Add the physical volume:

pvcreate /dev/sdb1 
  Physical volume "/dev/sdb1" successfully created

Show the status from the physical volumes:

pvs
  PV         VG        Fmt  Attr PSize   PFree  
  /dev/sda2  vg_system lvm2 a--u  99.61g   2.93g
  /dev/sdb1            lvm2 ---- 100.00g 100.00g

Show the status from the volume group:

vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_system   1   5   0 wz--n- 99.61g 2.93g

Add the physical volume to the volume group:

vgextend vg_system /dev/sdb1
  Volume group "vg_system" successfully extended

Now you can see the aktiv physical volume:

pvs
  PV         VG        Fmt  Attr PSize   PFree  
  /dev/sda2  vg_system lvm2 a--u  99.61g   2.93g
  /dev/sdb1  vg_system lvm2 a--u 100.00g 100.00g

Show the status from the group and you can see now is more space.

vgs
  VG        #PV #LV #SN Attr   VSize   VFree  
  vg_system   2   5   0 wz--n- 199.60g 102.92g