LVM: Difference between revisions

From DWIKI
mNo edit summary
mNo edit summary
Line 2: Line 2:
Logical Volume Management on [[Linux|Linux]]
Logical Volume Management on [[Linux|Linux]]


 


= Links =
= Links =
Line 16: Line 17:
*[[https://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in- https://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in-]  
*[[https://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in- https://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in-]  
*[http://tldp.org/HOWTO/LVM-HOWTO/snapshots_backup.html Taking a Backup Using Snapshots]  
*[http://tldp.org/HOWTO/LVM-HOWTO/snapshots_backup.html Taking a Backup Using Snapshots]  
*[https://linoxide.com/identify-linux-lvm-mirror/ LVM mirrors]
*[https://linoxide.com/identify-linux-lvm-mirror/ LVM mirrors]  


NOTE: remember to add snapshot support when calling lvcreate
NOTE: remember to add snapshot support when calling lvcreate
Line 29: Line 30:
 
 


 
= LVM Thin provisioning =
== Show some more about thin volumes ==
lvm -a


= Related commands =
= Related commands =
==lvs==


== lvs ==


== lvdisplay ==
== lvdisplay ==
Line 207: Line 215:
 
 


==lvremove Do you really want to remove and DISCARD active logical volume==
== lvremove Do you really want to remove and DISCARD active logical volume ==
 
If you like, deactivate the volume first:
If you like, deactivate the volume first:
  lvchange -an vgname/lvname
  lvchange -an vgname/lvname


 


== Grow physical volume ==
== Grow physical volume ==
Line 222: Line 233:
 
 


 


== Remove physical drive from a volume group ==
== Remove physical drive from a volume group ==
Line 229: Line 241:
  pvmove /dev/sdbX
  pvmove /dev/sdbX


 


  vgreduce vgname /dev/sdbX
  vgreduce vgname /dev/sdbX

Revision as of 09:29, 4 February 2022

Logical Volume Management on Linux

 

Links

NOTE: remember to add snapshot support when calling lvcreate

 

Raid on LVM

 

 

LVM Thin provisioning

Show some more about thin volumes

lvm -a

Related commands

lvs

lvdisplay

lvrename

lvrename groupname oldname newname

vgrename

lsblk

partprobe

lvchange

vgchange

dmsetup

vgs

create physical volume

pvcreate /dev/sda3

 

lvcreate

lvcreate -L12G -nmyvol myvolumegroup
lvcreate -l 100%FREE -nmyvol myvolumegroup

lvresize

lvresize --resizefs -L-2G /dev/vg/foo

or grow to all remaining space vg:

lvresize -l +100%FREE /dev/myvg/myvol

 

 

lvremove

To remove all volumes in group VGname

lvremove VGname

To remove a volume

lvremove VGname/LVname
      

Do you really want to remove active logical volume

lvchange -a n vgname/lvname

just to make sure

 

Logical volume X/Y contains a filesystem in use

https://www.thegeekdiary.com/lvremove-command-fails-with-error-lvm-cant-remove-open-logical-volume/

Could be NFS. Always remember NFS! If NFS has indeed been involved, restarting nfs service will most likely fix this.

pvck

To find the metadata:

pvck /dev/sdb1

 

LVM snapshot

lvcreate --size 1G --snapshot --name snap-1 /dev/myvg/mylv

where size should be enough to hold the data changes

 

FAQ

Access logical volumes within logical volume

partprobe /dev/mapper/vg-mydata
lsblk

This will show the (sub) partitions/volumes, then edit /etc/lvm/lvm.conf

filter = [ "a|.*/|", "a|mydata|","r|.*|" ]

Then run:

vgscan
lvscan
vgs

Now you should see the names of the volumes you're looking for, so now:

vgchange -a y guestsname_mydata-home

and then you should be able to

mount /dev/mapper/guestsname_mydata-home

When done, remember to change back the filter in lvm.conf, default is

filter = [ "a|.*/|" ]

and of course then once again

vgscan
lvscan

 

vgreduce Can't remove final physical volume

Means you're trying to remove the last physical volume, instead just use

vgremove

grow logical volume

https://www.tldp.org/HOWTO/LVM-HOWTO/extendlv.html

lvextend -L+100G /dev/myvg/myvol

Add disk to volume group

pvcreate /dev/sdc
vgextend MYVG /dev/sdc

And if you need space right now:

lvextend -l +100%FREE /dev/NYVG/mylv 

And then grow fs

lvremove: Logical volume vg-kvm/vps-snapshot is used by another device.

Could be kpartx, see

/dev/mapper/

lvremove Logical volume foo/bar in use

check with lsof, fuser and:

losetup -l

to see if a /dev/dm-* looks familiar

 

some say lvchange -an the snapshot first, but that disables the lv it's connected to as well

OR

dmsetup info -c

http://blog.roberthallam.org/2017/12/solved-logical-volume-is-used-by-another-device/comment-page-1/

 

lvremove Do you really want to remove and DISCARD active logical volume

If you like, deactivate the volume first:

lvchange -an vgname/lvname

 

Grow physical volume

Assuming your LVM partition is the last one, use fdisk to delete and recreate it, remember to set type to LVM again and reboot. Then use pvresize /dev/sdaX

Or just:

pvresize /dev/sdb

 

 

Remove physical drive from a volume group

Make sure the data fits on remaining drives, then

pvmove /dev/sdbX

 

vgreduce vgname /dev/sdbX

Create volume group

vgcreate vgname /dev/sdc1 /dev/sdd1

pvcreate Can't open /dev/sdg exclusively. Mounted filesystem?

https://blog.hqcodeshop.fi/archives/274-Replacing-physical-drive-for-LVM-pvcreate-Cant-open-dev-exclusively.html

 

Device /dev/sdb excluded by filter

Check disk label(gpt!!

Try:

 wipefs -af /dev/sdg

 

 

WARNING: Device /dev/dm-17 not initialized in udev database even after waiting 10000000 microseconds.

Try

udevadm trigger

 

wipefs: error: /dev/sdg: probing initialization failed: Device or resource busy

try all ways to unbusy

Check if volume is in use

dmsetup info -c

Check the 'Open' column

WARNING: PV /dev/sda5 in VG foo-vg is using an old PV header, modify the VG to update.

vgck --updatemetadata foo-vg

 

Mount logical volume from disk image

kpartx -av /path/to.img
lvscan
mount /dev/mapper/what-ever-var /mnt/loop