Linux Logical Volume Management Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Logical Volume Management")
 
No edit summary
Line 2: Line 2:


* [[Linux Logical Volume Management#Subjects|Logical Volume Management]]
* [[Linux Logical Volume Management#Subjects|Logical Volume Management]]
=Overview=
Logical volume management commands can be issued from the <tt>lvm</tt> console, or as standalone commands. For example:
<pre>
lvm> lvs
</pre>
produces identical results to
<pre>
lvs
</pre>
=Inventory of Devices that May Be Used as Physical Volumes=
<pre>
lvmdiskscan
</pre>
Example:
<pre>
[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
</pre>
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)
<pre>
lvmdiskscan -l
</pre>
=Inventory of Physical Volumes=
<pre>
pvs
<pre>
Example:
<pre>
[root@rhel-test ~]# pvs
  PV        VG            Fmt  Attr PSize PFree
  /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 Operations=
Initialize physical volume(s) for use by LVM:
<pre>
pvcreate
</pre>
Change attributes of physical volume:
<pre>
pvchange
</pre>
Resize physical volume:
<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>
=Information about Volume Groups=
<pre>
vgs
</pre>
<pre>
vgdisplay --verbose
</pre>
=Adding Physical Volumes to a Volume Group=
<pre>
vgextend my_volume /dev/hdc1
</pre>
=Information about Logical Volumes=
<pre>
lvs
</pre>
<pre>
lvdisplay --verbose
</pre>
<font color=red>
What does this do:
<pre>
lvscan
</pre>
</font>
=Creating a Logical Volume=
<pre>
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
{{{
    lvm
    lvm> lvrename VolGroup00 LogVol05numbercat lv05
}}}
!!!Removing a Logical Volume
Gather statistics on the free space before removing, and also on the size of the logical volume to be removed:
{{{
vgs
}}}
{{{
lvs 
}}}
Unmount the volume if necessary (or shutdown the service that is using it, as it is the case with Docker):
{{{
umount /dev/VolGroup00/MyLV1
}}}
Remove the logical volume with {{lvremove}}.
The command has a "dry run mode" (-t):
{{{
lvremove /dev/<VG_name>/<LV_name>
}}}
{{{
lvremove -t /dev/<VG_name>/<LV_name>
}}}
Example:
{{{
[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
}}}
This command actually removes it:
{{{
lvremove [-v] /dev/VolGroup00/MyLV1
}}}
<font color=red>
!!!Shrinking the Filesystem and the Logical Volume
This is the simple case, ''it will only work if the logical volume *does not* contain a partition table'':
{{{
      fsadm
}}}
or
{{{
umount lvm_partition
resize2fs /dev/vg/lv newSize
lvresize -L disksize /dev/vg/lv
resize2fs /dev/vg/lv
}}}
</font>
!!!Shrinking a Logical Volume used by a xen Virtual Machine
See [Logical Volume Management And Virtualization|LogicalVolumeManagementAndVirtualization]

Revision as of 02:38, 3 May 2017

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

Inventory of Physical Volumes

pvs
<pre>

Example:

<pre>
[root@rhel-test ~]# pvs
  PV         VG             Fmt  Attr PSize PFree
  /dev/sda2  rhel_rhel-test lvm2 a--  7.51g    0 

Equivalent command with slightly different output:

pvscan

Example:

[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   ]

Details about a Specific Physical Volume

pvdisplay [PhysicalVolumePath [PhysicalVolumePath...]]

Example:

[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

Physical Volume Operations

Initialize physical volume(s) for use by LVM:

pvcreate

Change attributes of physical volume:

pvchange

Resize physical volume:

pvresize

Check the consistency of physical volume:

pvck

Move extents from one physical volume to another:

pvmove

Remove LVM label(s) from physical volume(s)

pvremove

Information about Volume Groups

vgs 
vgdisplay --verbose 

Adding Physical Volumes to a Volume Group

vgextend my_volume /dev/hdc1

Information about Logical Volumes

lvs
lvdisplay --verbose 

What does this do:

lvscan

Creating a Logical Volume

lvm
lvm> lvcreate --size 20G --name santorini VolGroup00

Extending a Logical Volume

http://www.azhowto.com/2009/02/06/how-to-resize-lvm-running-xen-explained-part-1-increase-disk-size

!!!Renaming a Logical Volume

{{{

   lvm 
   lvm> lvrename VolGroup00 LogVol05numbercat lv05

}}}

!!!Removing a Logical Volume

Gather statistics on the free space before removing, and also on the size of the logical volume to be removed:

{{{ vgs }}}

{{{ lvs }}}

Unmount the volume if necessary (or shutdown the service that is using it, as it is the case with Docker):

{{{ umount /dev/VolGroup00/MyLV1 }}}


Remove the logical volume with Template:Lvremove.

The command has a "dry run mode" (-t):

{{{ lvremove /dev/<VG_name>/<LV_name> }}}

{{{ lvremove -t /dev/<VG_name>/<LV_name> }}}

Example:

{{{ [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

}}}

This command actually removes it:

{{{ lvremove [-v] /dev/VolGroup00/MyLV1 }}}

!!!Shrinking the Filesystem and the Logical Volume

This is the simple case, it will only work if the logical volume *does not* contain a partition table:

{{{

     fsadm

}}}

or

{{{ umount lvm_partition resize2fs /dev/vg/lv newSize lvresize -L disksize /dev/vg/lv resize2fs /dev/vg/lv }}}

!!!Shrinking a Logical Volume used by a xen Virtual Machine

See [Logical Volume Management And Virtualization|LogicalVolumeManagementAndVirtualization]