Difference between revisions of "LVM"

From DWIKI
Line 11: Line 11:
*[http://serverfault.com/questions/678642/linux-device-mapper-maps-lvm-pv-nested-inside-lv-when-taking-snapshot LVM nesting]
*[http://serverfault.com/questions/678642/linux-device-mapper-maps-lvm-pv-nested-inside-lv-when-taking-snapshot LVM nesting]
*http://blog.gadi.cc/better-lvm-for-kvm/
*http://blog.gadi.cc/better-lvm-for-kvm/
*[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]


Line 59: Line 59:
==LVM snapshot==
==LVM snapshot==


*https://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in-
*https://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in-


  lvcreate --size 1G --snapshot --name snap-1 /dev/myvg/mylv
  lvcreate --size 1G --snapshot --name snap-1 /dev/myvg/mylv
Line 131: Line 131:
==Create volume group==
==Create volume group==
  vgcreate vgname /dev/sdc1 /dev/sdd1
  vgcreate vgname /dev/sdc1 /dev/sdd1
==Device /dev/sdb excluded by filter==
Try:
  wipefs -af /dev/sdb




[[Category: System Administration]]
[[Category: System Administration]]
[[Category: Linux]]
[[Category: Linux]]

Revision as of 11:58, 24 December 2019

Logical Volume Management on Linux

Link

NOTE: remember to add snapshot support when calling lvcreate

Related commands

lvdisplay

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 left in 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

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

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/

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

Remove physical drive from a volume group

Make sure the data fits on remaining drive, then

pvmove /dev/sdbX
vgreduce /dev/sdbX


Create volume group

vgcreate vgname /dev/sdc1 /dev/sdd1

Device /dev/sdb excluded by filter

Try:

 wipefs -af /dev/sdb