Linux Logical Volume Management Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(45 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=External=


* https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Logical_Volume_Manager_Administration/index.html
* https://www.howtogeek.com/howto/40702/how-to-manage-and-use-lvm-logical-volume-management-in-ubuntu/
* https://www.howtogeek.com/howto/40702/how-to-manage-and-use-lvm-logical-volume-management-in-ubuntu/
* Step by step guide of using LVM with loopback devices https://ops.tips/blog/lvm-on-loopback-devices/


=Internal=
=Internal=
Line 50: Line 52:
</pre>
</pre>


=Physical Volume Operations=
=LVM Configuration=


==Information about Physical Volumes==
* [[lvmconfig]] - displays LVM configuration.


===Inventory of Physical Volumes===
=Physical Volume Operations=


{{Internal|pvs|pvs}}
{{Internal|Linux_Logical_Volume_Management_Concepts#Physical_Volumes_.28PVs.29|Physical Volume Concepts}}


Example:
==Information about Physical Volumes==


<pre>
* <span id='Inventory_of_Physical_Volumes'></span>[[pvs]] - provides information about physical volumes available on the system.
[root@rhel-test ~]# pvs
* [[pvscan]] - scans all disks for physical volumes.
  PV        VG            Fmt  Attr PSize PFree
* <span id='Details_about_a_Specific_Physical_Volume'></span>[[pvdisplay]] - provides details about a specific physical volume.
  /dev/sda2  rhel_rhel-test lvm2 a--  7.51g    0
</pre>
 
Equivalent command with slightly different output:
 
<pre>
pvscan
</pre>
 
Example:
 
<pre>
[root@rhel-test ~]# pvscan
  PV /dev/sda2  VG rhel_rhel-test  lvm2 [7.51 GiB / 0    free]
  Total: 1 [7.51 GiB] / in use: 1 [7.51 GiB] / in no VG: 0 [0  ]
</pre>
 
===Details about a Specific Physical Volume===
 
<pre>
pvdisplay [PhysicalVolumePath [PhysicalVolumePath...]]
</pre>
 
Example:
 
<pre>
[root@rhel-test ~]# pvdisplay /dev/sda2
  --- Physical volume ---
  PV Name              /dev/sda2
  VG Name              rhel_rhel-test
  PV Size              7.51 GiB / not usable 3.00 MiB
  Allocatable          yes (but full)
  PE Size              4.00 MiB
  Total PE              1922
  Free PE              0
  Allocated PE          1922
  PV UUID              xV16At-8wPi-wFp0-42BL-XFX0-5aJE-F471OI
</pre>


==Physical Volume Management Operations==
==Physical Volume Management Operations==


* [[pvcreate#Initialize_Partition_for_use_by_LVM|Initialize physical volume(s) for use by LVM]]
* [[pvcreate#Initialize_Partition_for_use_by_LVM|pvcreate]] - initializes a physical volume(s) for use by LVM.
* [[pvchange]] - changes attributes of a physical volume.
* [[pvresize]] - resizes a disk or partition in use.
* [[pvmove]] - moves physical extents from one physical volume to another.
* [[pvck]] - checks the consistency of the physical volume metadata.
* [[pvremove]] - removes a physical volume.


* Change attributes of physical volume
=Volume Group Operations=
 
<pre>
pvchange
</pre>


* Resize physical volume
{{Internal|Linux_Logical_Volume_Management_Concepts#Volume_Group_.28VG.29|Volume Group Concepts}}
 
<pre>
pvresize
</pre>
 
* Check the consistency of physical volume
 
<pre>
pvck
</pre>
 
* Move extents from one physical volume to another
 
<pre>
pvmove
</pre>
 
* Remove LVM label(s) from physical volume(s)
 
<pre>
pvremove
</pre>
 
=Volume Group Operations=


==Information about Volume Groups==
==Information about Volume Groups==


{{Internal|vgs|vgs}}
* [[vgs]] - reports information about volume groups.
 
* [[vgdisplay]] - display attributes of volume groups.
<pre>
vgdisplay --verbose
</pre>


==Volume Group Management Operations==
==Volume Group Management Operations==


* [[vgcreate#Create_a_Volume_Group|Create a Volume Group]]
* [[vgcreate]] - create a volume group.
* <span id='Adding_Physical_Volumes_to_a_Volume_Group'></span>[[vgextend#Add_Physical_Volumes_to_a_Volume_Group|Add Physical Volumes to a Volume Group]]
* <span id='Adding_Physical_Volumes_to_a_Volume_Group'></span>[[vgextend#Add_Physical_Volumes_to_a_Volume_Group|vgextend]] - add Physical Volumes to a Volume Group.
* [[vgreduce]] - removes one or more unused physical volumes from a volume group.
* [[vgremove]] - deletes a volume group.


=Logical Volume Operations=
=Logical Volume Operations=
{{Internal|Linux_Logical_Volume_Management_Concepts#Logical_Volume_.28LV.29|Logical Volume}}


==Information about Logical Volumes==
==Information about Logical Volumes==


{{Internal|lvs|lvs}}
* [[lvs]] - provides information about logical volumes available on the system.
 
* [[lvdisplay]] - displays attributes of a logical volume.
<pre>
* [[lvscan]] - scans all known volume groups or all supported LVM block devices in the system for defined Logical Volumes.
lvdisplay --verbose
</pre>
 
<tt>lvscan</tt> scan all known volume groups or all supported LVM block devices in the system for defined Logical Volumes.
<pre>
lvscan
</pre>
</font>


==Logical Volume Management Operations==
==Logical Volume Management Operations==


===Creating a Logical Volume===
* <span id='Creating_a_Logical_Volume'></span>[[lvcreate]] - creates a logical volume in an existing volume group.
* <span id='Extending_a_Logical_Volume'></span>[[lvresize]] - resize a logical volume.
* <span id='Renaming_a_Logical_Volume'>[[lvrename]]
* [[lvchange]]
* <span id='Remove_a_Logical_Volume'><span id='Removing_a_Logical_Volume'>[[lvremove]] - removes a logical volume from a volume group.


<pre>
=Procedures=
lvm
lvm> lvcreate --size 20G --name santorini VolGroup00
</pre>
 
===Extending a Logical Volume===
 
{{External|http://www.azhowto.com/2009/02/06/how-to-resize-lvm-running-xen-explained-part-1-increase-disk-size}}


===Renaming a Logical Volume===
* [[Provisioning and Installing a New Filesystem on a New Logical Volume]]
* <span id='Shrinking_the_Filesystem_and_the_Logical_Volume'></span>[[Shringking a File System on a Logical Volume]]
* <span id='Shrinking_a_Logical_Volume_used_by_a_xen_Virtual_Machine'></span>[[Logical Volume Management and Virtualization|Logical Volume Management and Virtualization]]
* [[Provision Docker Storage on a Dedicated Block Device|Provision Thin Pool Strorage for Docker on a Dedicated Block Device]]


<pre>
=Troubleshooting=
lvm
lvm> lvrename VolGroup00 LogVol05numbercat lv05
</pre>


* View LVM logs:


===Remove a Logical Volume===
journalctl -u dm-event.service
<span id='Removing_a_Logical_Volume'></span>
 
Gather statistics on the free space before removing, and also on the size of the logical volume to be removed:
 
<pre>
vgs
</pre>
 
<pre>
lvs 
</pre>
 
Unmount the volume if necessary (or shutdown the service that is using it, as it is the case with Docker):
 
<pre>
umount /dev/VolGroup00/MyLV1
</pre>
 
Remove the logical volume with <tt>lvremove</tt>.
 
The command has a "dry run mode" (-t):
 
<pre>
lvremove /dev/<VG_name>/<LV_name>
</pre>
 
<pre>
lvremove -t /dev/<VG_name>/<LV_name>
</pre>
 
Example:
 
<pre>
[root@rhel-test lvm]# lvremove -t /dev/rhel_rhel-test/docker-pool
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
Do you really want to remove active logical volume docker-pool? [y/n]: y
  Logical volume "docker-pool" successfully removed
</pre>
 
This command actually removes it:
 
<pre>
lvremove [-v] /dev/VolGroup00/MyLV1
</pre>
 
=Shrinking the Filesystem and the Logical Volume=
 
<font color=red>
This is the simple case, ''it will only work if the logical volume *does not* contain a partition table'':
 
<pre>
fsadm
</pre>
 
or
 
<pre>
umount lvm_partition
resize2fs /dev/vg/lv newSize
lvresize -L disksize /dev/vg/lv
resize2fs /dev/vg/lv
</pre>
</font>


=Shrinking a Logical Volume used by a xen Virtual Machine=
* Block devices:


{{Internal|Logical Volume Management and Virtualization|Logical Volume Management and Virtualization}}
[[lsblk]]

Latest revision as of 23:20, 13 February 2018

External

Internal

Overview

Logical volume management commands can be issued from the lvm console, or as standalone commands. For example:

lvm> lvs

produces identical results to

lvs

Inventory of Devices that May Be Used as Physical Volumes

lvmdiskscan

Example:

[root@rhel-test ~]# lvmdiskscan
  /dev/rhel_rhel-test/swap [     820.00 MiB] 
  /dev/sda1                [     500.00 MiB] 
  /dev/rhel_rhel-test/root [       6.67 GiB] 
  /dev/sda2                [       7.51 GiB] LVM physical volume
  /dev/sdb                 [       2.00 GiB] 
  3 disks
  1 partition
  0 LVM physical volume whole disks
  1 LVM physical volume

The output specifies which device is already a LVM Physical Volume

To see only the existing Physical Volumes (devices that have Volume Groups on them)

lvmdiskscan -l

LVM Configuration

Physical Volume Operations

Physical Volume Concepts

Information about Physical Volumes

  • pvs - provides information about physical volumes available on the system.
  • pvscan - scans all disks for physical volumes.
  • pvdisplay - provides details about a specific physical volume.

Physical Volume Management Operations

  • pvcreate - initializes a physical volume(s) for use by LVM.
  • pvchange - changes attributes of a physical volume.
  • pvresize - resizes a disk or partition in use.
  • pvmove - moves physical extents from one physical volume to another.
  • pvck - checks the consistency of the physical volume metadata.
  • pvremove - removes a physical volume.

Volume Group Operations

Volume Group Concepts

Information about Volume Groups

  • vgs - reports information about volume groups.
  • vgdisplay - display attributes of volume groups.

Volume Group Management Operations

  • vgcreate - create a volume group.
  • vgextend - add Physical Volumes to a Volume Group.
  • vgreduce - removes one or more unused physical volumes from a volume group.
  • vgremove - deletes a volume group.

Logical Volume Operations

Logical Volume

Information about Logical Volumes

  • lvs - provides information about logical volumes available on the system.
  • lvdisplay - displays attributes of a logical volume.
  • lvscan - scans all known volume groups or all supported LVM block devices in the system for defined Logical Volumes.

Logical Volume Management Operations

Procedures

Troubleshooting

  • View LVM logs:
journalctl -u dm-event.service
  • Block devices:
lsblk