LVM: Difference between revisions

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


=Link=
Logical Volume Management on [[Linux|Linux]]
*[http://www.andybotting.com/how-do-you-clone-an-lvm-partition How do you clone an lvm partition?]
 
*[https://github.com/radiorabe/rabe-zabbix/tree/master/app/LVM Monitoring with zabbix]
= Links =
*[http://tldp.org/HOWTO/LVM-HOWTO/ HOWTO]
 
*[https://www.theurbanpenguin.com/thin-provisioning-lvm2/ Thin provisioning]
*[http://www.andybotting.com/how-do-you-clone-an-lvm-partition How do you clone an lvm partition?]  
*[http://www.howtoforge.com/linux_lvm Beginner's guide to LVM]
*[https://github.com/radiorabe/rabe-zabbix/tree/master/app/LVM Monitoring with zabbix]  
*[http://theitdepartment.wordpress.com/2008/05/30/howto-resize-a-xen-drbd-lvm-vbd/ Resizing LVM + DRBD]
*[http://tldp.org/HOWTO/LVM-HOWTO/ HOWTO]  
*http://wiki.tldp.org/LVM-on-RAID
*[https://www.theurbanpenguin.com/thin-provisioning-lvm2/ Thin provisioning]  
*[http://serverfault.com/questions/678642/linux-device-mapper-maps-lvm-pv-nested-inside-lv-when-taking-snapshot LVM nesting]
*[http://www.howtoforge.com/linux_lvm Beginner's guide to LVM]  
*http://blog.gadi.cc/better-lvm-for-kvm/
*[http://theitdepartment.wordpress.com/2008/05/30/howto-resize-a-xen-drbd-lvm-vbd/ Resizing LVM + DRBD]  
*[https://www.tecmint.com/take-snapshot-of-logical-volume-and-restore-in-
*[http://wiki.tldp.org/LVM-on-RAID http://wiki.tldp.org/LVM-on-RAID]
*[http://tldp.org/HOWTO/LVM-HOWTO/snapshots_backup.html Taking a Backup Using Snapshots]
*[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]  


NOTE: remember to add snapshot support when calling lvcreate
NOTE: remember to add snapshot support when calling lvcreate


=Related commands=
== Raid on LVM ==
==lvdisplay==
*[https://www.theurbanpenguin.com/striped-lvm-volumes/ Striped LVM volumes]
 
= Related commands =
 
== lvdisplay ==
 
== lvrename ==


==lvrename==
  lvrename groupname oldname newname
  lvrename groupname oldname newname
==lsblk==


==partprobe==
== lsblk ==
 
== partprobe ==
 
== lvchange ==


==lvchange==
== vgchange ==


==vgchange==
== dmsetup ==


==dmsetup==
== vgs ==


==vgs==
== create physical volume ==


==create physical volume==
  pvcreate /dev/sda3
  pvcreate /dev/sda3


 
== lvcreate ==


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


==lvresize==  
== lvresize ==
 
  lvresize --resizefs -L-2G /dev/vg/foo
  lvresize --resizefs -L-2G /dev/vg/foo
or grow to all remaining space vg:
or grow to all remaining space vg:
  lvresize -l +100%FREE /dev/myvg/myvol
  lvresize -l +100%FREE /dev/myvg/myvol


==lvremove==
== lvremove ==
 
To remove all volumes in group VGname
To remove all volumes in group VGname
  lvremove VGname
  lvremove VGname


To remove a volume
To remove a volume
  lvremove VGname/LVname
  lvremove VGname/LVname


==pvck==
== pvck ==
 
To find the metadata:
To find the metadata:
  pvck /dev/sdb1
  pvck /dev/sdb1


 


==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- 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 66: Line 86:
where size should be enough to hold the data changes
where size should be enough to hold the data changes


=FAQ=
= FAQ =
==Access logical volumes within logical volume==
 
== Access logical volumes within logical volume ==
 
  partprobe /dev/mapper/vg-mydata
  partprobe /dev/mapper/vg-mydata
  lsblk
  lsblk
This will show the (sub) partitions/volumes, then edit /etc/lvm/lvm.conf
This will show the (sub) partitions/volumes, then edit /etc/lvm/lvm.conf
  filter = [ "a|.*/|", "a|mydata|","r|.*|" ]
  filter = [ "a|.*/|", "a|mydata|","r|.*|" ]
Then run:
Then run:
  vgscan
  vgscan
  lvscan
  lvscan
  vgs
  vgs
Now you should see the names of the volumes you're looking for, so now:
Now you should see the names of the volumes you're looking for, so now:
  vgchange -a y guestsname_mydata-home
  vgchange -a y guestsname_mydata-home
and then you should be able to  
 
and then you should be able to
 
  mount /dev/mapper/guestsname_mydata-home
  mount /dev/mapper/guestsname_mydata-home


When done, remember to change back the filter in lvm.conf, default is  
When done, remember to change back the filter in lvm.conf, default is
 
  filter = [ "a|.*/|" ]
  filter = [ "a|.*/|" ]
and of course then once again
and of course then once again
  vgscan
  vgscan
  lvscan
  lvscan


 
== vgreduce Can't remove final physical volume ==


==vgreduce Can't remove final physical volume==
Means you're trying to remove the last physical volume, instead just use


Means you're trying to remove the last physical volume, instead just use
  vgremove
  vgremove
==grow logical volume==
 
https://www.tldp.org/HOWTO/LVM-HOWTO/extendlv.html
== grow logical volume ==
 
[https://www.tldp.org/HOWTO/LVM-HOWTO/extendlv.html https://www.tldp.org/HOWTO/LVM-HOWTO/extendlv.html]
 
  lvextend -L+100G /dev/myvg/myvol
  lvextend -L+100G /dev/myvg/myvol


==Add disk to volume group==
== Add disk to volume group ==
 
  pvcreate /dev/sdc
  pvcreate /dev/sdc
  vgextend MYVG /dev/sdc
  vgextend MYVG /dev/sdc


And if you need space right now:
And if you need space right now:
  lvextend -l +100%FREE /dev/NYVG/mylv  
  lvextend -l +100%FREE /dev/NYVG/mylv  


And then grow fs
And then grow fs


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


Could be kpartx, see
Could be kpartx, see
  /dev/mapper/
  /dev/mapper/


==lvremove Logical volume foo/bar in use==
== lvremove Logical volume foo/bar in use ==
 
check with lsof, fuser and:
check with lsof, fuser and:
  losetup -l
  losetup -l


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


 


*http://naveen161089.blogspot.nl/2014/03/forcefully-remove-lvm.html
*[http://naveen161089.blogspot.nl/2014/03/forcefully-remove-lvm.html http://naveen161089.blogspot.nl/2014/03/forcefully-remove-lvm.html]


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


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


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


== Grow physical volume ==
== 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
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:
Or just:
  pvresize /dev/sdb
  pvresize /dev/sdb


== Remove physical drive from a volume group ==
== Remove physical drive from a volume group ==
Make sure the data fits on remaining drive, then
Make sure the data fits on remaining drive, then
  pvmove /dev/sdbX
  pvmove /dev/sdbX
  vgreduce vgname /dev/sdbX
  vgreduce vgname /dev/sdbX


==Create volume group==
== Create volume group ==
 
  vgcreate vgname /dev/sdc1 /dev/sdd1
  vgcreate vgname /dev/sdc1 /dev/sdd1


==pvcreate Can't open /dev/sdg exclusively. Mounted filesystem?==
== 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


[https://blog.hqcodeshop.fi/archives/274-Replacing-physical-drive-for-LVM-pvcreate-Cant-open-dev-exclusively.html https://blog.hqcodeshop.fi/archives/274-Replacing-physical-drive-for-LVM-pvcreate-Cant-open-dev-exclusively.html]
 
== Device /dev/sdb excluded by filter ==


==Device /dev/sdb excluded by filter==
Check disk label(gpt!!
Check disk label(gpt!!


Try:


Try:
   wipefs -af /dev/sdg
   wipefs -af /dev/sdg


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


===wipefs: error: /dev/sdg: probing initialization failed: Device or resource busy===
try all ways to unbusy
try all ways to unbusy


==Check if volume is in use==
== Check if volume is in use ==
 
  dmsetup info -c
  dmsetup info -c
Check the 'Open' column
Check the 'Open' column
 
  [[Category:System Administration]] [[Category:Linux]]
[[Category: System Administration]]
[[Category: Linux]]

Revision as of 13:41, 5 November 2020

Logical Volume Management on Linux

Links

NOTE: remember to add snapshot support when calling lvcreate

Raid on LVM

Related commands

lvdisplay

lvrename

lvrename groupname oldname newname

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

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/

 

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 drive, 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

 

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