Setting the Partition Type
If you are using a whole disk device for your physical volume, the disk must have no partition table. For DOS disk partitions, the partition id should be set to 0x8e using the
fdisk
or cfdisk
command or an equivalent. For whole disk devices only the partition table must be erased, which will effectively destroy all data on that disk. You can remove an existing partition table by zeroing the first sector with the following command:# dd if=/dev/zero of=PhysicalVolume
bs=512 count=1
Initializing Physical Volumes
Use the
pvcreate
command to initialize a block device to be used as a physical volume. Initialization is analogous to formatting a file system.
The following command initializes
/dev/sdd
, /dev/sde
, and /dev/sdf
as LVM physical volumes for later use as part of LVM logical volumes.# pvcreate /dev/sdd /dev/sde /dev/sdf
To initialize partitions rather than whole disks: run the
pvcreate
command on the partition. The following example initializes the partition /dev/hdb1
as an LVM physical volume for later use as part of an LVM logical volume.# pvcreate /dev/hdb1
Scanning for Block Devices
You can scan for block devices that may be used as physical volumes with the
lvmdiskscan
command, as shown in the following example.# lvmdiskscan
/dev/ram0 [ 16.00 MB]
/dev/sda [ 17.15 GB]
/dev/root [ 13.69 GB]
/dev/ram [ 16.00 MB]
/dev/sda1 [ 17.14 GB] LVM physical volume
/dev/VolGroup00/LogVol01 [ 512.00 MB]
/dev/ram2 [ 16.00 MB]
/dev/new_vg/lvol0 [ 52.00 MB]
/dev/ram3 [ 16.00 MB]
/dev/pkl_new_vg/sparkie_lv [ 7.14 GB]
/dev/ram4 [ 16.00 MB]
/dev/ram5 [ 16.00 MB]
/dev/ram6 [ 16.00 MB]
/dev/ram7 [ 16.00 MB]
/dev/ram8 [ 16.00 MB]
/dev/ram9 [ 16.00 MB]
/dev/ram10 [ 16.00 MB]
/dev/ram11 [ 16.00 MB]
/dev/ram12 [ 16.00 MB]
/dev/ram13 [ 16.00 MB]
/dev/ram14 [ 16.00 MB]
/dev/ram15 [ 16.00 MB]
/dev/sdb [ 17.15 GB]
/dev/sdb1 [ 17.14 GB] LVM physical volume
/dev/sdc [ 17.15 GB]
/dev/sdc1 [ 17.14 GB] LVM physical volume
/dev/sdd [ 17.15 GB]
/dev/sdd1 [ 17.14 GB] LVM physical volume
7 disks
17 partitions
0 LVM physical volume whole disks
4 LVM physical volumes
Displaying Physical Volumes
There are three commands you can use to display properties of LVM physical volumes:
pvs
, pvdisplay
, and pvscan
.
The
pvs
command provides physical volume information in a configurable form, displaying one line per physical volume. The pvs
command provides a great deal of format control, and is useful for scripting.
The
pvdisplay
command provides a verbose multi-line output for each physical volume. It displays physical properties (size, extents, volume group, etc.) in a fixed format.
The following example shows the output of the
pvdisplay
command for a single physical volume.# pvdisplay --- Physical volume --- PV Name /dev/sdc1 VG Name new_vg PV Size 17.14 GB / not usable 3.40 MB Allocatable yes PE Size (KByte) 4096 Total PE 4388 Free PE 4375 Allocated PE 13 PV UUID Joqlch-yWSj-kuEn-IdwM-01S9-XO8M-mcpsVe
The
pvscan
command scans all supported LVM block devices in the system for physical volumes.
The following command shows all physical devices found:
# pvscan
PV /dev/sdb2 VG vg0 lvm2 [964.00 MB / 0 free]
PV /dev/sdc1 VG vg0 lvm2 [964.00 MB / 428.00 MB free]
PV /dev/sdc2 lvm2 [964.84 MB]
Total: 3 [2.83 GB] / in use: 2 [1.88 GB] / in no VG: 1 [964.84 MB]
Preventing Allocation on a Physical Volume
You can prevent allocation of physical extents on the free space of one or more physical volumes with the
pvchange
command. This may be necessary if there are disk errors, or if you will be removing the physical volume.
The following command disallows the allocation of physical extents on
/dev/sdk1
.# pvchange -x n /dev/sdk1
You can also use the
-xy
arguments of the pvchange
command to allow allocation where it had previously been disallowed.Resizing a Physical Volume
If you need to change the size of an underlying block device for any reason, use the
pvresize
command to update LVM with the new size. You can execute this command while LVM is using the physical volume.# pvremove /dev/ram15
Labels on physical volume "/dev/ram15" successfully wiped
Volume Group Administration
reating Volume Groups
To create a volume group from one or more physical volumes, use the
vgcreate
command. Thevgcreate
command creates a new volume group by name and adds at least one physical volume to it.
The following command creates a volume group named
vg1
that contains physical volumes /dev/sdd1
and /dev/sde1
.# vgcreate vg1 /dev/sdd1 /dev/sde1
When physical volumes are used to create a volume group, its disk space is divided into 4 MB extents, by default. This extent is the minimum amount by which the logical volume may be increased or decreased in size.
Creating Volume Groups in a Cluster
You create volume groups in a cluster environment with the
vgcreate
command, just as you create them on a single node.
By default, volume groups created with CLVM on shared storage are visible to all computers that have access to the shared storage. It is possible, however, to create volume groups that are local, visible only to one node in the cluster, by using the
-c n
of the vgcreate
command.
The following command, when executed in a cluster environment, creates a volume group that is local to the node from which the command was executed. The command creates a local volume named
vg1
that contains physical volumes /dev/sdd1
and /dev/sde1
.# vgcreate -c n vg1 /dev/sdd1 /dev/sde1
You can change whether an existing volume group is local or clustered with the
-c
option of the vgchange
command
You can check whether an existing volume group is a clustered volume group with the
vgs
command, which displays the c
attribute if the volume is clustered. The following command displays the attributes of the volume groups VolGroup00
and testvg1
. In this example, VolGroup00
is not clustered, while testvg1
is clustered, as indicated by the c
attribute under the Attr
heading.# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 1 2 0 wz--n- 19.88G 0
testvg1 1 1 0 wz--nc 46.00G 8.00M
Adding Physical Volumes to a Volume Group
To add additional physical volumes to an existing volume group, use the
vgextend
command. The vgextend
command increases a volume group's capacity by adding one or more free physical volumes.
The following command adds the physical volume
/dev/sdf1
to the volume group vg1
.# vgextend vg1 /dev/sdf1
Displaying Volume Groups
There are two commands you can use to display properties of LVM volume groups:
vgs
and vgdisplay
.
The
vgscan
command, which scans all the disks for volume groups and rebuilds the LVM cache file, also displays the volume groups.
The
vgs
command provides volume group information in a configurable form, displaying one line per volume group. The vgs
command provides a great deal of format control, and is useful for scripting.
The
vgdisplay
command displays volume group properties (such as size, extents, number of physical volumes, etc.) in a fixed form. The following example shows the output of a vgdisplay
command for the volume group new_vg
. If you do not specify a volume group, all existing volume groups are displayed.# vgdisplay new_vg
--- Volume group ---
VG Name new_vg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 11
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 51.42 GB
PE Size 4.00 MB
Total PE 13164
Alloc PE / Size 13 / 52.00 MB
Free PE / Size 13151 / 51.37 GB
VG UUID jxQJ0a-ZKk0-OpMO-0118-nlwO-wwqd-fD5D32
Scanning Disks for Volume Groups to Build the Cache File
The vgscan
command scans all supported disk devices in the system looking for LVM physical volumes and volume groups. This builds the LVM cache in the /etc/lvm/.cache
file, which maintains a listing of current LVM devices.
LVM runs the vgscan
command automatically at system startup and at other times during LVM operation, such as when you execute a vgcreate
command or when LVM detects an inconsistency.
You may need to run the vgscan
command manually when you change your hardware configuration and add or delete a device from a node, causing new devices to be visible to the system that were not present at system bootup. This may be necessary, for example, when you add new disks to the system on a SAN or hotplug a new disk that has been labeled as a physical volume.
The following example shows the output of a vgscan
command.
# vgscan
Reading all physical volumes. This may take a while...
Found volume group "new_vg" using metadata type lvm2
Found volume group "officevg" using metadata type lvm2
vgscan
command scans all supported disk devices in the system looking for LVM physical volumes and volume groups. This builds the LVM cache in the /etc/lvm/.cache
file, which maintains a listing of current LVM devices.vgscan
command automatically at system startup and at other times during LVM operation, such as when you execute a vgcreate
command or when LVM detects an inconsistency.vgscan
command manually when you change your hardware configuration and add or delete a device from a node, causing new devices to be visible to the system that were not present at system bootup. This may be necessary, for example, when you add new disks to the system on a SAN or hotplug a new disk that has been labeled as a physical volume.
The following example shows the output of a
vgscan
command.# vgscan
Reading all physical volumes. This may take a while...
Found volume group "new_vg" using metadata type lvm2
Found volume group "officevg" using metadata type lvm2
Removing Physical Volumes from a Volume Group
To remove unused physical volumes from a volume group, use the vgreduce
command. The vgreduce
command shrinks a volume group's capacity by removing one or more empty physical volumes. This frees those physical volumes to be used in different volume groups or to be removed from the system.
Before removing a physical volume from a volume group, you can make sure that the physical volume is not used by any logical volumes by using the pvdisplay
command.
# pvdisplay /dev/hda1
-- Physical volume ---
PV Name /dev/hda1
VG Name myvg
PV Size 1.95 GB / NOT usable 4 MB [LVM: 122 KB]
PV# 1
PV Status available
Allocatable yes (but full)
Cur LV 1
PE Size (KByte) 4096
Total PE 499
Free PE 0
Allocated PE 499
PV UUID Sd44tK-9IRw-SrMC-MOkn-76iP-iftz-OVSen7
If the physical volume is still being used you will have to migrate the data to another physical volume using the pvmove
command. Then use the vgreduce
command to remove the physical volume:
The following command removes the physical volume /dev/hda1
from the volume group my_volume_group
.
# vgreduce my_volume_group /dev/hda1
To remove unused physical volumes from a volume group, use the
vgreduce
command. The vgreduce
command shrinks a volume group's capacity by removing one or more empty physical volumes. This frees those physical volumes to be used in different volume groups or to be removed from the system.
Before removing a physical volume from a volume group, you can make sure that the physical volume is not used by any logical volumes by using the
pvdisplay
command.# pvdisplay /dev/hda1 -- Physical volume --- PV Name /dev/hda1 VG Name myvg PV Size 1.95 GB / NOT usable 4 MB [LVM: 122 KB] PV# 1 PV Status available Allocatable yes (but full) Cur LV 1 PE Size (KByte) 4096 Total PE 499 Free PE 0 Allocated PE 499 PV UUID Sd44tK-9IRw-SrMC-MOkn-76iP-iftz-OVSen7
If the physical volume is still being used you will have to migrate the data to another physical volume using the
pvmove
command. Then use the vgreduce
command to remove the physical volume:
The following command removes the physical volume
/dev/hda1
from the volume group my_volume_group
.# vgreduce my_volume_group /dev/hda1
Changing the Parameters of a Volume Group
The
vgchange
command is used to deactivate and activate volume groups. You can also use this command to change several volume group parameters for an existing volume group.
The following command changes the maximum number of logical volumes of volume group
vg00
to 128.# vgchange -l 128 /dev/vg00
For a description of the volume group parameters you can change with the
vgchange
command, see the vgchange
(8) man page.Activating and Deactivating Volume Groups
When you create a volume group it is, by default, activated. This means that the logical volumes in that group are accessible and subject to change.
There are various circumstances for which you need to make a volume group inactive and thus unknown to the kernel. To deactivate or activate a volume group, use the -a
(--available
) argument of the vgchange
command.
The following example deactivates the volume group my_volume_group
.
# vgchange -a n my_volume_group
If clustered locking is enabled, add ’e’ to activate or deactivate a volume group exclusively on one node or ’l’ to activate or/deactivate a volume group only on the local node. Logical volumes with single-host snapshots are always activated exclusively because they can only be used on one node at once.
-a
(--available
) argument of the vgchange
command.my_volume_group
.Removing Volume Groups
Splitting a Volume Group
To split the physical volumes of a volume group and create a new volume group, use the vgsplit
command.
Logical volumes cannot be split between volume groups. Each existing logical volume must be entirely on the physical volumes forming either the old or the new volume group. If necessary, however, you can use the pvmove
command to force the split.
The following example splits off the new volume group smallvg
from the original volume groupbigvg
.
# vgsplit bigvg smallvg /dev/ram15
Volume group "smallvg" successfully split from "bigvg"
To split the physical volumes of a volume group and create a new volume group, use the
vgsplit
command.
Logical volumes cannot be split between volume groups. Each existing logical volume must be entirely on the physical volumes forming either the old or the new volume group. If necessary, however, you can use the
pvmove
command to force the split.
The following example splits off the new volume group
smallvg
from the original volume groupbigvg
.# vgsplit bigvg smallvg /dev/ram15
Volume group "smallvg" successfully split from "bigvg"
Combining Volume Groups
To combine two volume groups into a single volume group, use the vgmerge
command. You can merge an inactive "source" volume with an active or an inactive "destination" volume if the physical extent sizes of the volume are equal and the physical and logical volume summaries of both volume groups fit into the destination volume groups limits.
The following command merges the inactive volume group my_vg
into the active or inactive volume group databases
giving verbose runtime information.
# vgmerge -v databases my_vg
To combine two volume groups into a single volume group, use the
vgmerge
command. You can merge an inactive "source" volume with an active or an inactive "destination" volume if the physical extent sizes of the volume are equal and the physical and logical volume summaries of both volume groups fit into the destination volume groups limits.
The following command merges the inactive volume group
my_vg
into the active or inactive volume group databases
giving verbose runtime information.# vgmerge -v databases my_vg
Backing Up Volume Group Metadata
Metadata backups and archives are automatically created on every volume group and logical volume configuration change unless disabled in the lvm.conf
file. By default, the metadata backup is stored in the /etc/lvm/backup
file and the metadata archives are stored in the /etc/lvm/archives
file. You can manually back up the metadata to the /etc/lvm/backup
file with the vgcfgbackup
command.
The vgcfrestore
command restores the metadata of a volume group from the archive to all the physical volumes in the volume groups.
Metadata backups and archives are automatically created on every volume group and logical volume configuration change unless disabled in the
lvm.conf
file. By default, the metadata backup is stored in the /etc/lvm/backup
file and the metadata archives are stored in the /etc/lvm/archives
file. You can manually back up the metadata to the /etc/lvm/backup
file with the vgcfgbackup
command.
The
vgcfrestore
command restores the metadata of a volume group from the archive to all the physical volumes in the volume groups.Renaming a Volume Group
Moving a Volume Group to Another System
You can move an entire LVM volume group to another system. It is recommended that you use thevgexport
and vgimport
commands when you do this.
The vgexport
command makes an inactive volume group inaccessible to the system, which allows you to detach its physical volumes. The vgimport
command makes a volume group accessible to a machine again after the vgexport
command has made it inactive.
To move a volume group form one system to another, perform the following steps:
-
Make sure that no users are accessing files on the active volumes in the volume group, then unmount the logical volumes.
-
Use the
-a n
argument of the vgchange
command to mark the volume group as inactive, which prevents any further activity on the volume group.
-
Use the
vgexport
command to export the volume group. This prevents it from being accessed by the system from which you are removing it.
After you export the volume group, the physical volume will show up as being in an exported volume group when you execute the pvscan
command, as in the following example.
# pvscan
PV /dev/sda1 is in exported VG myvg [17.15 GB / 7.15 GB free]
PV /dev/sdc1 is in exported VG myvg [17.15 GB / 15.15 GB free]
PV /dev/sdd1 is in exported VG myvg [17.15 GB / 15.15 GB free]
...
When the system is next shut down, you can unplug the disks that constitute the volume group and connect them to the new system.
-
When the disks are plugged into the new system, use the
vgimport
command to import the volume group, making it accessible to the new system.
-
Activate the volume group with the
-a y
argument of the vgchange
command.
-
Mount the file system to make it available for use.
You can move an entire LVM volume group to another system. It is recommended that you use the
vgexport
and vgimport
commands when you do this.
The
vgexport
command makes an inactive volume group inaccessible to the system, which allows you to detach its physical volumes. The vgimport
command makes a volume group accessible to a machine again after the vgexport
command has made it inactive.
To move a volume group form one system to another, perform the following steps:
- Make sure that no users are accessing files on the active volumes in the volume group, then unmount the logical volumes.
- Use the
-a n
argument of thevgchange
command to mark the volume group as inactive, which prevents any further activity on the volume group. - Use the
vgexport
command to export the volume group. This prevents it from being accessed by the system from which you are removing it.After you export the volume group, the physical volume will show up as being in an exported volume group when you execute thepvscan
command, as in the following example.# pvscan PV /dev/sda1 is in exported VG myvg [17.15 GB / 7.15 GB free] PV /dev/sdc1 is in exported VG myvg [17.15 GB / 15.15 GB free] PV /dev/sdd1 is in exported VG myvg [17.15 GB / 15.15 GB free] ...
When the system is next shut down, you can unplug the disks that constitute the volume group and connect them to the new system. - When the disks are plugged into the new system, use the
vgimport
command to import the volume group, making it accessible to the new system. - Activate the volume group with the
-a y
argument of thevgchange
command. - Mount the file system to make it available for use.
Recreating a Volume Group Directory
To recreate a volume group directory and logical volume special files, use the vgmknodes
command. This command checks the LVM2 special files in the /dev
directory that are needed for active logical volumes. It creates any special files that are missing removes unused ones.
You can incorporate the vgmknodes
command into the vgscan
command by specifying the mknodes
argument to the vgscan
command.
To recreate a volume group directory and logical volume special files, use the
vgmknodes
command. This command checks the LVM2 special files in the /dev
directory that are needed for active logical volumes. It creates any special files that are missing removes unused ones.
You can incorporate the
vgmknodes
command into the vgscan
command by specifying the mknodes
argument to the vgscan
command.Logical Volume Administration
Creating Logical Volumes
To create a logical volume, use the
lvcreate
command. You can create linear volumes, striped volumes, and mirrored volumes, as described in the following subsections.
If you do not specify a name for the logical volume, the default name
lvol#
is used where #
is the internal number of the logical volume.Creating Linear Volumes
When you create a logical volume, the logical volume is carved from a volume group using the free extents on the physical volumes that make up the volume group. Normally logical volumes use up any space available on the underlying physical volumes on a next-free basis. Modifying the logical volume frees and reallocates space in the physical volumes.
The following command creates a logical volume 10 gigabytes in size in the volume group
vg1
.# lvcreate -L 10G vg1
The following command creates a 1500 MB linear logical volume named testlv
in the volume group testvg
, creating the block device /dev/testvg/testlv
.
# lvcreate -L1500 -n testlv testvg
The following command creates a 50 gigabyte logical volume named gfslv
from the free extents in volume group vg0
.
# lvcreate -L 50G -n gfslv vg0
You can use the -l
argument of the lvcreate
command to specify the size of the logical volume in extents. You can also use this argument to specify the percentage of the volume group to use for the logical volume. The following command creates a logical volume called mylv
that uses 60% of the total space in volume group testvg
.
# lvcreate -l 60%VG -n mylv testvg
You can also use the -l
argument of the lvcreate
command to specify the percentage of the remaining free space in a volume group as the size of the logical volume. The following command creates a logical volume called yourlv
that uses all of the unallocated space in the volume group testvg
.
# lvcreate -l 100%FREE -n yourlv testvg
You can use -l
argument of the lvcreate
command to create a logical volume that uses the entire volume group. Another way to create a logical volume that uses the entire volume group is to use the vgdisplay
command to find the "Total PE" size and to use those results as input to the lvcreate
command.
The following commands create a logical volume called mylv
that fills the volume group named testvg
.
# vgdisplay testvg | grep "Total PE"
Total PE 10230
# lvcreate -l 10230 testvg -n mylv
To create a logical volume to be allocated from a specific physical volume in the volume group, specify the physical volume or volumes at the end at the lvcreate
command line. The following command creates a logical volume named testlv
in volume group testvg
allocated from the physical volume /dev/sdg1
,
# lvcreate -L 1500 -ntestlv testvg /dev/sdg1
You can specify which extents of a physical volume are to be used for a logical volume. The following example creates a linear logical volume out of extents 0 through 24 of physical volume /dev/sda1
and extents 50 through 124 of physical volume /dev/sdb1
in volume group testvg
.
# lvcreate -l 100 -n testlv testvg /dev/sda1:0-24 /dev/sdb1:50-124
The following example creates a linear logical volume out of extents 0 through 24 of physical volume /dev/sda1
and then continues laying out the logical volume at extent 100.
# lvcreate -l 100 -n testlv testvg /dev/sda1:0-24:100-
The default policy for how the extents of a logical volume are allocated is inherit
, which applies the same policy as for the volume group. These policies can be changed using the lvchange
command.
The following command creates a 1500 MB linear logical volume named
testlv
in the volume group testvg
, creating the block device /dev/testvg/testlv
.# lvcreate -L1500 -n testlv testvg
The following command creates a 50 gigabyte logical volume named
gfslv
from the free extents in volume group vg0
.# lvcreate -L 50G -n gfslv vg0
You can use the
-l
argument of the lvcreate
command to specify the size of the logical volume in extents. You can also use this argument to specify the percentage of the volume group to use for the logical volume. The following command creates a logical volume called mylv
that uses 60% of the total space in volume group testvg
.# lvcreate -l 60%VG -n mylv testvg
You can also use the
-l
argument of the lvcreate
command to specify the percentage of the remaining free space in a volume group as the size of the logical volume. The following command creates a logical volume called yourlv
that uses all of the unallocated space in the volume group testvg
.# lvcreate -l 100%FREE -n yourlv testvg
You can use
-l
argument of the lvcreate
command to create a logical volume that uses the entire volume group. Another way to create a logical volume that uses the entire volume group is to use the vgdisplay
command to find the "Total PE" size and to use those results as input to the lvcreate
command.
The following commands create a logical volume called
mylv
that fills the volume group named testvg
.# vgdisplay testvg | grep "Total PE"
Total PE 10230
# lvcreate -l 10230 testvg -n mylv
To create a logical volume to be allocated from a specific physical volume in the volume group, specify the physical volume or volumes at the end at the
lvcreate
command line. The following command creates a logical volume named testlv
in volume group testvg
allocated from the physical volume /dev/sdg1
,# lvcreate -L 1500 -ntestlv testvg /dev/sdg1
You can specify which extents of a physical volume are to be used for a logical volume. The following example creates a linear logical volume out of extents 0 through 24 of physical volume
/dev/sda1
and extents 50 through 124 of physical volume /dev/sdb1
in volume group testvg
.# lvcreate -l 100 -n testlv testvg /dev/sda1:0-24 /dev/sdb1:50-124
The following example creates a linear logical volume out of extents 0 through 24 of physical volume
/dev/sda1
and then continues laying out the logical volume at extent 100.# lvcreate -l 100 -n testlv testvg /dev/sda1:0-24:100-
The default policy for how the extents of a logical volume are allocated is
inherit
, which applies the same policy as for the volume group. These policies can be changed using the lvchange
command.Creating Striped Volumes
For large sequential reads and writes, creating a striped logical volume can improve the efficiency of the data I/O.
When you create a striped logical volume, you specify the number of stripes with the -i
argument of the lvcreate
command. This determines over how many physical volumes the logical volume will be striped. The number of stripes cannot be greater than the number of physical volumes in the volume group (unless the --alloc anywhere
argument is used).
If the underlying physical devices that make up a striped logical volume are different sizes, the maximum size of the striped volume is determined by the smallest underlying device. For example, in a two-legged stripe, the maximum size is twice the size of the smaller device. In a three-legged stripe, the maximum size is three times the size of the smallest device.
The following command creates a striped logical volume across 2 physical volumes with a stripe of 64kB. The logical volume is 50 gigabytes in size, is named gfslv
, and is carved out of volume group vg0
.
# lvcreate -L 50G -i2 -I64 -n gfslv vg0
As with linear volumes, you can specify the extents of the physical volume that you are using for the stripe. The following command creates a striped volume 100 extents in size that stripes across two physical volumes, is named stripelv
and is in volume group testvg
. The stripe will use sectors 0-49 of /dev/sda1
and sectors 50-99 of /dev/sdb1
.
# lvcreate -l 100 -i2 -nstripelv testvg /dev/sda1:0-49 /dev/sdb1:50-99
Using default stripesize 64.00 KB
Logical volume "stripelv" created
For large sequential reads and writes, creating a striped logical volume can improve the efficiency of the data I/O.
When you create a striped logical volume, you specify the number of stripes with the
-i
argument of the lvcreate
command. This determines over how many physical volumes the logical volume will be striped. The number of stripes cannot be greater than the number of physical volumes in the volume group (unless the --alloc anywhere
argument is used).
If the underlying physical devices that make up a striped logical volume are different sizes, the maximum size of the striped volume is determined by the smallest underlying device. For example, in a two-legged stripe, the maximum size is twice the size of the smaller device. In a three-legged stripe, the maximum size is three times the size of the smallest device.
The following command creates a striped logical volume across 2 physical volumes with a stripe of 64kB. The logical volume is 50 gigabytes in size, is named
gfslv
, and is carved out of volume group vg0
.# lvcreate -L 50G -i2 -I64 -n gfslv vg0
As with linear volumes, you can specify the extents of the physical volume that you are using for the stripe. The following command creates a striped volume 100 extents in size that stripes across two physical volumes, is named
stripelv
and is in volume group testvg
. The stripe will use sectors 0-49 of /dev/sda1
and sectors 50-99 of /dev/sdb1
.# lvcreate -l 100 -i2 -nstripelv testvg /dev/sda1:0-49 /dev/sdb1:50-99
Using default stripesize 64.00 KB
Logical volume "stripelv" created
Creating Mirrored Volumes
When you create a mirrored volume, you specify the number of copies of the data to make with the
-m
argument of the lvcreate
command. Specifying -m1
creates one mirror, which yields two copies of the file system: a linear logical volume plus one copy. Similarly, specifying -m2
creates two mirrors, yielding three copies of the file system.
The following command creates a mirrored logical volume with a single mirror. The volume is 50 gigabytes in size, is named
mirrorlv
, and is carved out of volume group vg0
:# lvcreate -L 50G -m1 -n mirrorlv vg0
An LVM mirror divides the device being copied into regions that, by default, are 512KB in size. You can use the
-R
argument of the lvcreate
command to specify the region size in megabytes. You can also change the default region size by editing the mirror_region_size
setting in the lvm.conf
file.
When a mirror is created, the mirror regions are synchronized. For large mirror components, the sync process may take a long time. When you are creating a new mirror that does not need to be revived, you can specify the
--nosync
argument to indicate that an initial synchronization from the first device is not required.
LVM maintains a small log which it uses to keep track of which regions are in sync with the mirror or mirrors. By default, this log is kept on disk, which keeps it persistent across reboots. You can specify instead that this log be kept in memory with the
--corelog
argument; this eliminates the need for an extra log device, but it requires that the entire mirror be resynchronized at every reboot.
The following command creates a mirrored logical volume from the volume group
bigvg
. The logical is named ondiskmirvol
and has a single mirror. The volume is 12 MB in size and keeps the mirror log in memory.# lvcreate -L 12MB -m1 --corelog -n ondiskmirvol bigvg Logical volume "ondiskmirvol" created
The mirror log is created on a separate device from the devices on which any of the mirror legs are created. It is possible, however, to create the mirror log on the same device as one of the mirror legs by using the
--alloc anywhere
argument of the vgcreate
command. This may degrade performance, but it allows you to create a mirror even if you have only two underlying devices.
The following command creates a mirrored logical volume with a single mirror for which the mirror log is on the same device as one of the mirror legs. In this example, the volume group
vg0
consists of only two devices. This command creates a 500 MB volume named mirrorlv
in the vg0
volume group.# lvcreate -L 500M -m1 -n mirrorlv -alloc anywhere vg0
Mirroring the Mirror Log
To create a mirror log that is itself mirrored, you can specify the --mirrorlog mirrored
argument. The following command creates a mirrored logical volume from the volume group bigvg
. The logical volume is named twologvol
and has a single mirror. The volume is 12 MB in size and the mirror log is mirrored, with each log kept on a separate device.
# lvcreate -L 12MB -m1 --mirrorlog mirrored -n twologvol bigvg
Logical volume "twologvol" created
Just as with a standard mirror log, it is possible to create the redundant mirror logs on the same device as the mirror legs by using the --alloc anywhere
argument of the vgcreate
command. This may degrade performance, but it allows you to create a redundant mirror log even if you do not have sufficient underlying devices for each log to be kept on a separate device than the mirror legs.
To create a mirror log that is itself mirrored, you can specify the
--mirrorlog mirrored
argument. The following command creates a mirrored logical volume from the volume group bigvg
. The logical volume is named twologvol
and has a single mirror. The volume is 12 MB in size and the mirror log is mirrored, with each log kept on a separate device.# lvcreate -L 12MB -m1 --mirrorlog mirrored -n twologvol bigvg Logical volume "twologvol" created
Just as with a standard mirror log, it is possible to create the redundant mirror logs on the same device as the mirror legs by using the
--alloc anywhere
argument of the vgcreate
command. This may degrade performance, but it allows you to create a redundant mirror log even if you do not have sufficient underlying devices for each log to be kept on a separate device than the mirror legs.Specifying Devices for Mirror Components
You can specify which devices to use for the mirror legs and log, and which extents of the devices to use. To force the log onto a particular disk, specify exactly one extent on the disk on which it will be placed. LVM does not necessary respect the order in which devices are listed in the command line. If any physical volumes are listed that is the only space on which allocation will take place. Any physical extents included in the list that are already allocated will get ignored.
The following command creates a mirrored logical volume with a single mirror. The volume is 500 MB in size, it is named mirrorlv
, and it is carved out of volume group vg0
. The first leg of the mirror is on device /dev/sda1
, the second leg of the mirror is on device /dev/sdb1
, and the mirror log is on /dev/sdc1
.
# lvcreate -L 500M -m1 -n mirrorlv vg0 /dev/sda1 /dev/sdb1 /dev/sdc1
The following command creates a mirrored logical volume with a single mirror. The volume is 500 MB in size, it is named mirrorlv
, and it is carved out of volume group vg0
. The first leg of the mirror is on extents 0 through 499 of device /dev/sda1
, the second leg of the mirror is on extents 0 through 499 of device /dev/sdb1
, and the mirror log starts on extent 0 of device /dev/sdc1
. These are 1 MB extents. If any of the specified extents have already been allocated, they will be ignored.
# lvcreate -L 500M -m1 -n mirrorlv vg0 /dev/sda1:0-499 /dev/sdb1:0-499 /dev/sdc1:0
You can specify which devices to use for the mirror legs and log, and which extents of the devices to use. To force the log onto a particular disk, specify exactly one extent on the disk on which it will be placed. LVM does not necessary respect the order in which devices are listed in the command line. If any physical volumes are listed that is the only space on which allocation will take place. Any physical extents included in the list that are already allocated will get ignored.
The following command creates a mirrored logical volume with a single mirror. The volume is 500 MB in size, it is named
mirrorlv
, and it is carved out of volume group vg0
. The first leg of the mirror is on device /dev/sda1
, the second leg of the mirror is on device /dev/sdb1
, and the mirror log is on /dev/sdc1
.# lvcreate -L 500M -m1 -n mirrorlv vg0 /dev/sda1 /dev/sdb1 /dev/sdc1
The following command creates a mirrored logical volume with a single mirror. The volume is 500 MB in size, it is named
mirrorlv
, and it is carved out of volume group vg0
. The first leg of the mirror is on extents 0 through 499 of device /dev/sda1
, the second leg of the mirror is on extents 0 through 499 of device /dev/sdb1
, and the mirror log starts on extent 0 of device /dev/sdc1
. These are 1 MB extents. If any of the specified extents have already been allocated, they will be ignored.# lvcreate -L 500M -m1 -n mirrorlv vg0 /dev/sda1:0-499 /dev/sdb1:0-499 /dev/sdc1:0
Splitting Off a Redundant Image of a Mirrored Logical Volume
You can split off a redundant image of a mirrored logical volume to form a new logical volume. To split off an image, you use the --splitmirrors
argument of the lvconvert
command, specifying the number of redundant images to split off. You must use the --name
argument of the command to specify a name for the newly-split-off logical volume.
The following command splits off a new logical volume named copy
from the mirrored logical volume vg/lv
. The new logical volume contains two mirror legs. In this example, LVM selects which devices to split off.
# lvconvert --splitmirrors 2 --name copy vg/lv
You can specify which devices to split off. The following command splits off a new logical volume named copy
from the mirrored logical volume vg/lv
. The new logical volume contains two mirror legs consisting of devices /dev/sdc1
and /dev/sde1
.
# lvconvert --splitmirrors 2 --name copy vg/lv /dev/sd[ce]1
You can split off a redundant image of a mirrored logical volume to form a new logical volume. To split off an image, you use the
--splitmirrors
argument of the lvconvert
command, specifying the number of redundant images to split off. You must use the --name
argument of the command to specify a name for the newly-split-off logical volume.
The following command splits off a new logical volume named
copy
from the mirrored logical volume vg/lv
. The new logical volume contains two mirror legs. In this example, LVM selects which devices to split off.# lvconvert --splitmirrors 2 --name copy vg/lv
You can specify which devices to split off. The following command splits off a new logical volume named
copy
from the mirrored logical volume vg/lv
. The new logical volume contains two mirror legs consisting of devices /dev/sdc1
and /dev/sde1
.# lvconvert --splitmirrors 2 --name copy vg/lv /dev/sd[ce]1
Splitting Off a Redundant Image of a Mirrored Logical Volume
You can split off a redundant image of a mirrored logical volume to form a new logical volume. To split off an image, you use the --splitmirrors
argument of the lvconvert
command, specifying the number of redundant images to split off. You must use the --name
argument of the command to specify a name for the newly-split-off logical volume.
The following command splits off a new logical volume named copy
from the mirrored logical volume vg/lv
. The new logical volume contains two mirror legs. In this example, LVM selects which devices to split off.
# lvconvert --splitmirrors 2 --name copy vg/lv
You can specify which devices to split off. The following command splits off a new logical volume named copy
from the mirrored logical volume vg/lv
. The new logical volume contains two mirror legs consisting of devices /dev/sdc1
and /dev/sde1
.
# lvconvert --splitmirrors 2 --name copy vg/lv /dev/sd[ce]1
The following command converts the linear logical volume vg00/lvol1
to a mirrored logical volume.
# lvconvert -m1 vg00/lvol1
The following command converts the mirrored logical volume vg00/lvol1
to a linear logical volume, removing the mirror leg.
# lvconvert -m0 vg00/lvol1
You can split off a redundant image of a mirrored logical volume to form a new logical volume. To split off an image, you use the
--splitmirrors
argument of the lvconvert
command, specifying the number of redundant images to split off. You must use the --name
argument of the command to specify a name for the newly-split-off logical volume.
The following command splits off a new logical volume named
copy
from the mirrored logical volume vg/lv
. The new logical volume contains two mirror legs. In this example, LVM selects which devices to split off.# lvconvert --splitmirrors 2 --name copy vg/lv
You can specify which devices to split off. The following command splits off a new logical volume named
copy
from the mirrored logical volume vg/lv
. The new logical volume contains two mirror legs consisting of devices /dev/sdc1
and /dev/sde1
.# lvconvert --splitmirrors 2 --name copy vg/lv /dev/sd[ce]1
The following command converts the linear logical volume
vg00/lvol1
to a mirrored logical volume.# lvconvert -m1 vg00/lvol1
The following command converts the mirrored logical volume
vg00/lvol1
to a linear logical volume, removing the mirror leg.# lvconvert -m0 vg00/lvol1
Persistent Device Numbers
Major and minor device numbers are allocated dynamically at module load. Some applications work best if the block device always is activated with the same device (major and minor) number. You can specify these with the lvcreate
and the lvchange
commands by using the following arguments:
--persistent y --major major
--minor minor
Use a large minor number to be sure that it has not already been allocated to another device dynamically.
Major and minor device numbers are allocated dynamically at module load. Some applications work best if the block device always is activated with the same device (major and minor) number. You can specify these with the
lvcreate
and the lvchange
commands by using the following arguments:--persistent y --majormajor
--minorminor
Use a large minor number to be sure that it has not already been allocated to another device dynamically.
Resizing Logical Volumes
To reduce the size of a logical volume, use the lvreduce
command. If the logical volume contains a file system, be sure to reduce the file system first (or use the LVM GUI) so that the logical volume is always at least as large as the file system expects it to be.
The following command reduces the size of logical volume lvol1
in volume group vg00
by 3 logical extents.
# lvreduce -l -3 vg00/lvol1
To reduce the size of a logical volume, use the
lvreduce
command. If the logical volume contains a file system, be sure to reduce the file system first (or use the LVM GUI) so that the logical volume is always at least as large as the file system expects it to be.
The following command reduces the size of logical volume
lvol1
in volume group vg00
by 3 logical extents.# lvreduce -l -3 vg00/lvol1
Changing the Parameters of a Logical Volume Group
To change the parameters of a logical volume, use the lvchange
command. For a listing of the parameters you can change, see the lvchange
(8) man page.
You can use the lvchange
command to activate and deactivate logical volumes. To activate and deactivate all the logical volumes in a volume group at the same time, use the vgchange
command
The following command changes the permission on volume lvol1
in volume group vg00
to be read-only.
# lvchange -pr vg00/lvol1
To change the parameters of a logical volume, use the
lvchange
command. For a listing of the parameters you can change, see the lvchange
(8) man page.
You can use the
lvchange
command to activate and deactivate logical volumes. To activate and deactivate all the logical volumes in a volume group at the same time, use the vgchange
command
The following command changes the permission on volume
lvol1
in volume group vg00
to be read-only.# lvchange -pr vg00/lvol1
Renaming Logical Volumes
To rename an existing logical volume, use the
lvrename
command.
Either of the following commands renames logical volume
lvold
in volume group vg02
to lvnew
.# lvrename /dev/vg02/lvold /dev/vg02/lvnew
# lvrename vg02 lvold lvnew
Removing Logical Volumes
To remove an inactive logical volume, use the
lvremove
command. If the logical volume is currently mounted, unmount the volume before removing it. In addition, in a clustered environment you must deactivate a logical volume before it can be removed.
The following command removes the logical volume
/dev/testvg/testlv
. from the volume group testvg
. Note that in this case the logical volume has not been deactivated.# lvremove /dev/testvg/testlv Do you really want to remove active logical volume "testlv"? [y/n]: y Logical volume "testlv" successfully removed
You could explicitly deactivate the logical volume before removing it with the
lvchange -an
command, in which case you would not see the prompt verifying whether you want to remove an active logical volume.Displaying Logical Volumes
There are three commands you can use to display properties of LVM logical volumes:
lvs
, lvdisplay
, and lvscan
.
The
lvs
command provides logical volume information in a configurable form, displaying one line per logical volume. The lvs
command provides a great deal of format control, and is useful for scripting.
The lvdisplay
command displays logical volume properties (such as size, layout, and mapping) in a fixed format.
The following command shows the attributes of lvol2
in vg00
. If snapshot logical volumes have been created for this original logical volume, this command shows a list of all snapshot logical volumes and their status (active or inactive) as well.
# lvdisplay -v /dev/vg00/lvol2
The lvscan
command scans for all logical volumes in the system and lists them, as in the following example.
# lvscan
ACTIVE '/dev/vg0/gfslv' [1.46 GB] inherit
lvdisplay
command displays logical volume properties (such as size, layout, and mapping) in a fixed format.lvol2
in vg00
. If snapshot logical volumes have been created for this original logical volume, this command shows a list of all snapshot logical volumes and their status (active or inactive) as well.lvscan
command scans for all logical volumes in the system and lists them, as in the following example.rowing Logical Volumes
To increase the size of a logical volume, use the
lvextend
command.
After extending the logical volume, you will need to increase the size of the associated file system to match.
When you extend the logical volume, you can indicate how much you want to extend the volume, or how large you want it to be after you extend it.
The following command extends the logical volume
/dev/myvg/homevol
to 12 gigabytes.# lvextend -L12G /dev/myvg/homevol lvextend -- extending logical volume "/dev/myvg/homevol" to 12 GB lvextend -- doing automatic backup of volume group "myvg" lvextend -- logical volume "/dev/myvg/homevol" successfully extended
The following command adds another gigabyte to the logical volume
/dev/myvg/homevol
.# lvextend -L+1G /dev/myvg/homevol lvextend -- extending logical volume "/dev/myvg/homevol" to 13 GB lvextend -- doing automatic backup of volume group "myvg" lvextend -- logical volume "/dev/myvg/homevol" successfully extended
As with the
lvcreate
command, you can use the -l
argument of the lvextend
command to specify the number of extents by which to increase the size of the logical volume. You can also use this argument to specify a percentage of the volume group, or a percentage of the remaining free space in the volume group. The following command extends the logical volume called testlv
to fill all of the unallocated space in the volume group myvg
.# lvextend -l +100%FREE /dev/myvg/testlv
Extending logical volume testlv to 68.59 GB
Logical volume testlv successfully resized
After you have extended the logical volume it is necessary to increase the file system size to match.
By default, most file system resizing tools will increase the size of the file system to be the size of the underlying logical volume so you do not need to worry about specifying the same size for each of the two commands.
xtending a Striped Volume
In order to increase the size of a striped logical volume, there must be enough free space on the underlying physical volumes that make up the volume group to support the stripe. For example, if you have a two-way stripe that that uses up an entire volume group, adding a single physical volume to the volume group will not enable you to extend the stripe. Instead, you must add at least two physical volumes to the volume group.
For example, consider a volume group
vg
that consists of two underlying physical volumes, as displayed with the following vgs
command.# vgs VG #PV #LV #SN Attr VSize VFree vg 2 0 0 wz--n- 271.31G 271.31G
You can create a stripe using the entire amount of space in the volume group.
# lvcreate -n stripe1 -L 271.31G -i 2 vg Using default stripesize 64.00 KB Rounding up size to full physical extent 271.31 GB Logical volume "stripe1" created # lvs -a -o +devices LV VG Attr LSize Origin Snap% Move Log Copy% Devices stripe1 vg -wi-a- 271.31G /dev/sda1(0),/dev/sdb1(0)
Note that the volume group now has no more free space.
# vgs VG #PV #LV #SN Attr VSize VFree vg 2 1 0 wz--n- 271.31G 0
The following command adds another physical volume to the volume group, which then has 135G of additional space.
# vgextend vg /dev/sdc1 Volume group "vg" successfully extended # vgs VG #PV #LV #SN Attr VSize VFree vg 3 1 0 wz--n- 406.97G 135.66G
At this point you cannot extend the striped logical volume to the full size of the volume group, because two underlying devices are needed in order to stripe the data.
# lvextend vg/stripe1 -L 406G Using stripesize of last segment 64.00 KB Extending logical volume stripe1 to 406.00 GB Insufficient suitable allocatable extents for logical volume stripe1: 34480 more required
To extend the striped logical volume, add another physical volume and then extend the logical volume. In this example, having added two physical volumes to the volume group we can extend the logical volume to the full size of the volume group.
# vgextend vg /dev/sdd1 Volume group "vg" successfully extended # vgs VG #PV #LV #SN Attr VSize VFree vg 4 1 0 wz--n- 542.62G 271.31G # lvextend vg/stripe1 -L 542G Using stripesize of last segment 64.00 KB Extending logical volume stripe1 to 542.00 GB Logical volume stripe1 successfully resized
If you do not have enough underlying physical devices to extend the striped logical volume, it is possible to extend the volume anyway if it does not matter that the extension is not striped, which may result in uneven performance. When adding space to the logical volume, the default operation is to use the same striping parameters of the last segment of the existing logical volume, but you can override those parameters. The following example extends the existing striped logical volume to use the remaining free space after the initial
lvextend
command fails.# lvextend vg/stripe1 -L 406G
Using stripesize of last segment 64.00 KB
Extending logical volume stripe1 to 406.00 GB
Insufficient suitable allocatable extents for logical volume stripe1: 34480
more required
# lvextend -i1 -l+100%FREE vg/stripe1
Extending a Mirrored Volume
As of the Red Hat Enterprise Linux 5.8 release, it is possible to grow mirrored logical volumes with the
lvextend
command without performing a synchronization of the new mirror regions.
If you specify the
--nosync
option when you create a mirrored logical volume with the lvcreate
command, the mirror regions are not synchronized when the mirror is created
You can determine whether an existing logical volume was created with the
--nosync
option by using the lvs
command to display the volume's attributes. A logical volume will have an attribute of "M" if it is a mirrored volume that was created without an initial synchronization, and it will have an attribute of "m" if it was created with initial synchronization.
The following command displays the attributes of a mirrored logical volume named
lv
that was created without initial synchronization.# lvs vg LV VG Attr LSize Pool Origin Snap% Move Log Copy% Convert lv vg Mwi-a-m- 5.00g lv_mlog 100.00
If you grow this mirrored logical volume with the
lvextend
command, the mirror extension will not be resynchronized.
If you created a mirrored logical volume without specifying the
--nosync
option of the lvcreate
command, you can grow the logical volume without resynchronizing the mirror by specifying the --nosync
option of the lvextend
command.
The following example extends a logical volume that was created without the
--nosync
option, indicated that the mirror was synchronized when it was created. This example, however, specifies that the mirror not be synchronized when the volume is extended. Note that the volume has an attribute of "m", but after executing the lvextend
commmand with the --nosync
option the volume has an attribute of "M".# lvs vg LV VG Attr LSize Pool Origin Snap% Move Log Copy% Convert lv vg mwi-a-m- 20.00m lv_mlog 100.00 # lvextend -L +5G vg/lv --nosync Extending 2 mirror images. Extending logical volume lv to 5.02 GiB Logical volume lv successfully resized # lvs vg LV VG Attr LSize Pool Origin Snap% Move Log Copy% Convert lv vg Mwi-a-m- 5.02g lv_mlog 100.00
If a mirror is inactive, it will not automatically skip synchronization when you extend the mirror, even if you create the mirror with the
--nosync
option specified. Instead, you will be prompted whether to do a full resync of the extended portion of the logical volume.
Extending a Logical Volume with the cling
Allocation Policy
As of the Red Hat Enterprise Linux 5.7 release, when extending an LVM volume, you can use the
--alloc cling
option of the lvextend
command to specify the cling
allocation policy. This policy will choose space on the same physical volumes as the last segment of the existing logical volume. If there is insufficient space on the physical volumes and a list of tags is defined in the lvm.conf
file, LVM will check whether any of the tags are attached to the physical volumes and seek to match those physical volume tags between existing extents and new extents.
For example, if you have logical volumes that are mirrored between two sites within a single volume group, you can tag the physical volumes according to where they are situated by tagging the physical volumes with @site1 and @site2 tags and specify the following line in the
lvm.conf
file:cling_tag_list = [ "@site1", "@site2" ]
In the following example, the
lvm.conf
file has been modified to contain the following line:cling_tag_list = [ "@A", "@B" ]
Also in this example, a volume group
taft
has been created that consists of the physical volumes /dev/sdb1
, /dev/sdc1
, /dev/sdd1
, /dev/sde1
, /dev/sdf1
, /dev/sdg1
, and /dev/sdh1
. These physical volumes have been tagged with tags A
, B
, and C
. The example does not use the C
tag, but this will show that LVM uses the tags to select which physical volumes to use for the mirror legs.# pvs -a -o +pv_tags /dev/sd[bcdefgh]1 PV VG Fmt Attr PSize PFree PV Tags /dev/sdb1 taft lvm2 a- 135.66g 135.66g A /dev/sdc1 taft lvm2 a- 135.66g 135.66g B /dev/sdd1 taft lvm2 a- 135.66g 135.66g B /dev/sde1 taft lvm2 a- 135.66g 135.66g C /dev/sdf1 taft lvm2 a- 135.66g 135.66g C /dev/sdg1 taft lvm2 a- 135.66g 135.66g A /dev/sdh1 taft lvm2 a- 135.66g 135.66g A
The following command creates a 100G mirrored volume from the volume group
taft
.# lvcreate -m 1 -n mirror --nosync -L 100G taft
The following command shows which devices are used for the mirror legs and mirror log.
# lvs -a -o +devices LV VG Attr LSize Log Copy% Devices mirror taft Mwi-a- 100.00g mirror_mlog 100.00 mirror_mimage_0(0),mirror_mimage_1(0) [mirror_mimage_0] taft iwi-ao 100.00g /dev/sdb1(0) [mirror_mimage_1] taft iwi-ao 100.00g /dev/sdc1(0) [mirror_mlog] taft lwi-ao 4.00m /dev/sdh1(0)
The following command extends the size of the mirrored volume, using the
cling
allocation policy to indicate that the mirror legs should be extended using physical volumes with the same tag.# lvextend --alloc cling -L +100G taft/mirror Extending 2 mirror images. Extending logical volume mirror to 200.00 GiB Logical volume mirror successfully resized
The following display command shows that the mirror legs have been extended using physical volumes with the same tag as the leg. Note that the physical volumes with a tag of
C
were ignored.# lvs -a -o +devices
LV VG Attr LSize Log Copy% Devices
mirror taft Mwi-a- 200.00g mirror_mlog 50.16
mirror_mimage_0(0),mirror_mimage_1(0)
[mirror_mimage_0] taft Iwi-ao 200.00g /dev/sdb1(0)
[mirror_mimage_0] taft Iwi-ao 200.00g /dev/sdg1(0)
[mirror_mimage_1] taft Iwi-ao 200.00g /dev/sdc1(0)
[mirror_mimage_1] taft Iwi-ao 200.00g /dev/sdd1(0)
[mirror_mlog] taft lwi-ao 4.00m /dev/sdh1(0)
Shrinking Logical Volumes
To reduce the size of a logical volume, first unmount the file system. You can then use the
lvreduce
command to shrink the volume. After shrinking the volume, remount the file system.
Shrinking a logical volume frees some of the volume group to be allocated to other logical volumes in the volume group.
The following example reduces the size of logical volume
lvol1
in volume group vg00
by 3 logical extents.# lvreduce -l -3 vg00/lvol1
Creating Snapshot Volumes
Use the
-s
argument of the lvcreate
command to create a snapshot volume. A snapshot volume is writable.
The following command creates a snapshot logical volume that is 100 MB in size named
/dev/vg00/snap
. This creates a snapshot of the origin logical volume named /dev/vg00/lvol1
. If the original logical volume contains a file system, you can mount the snapshot logical volume on an arbitrary directory in order to access the contents of the file system to run a backup while the original file system continues to get updated.# lvcreate --size 100M --snapshot --name snap /dev/vg00/lvol1
After you create a snapshot logical volume, specifying the origin volume on the
lvdisplay
command yields output that includes a list of all snapshot logical volumes and their status (active or inactive).
The following example shows the status of the logical volume
/dev/new_vg/lvol0
, for which a snapshot volume /dev/new_vg/newvgsnap
has been created.# lvdisplay /dev/new_vg/lvol0 --- Logical volume --- LV Name /dev/new_vg/lvol0 VG Name new_vg LV UUID LBy1Tz-sr23-OjsI-LT03-nHLC-y8XW-EhCl78 LV Write Access read/write LV snapshot status source of /dev/new_vg/newvgsnap1 [active] LV Status available # open 0 LV Size 52.00 MB Current LE 13 Segments 1 Allocation inherit Read ahead sectors 0 Block device 253:2
The
lvs
command, by default, displays the origin volume and the current percentage of the snapshot volume being used for each snapshot volume. The following example shows the default output for the lvs
command for a system that includes the logical volume /dev/new_vg/lvol0
, for which a snapshot volume /dev/new_vg/newvgsnap
has been created.# lvs
LV VG Attr LSize Origin Snap% Move Log Copy%
lvol0 new_vg owi-a- 52.00M
newvgsnap1 new_vg swi-a- 8.00M lvol0 0.20
Controlling LVM Device Scans with Filters
At startup, the
vgscan
command is run to scan the block devices on the system looking for LVM labels, to determine which of them are physical volumes and to read the metadata and build up a list of volume groups. The names of the physical volumes are stored in the cache file of each node in the system, /etc/lvm/.cache
. Subsequent commands may read that file to avoiding rescanning.
You can control which devices LVM scans by setting up filters in the
lvm.conf
configuration file. The filters in the lvm.conf
file consist of a series of simple regular expressions that get applied to the device names that are in the /dev
directory to decide whether to accept or reject each block device found.
The following examples show the use of filters to control which devices LVM scans. Note that some of these examples do not necessarily represent best practice, as the regular expressions are matched freely against the complete pathname. For example,
a/loop/
is equivalent to a/.*loop.*/
and would match /dev/solooperation/lvol1
.
The following filter adds all discovered devices, which is the default behavior as there is no filter configured in the configuration file:
filter = [ "a/.*/" ]
The following filter removes the cdrom device in order to avoid delays if the drive contains no media:
filter = [ "r|/dev/cdrom|" ]
The following filter adds all loop and removes all other block devices:
filter = [ "a/loop.*/", "r/.*/" ]
The following filter adds all loop and IDE and removes all other block devices:
filter =[ "a|loop.*|", "a|/dev/hd.*|", "r|.*|" ]
The following filter adds just partition 8 on the first IDE drive and removes all other block devices:
filter = [ "a|^/dev/hda8$|", "r/.*/" ]
Online Data Relocation
You can move data while the system is in use with the
pvmove
command.
The
pvmove
command breaks up the data to be moved into sections and creates a temporary mirror to move each section.
The following command moves all allocated space off the physical volume
/dev/sdc1
to other free physical volumes in the volume group:# pvmove /dev/sdc1
The following command moves just the extents of the logical volume
MyLV
.# pvmove -n MyLV /dev/sdc1
Since the
pvmove
command can take a long time to execute, you may want to run the command in the background to avoid display of progress updates in the foreground. The following command moves all extents allocated to the physical volume /dev/sdc1
over to /dev/sdf1
in the background.# pvmove -b /dev/sdc1 /dev/sdf1
The following command reports the progress of the move as a percentage at five second intervals.
# pvmove -i5 /dev/sdd1
Activating Logical Volumes on Individual Nodes in a Cluster
If you have LVM installed in a cluster environment, you may at times need to activate logical volumes exclusively on one node.
To activate logical volumes exclusively on one node, use the
lvchange -aey
command. Alternatively, you can use lvchange -aly
command to activate logical volumes only on the local node but not exclusively. You can later activate them on additional nodes concurrently.Customized Reporting for LVM
You can produce concise and customizable reports of LVM objects with the
pvs
, lvs
, and vgs
commands. The reports that these commands generate include one line of output for each object. Each line contains an ordered list of fields of properties related to the object. There are five ways to select the objects to be reported: by physical volume, volume group, logical volume, physical volume segment, and logical volume segment.
The following sections provide:
- A summary of command arguments you can use to control the format of the generated report.
- A list of the fields you can select for each LVM object.
- A summary of command arguments you can use to sort the generated report.
- Instructions for specifying the units of the report output.
ormat Control
Whether you use the
pvs
, lvs
, or vgs
command determines the default set of fields displayed and the sort order. You can control the output of these commands with the following arguments:- You can change what fields are displayed to something other than the default by using the
-o
argument. For example, the following output is the default display for thepvs
command (which displays information about physcial volumes).# pvs PV VG Fmt Attr PSize PFree /dev/sdb1 new_vg lvm2 a- 17.14G 17.14G /dev/sdc1 new_vg lvm2 a- 17.14G 17.09G /dev/sdd1 new_vg lvm2 a- 17.14G 17.14G
The following command displays only the physical volume name and size.# pvs -o pv_name,pv_size PV PSize /dev/sdb1 17.14G /dev/sdc1 17.14G /dev/sdd1 17.14G
- You can append a field to the output with the plus sign (+), which is used in combination with the -o argument.The following example displays the UUID of the physical volume in addition to the default fields.
# pvs -o +pv_uuid PV VG Fmt Attr PSize PFree PV UUID /dev/sdb1 new_vg lvm2 a- 17.14G 17.14G onFF2w-1fLC-ughJ-D9eB-M7iv-6XqA-dqGeXY /dev/sdc1 new_vg lvm2 a- 17.14G 17.09G Joqlch-yWSj-kuEn-IdwM-01S9-X08M-mcpsVe /dev/sdd1 new_vg lvm2 a- 17.14G 17.14G yvfvZK-Cf31-j75k-dECm-0RZ3-0dGW-UqkCS
- Adding the
-v
argument to a command includes some extra fields. For example, thepvs -v
command will display theDevSize
andPV UUID
fields in addition to the default fields.# pvs -v Scanning for physical volume names PV VG Fmt Attr PSize PFree DevSize PV UUID /dev/sdb1 new_vg lvm2 a- 17.14G 17.14G 17.14G onFF2w-1fLC-ughJ-D9eB-M7iv-6XqA-dqGeXY /dev/sdc1 new_vg lvm2 a- 17.14G 17.09G 17.14G Joqlch-yWSj-kuEn-IdwM-01S9-XO8M-mcpsVe /dev/sdd1 new_vg lvm2 a- 17.14G 17.14G 17.14G yvfvZK-Cf31-j75k-dECm-0RZ3-0dGW-tUqkCS
- The
--noheadings
argument suppresses the headings line. This can be useful for writing scripts.The following example uses the--noheadings
argument in combination with thepv_name
argument, which will generate a list of all physical volumes.# pvs --noheadings -o pv_name /dev/sdb1 /dev/sdc1 /dev/sdd1
- The
--separator
argument usesseparator
separator
to separate each field.The following example separates the default output fields of thepvs
command with an equals sign (=).# pvs --separator = PV=VG=Fmt=Attr=PSize=PFree /dev/sdb1=new_vg=lvm2=a-=17.14G=17.14G /dev/sdc1=new_vg=lvm2=a-=17.14G=17.09G /dev/sdd1=new_vg=lvm2=a-=17.14G=17.14G
To keep the fields aligned when using theseparator
argument, use theseparator
argument in conjunction with the--aligned
argument.# pvs --separator = --aligned PV =VG =Fmt =Attr=PSize =PFree /dev/sdb1 =new_vg=lvm2=a- =17.14G=17.14G /dev/sdc1 =new_vg=lvm2=a- =17.14G=17.09G /dev/sdd1 =new_vg=lvm2=a- =17.14G=17.14G
You can use the
-P
argument of the lvs
or vgs
command to display information about a failed volume that would otherwise not appear in the output.Creating an LVM Logical Volume on Three Disks
This example creates an LVM logical volume called
new_logical_volume
that consists of the disks at /dev/sda1
, /dev/sdb1
, and /dev/sdc1
.Creating the Physical Volumes
To use disks in a volume group, you label them as LVM physical volumes.
# pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1
Physical volume "/dev/sda1" successfully created
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
Creating the Volume Group
The following command creates the volume group
new_vol_group
.# vgcreate new_vol_group /dev/sda1 /dev/sdb1 /dev/sdc1 Volume group "new_vol_group" successfully created
You can use the
vgs
command to display the attributes of the new volume group.# vgs
VG #PV #LV #SN Attr VSize VFree
new_vol_group 3 0 0 wz--n- 51.45G 51.45G
Creating the Logical Volume
The following command creates the logical volume
new_logical_volume
from the volume group new_vol_group
. This example creates a logical volume that uses 2GB of the volume group.# lvcreate -L2G -n new_logical_volume new_vol_group
Logical volume "new_logical_volume" created
Creating the File System
The following command creates a GFS file system on the logical volume.
# gfs_mkfs -plock_nolock -j 1 /dev/new_vol_group/new_logical_volume This will destroy any data on /dev/new_vol_group/new_logical_volume. Are you sure you want to proceed? [y/n] y Device: /dev/new_vol_group/new_logical_volume Blocksize: 4096 Filesystem Size: 491460 Journals: 1 Resource Groups: 8 Locking Protocol: lock_nolock Lock Table: Syncing... All Done
The following commands mount the logical volume and report the file system disk space usage.
# mount /dev/new_vol_group/new_logical_volume /mnt
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/new_vol_group/new_logical_volume
1965840 20 1965820 1% /mnt
Creating a Striped Logical Volume
This example creates an LVM striped logical volume called
striped_logical_volume
that stripes data across the disks at /dev/sda1
, /dev/sdb1
, and /dev/sdc1
.# pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1
Physical volume "/dev/sda1" successfully created
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
Creating the Volume Group
The following command creates the volume group
volgroup01
.# vgcreate volgroup01 /dev/sda1 /dev/sdb1 /dev/sdc1 Volume group "volgroup01" successfully created
You can use the
vgs
command to display the attributes of the new volume group.# vgs
VG #PV #LV #SN Attr VSize VFree
volgroup01 3 0 0 wz--n- 51.45G 51.45G
Creating the Logical Volume
The following command creates the striped logical volume
striped_logical_volume
from the volume group volgroup01
. This example creates a logical volume that is 2 gigabytes in size, with three stripes and a stripe size of 4 kilobytes.# lvcreate -i3 -I4 -L2G -nstriped_logical_volume volgroup01
Rounding size (512 extents) up to stripe boundary size (513 extents)
Logical volume "striped_logical_volume" created
Creating the File System
The following command creates a GFS file system on the logical volume.
# gfs_mkfs -plock_nolock -j 1 /dev/volgroup01/striped_logical_volume This will destroy any data on /dev/volgroup01/striped_logical_volume. Are you sure you want to proceed? [y/n] y Device: /dev/volgroup01/striped_logical_volume Blocksize: 4096 Filesystem Size: 492484 Journals: 1 Resource Groups: 8 Locking Protocol: lock_nolock Lock Table: Syncing... All Done
The following commands mount the logical volume and report the file system disk space usage.
# mount /dev/volgroup01/striped_logical_volume /mnt
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
13902624 1656776 11528232 13% /
/dev/hda1 101086 10787 85080 12% /boot
tmpfs 127880 0 127880 0% /dev/shm
/dev/volgroup01/striped_logical_volume
1969936 20 1969916 1% /mnt
Removing a Disk from a Logical Volume
This example shows how you can remove a disk from an existing logical volume, either to replace the disk or to use the disk as part of a different volume. In order to remove a disk, you must first move the extents on the LVM physical volume to a different disk or set of disks.
Moving Extents to Existing Physical Volumes
In this example, the logical volume is distributed across four physical volumes in the volume group
myvg
.# pvs -o+pv_used PV VG Fmt Attr PSize PFree Used /dev/sda1 myvg lvm2 a- 17.15G 12.15G 5.00G /dev/sdb1 myvg lvm2 a- 17.15G 12.15G 5.00G /dev/sdc1 myvg lvm2 a- 17.15G 12.15G 5.00G /dev/sdd1 myvg lvm2 a- 17.15G 2.15G 15.00G
We want to move the extents off of
/dev/sdb1
so that we can remove it from the volume group.
If there are enough free extents on the other physical volumes in the volume group, you can execute the
pvmove
command on the device you want to remove with no other options and the extents will be distributed to the other devices.# pvmove /dev/sdb1 /dev/sdb1: Moved: 2.0% ... /dev/sdb1: Moved: 79.2% ... /dev/sdb1: Moved: 100.0%
After the
pvmove
command has finished executing, the distribution of extents is as follows:# pvs -o+pv_used PV VG Fmt Attr PSize PFree Used /dev/sda1 myvg lvm2 a- 17.15G 7.15G 10.00G /dev/sdb1 myvg lvm2 a- 17.15G 17.15G 0 /dev/sdc1 myvg lvm2 a- 17.15G 12.15G 5.00G /dev/sdd1 myvg lvm2 a- 17.15G 2.15G 15.00G
Use the
vgreduce
command to remove the physical volume /dev/sdb1
from the volume group.# vgreduce myvg /dev/sdb1
Removed "/dev/sdb1" from volume group "myvg"
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 myvg lvm2 a- 17.15G 7.15G
/dev/sdb1 lvm2 -- 17.15G 17.15G
/dev/sdc1 myvg lvm2 a- 17.15G 12.15G
/dev/sdd1 myvg lvm2 a- 17.15G 2.15G
The disk can now be physically removed or allocated to other users.
Moving Extents to a New Disk
In this example, the logical volume is distributed across three physical volumes in the volume group
myvg
as follows:# pvs -o+pv_used PV VG Fmt Attr PSize PFree Used /dev/sda1 myvg lvm2 a- 17.15G 7.15G 10.00G /dev/sdb1 myvg lvm2 a- 17.15G 15.15G 2.00G /dev/sdc1 myvg lvm2 a- 17.15G 15.15G 2.00G
We want to move the extents of
/dev/sdb1
to a new device, /dev/sdd1
.Creating the New Physical Volume
Create a new physical volume from
/dev/sdd1
.# pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created
Adding the New Physical Volume to the Volume Group
Add
/dev/sdd1
to the existing volume group myvg
.# vgextend myvg /dev/sdd1
Volume group "myvg" successfully extended
# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/sda1 myvg lvm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg lvm2 a- 17.15G 15.15G 2.00G
/dev/sdc1 myvg lvm2 a- 17.15G 15.15G 2.00G
/dev/sdd1 myvg lvm2 a- 17.15G 17.15G 0
Moving the Data
Use the
pvmove
command to move the data from /dev/sdb1
to /dev/sdd1
.# pvmove /dev/sdb1 /dev/sdd1
/dev/sdb1: Moved: 10.0%
...
/dev/sdb1: Moved: 79.7%
...
/dev/sdb1: Moved: 100.0%
# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/sda1 myvg lvm2 a- 17.15G 7.15G 10.00G
/dev/sdb1 myvg lvm2 a- 17.15G 17.15G 0
/dev/sdc1 myvg lvm2 a- 17.15G 15.15G 2.00G
/dev/sdd1 myvg lvm2 a- 17.15G 15.15G 2.00G
Removing the Old Physical Volume from the Volume Group
After you have moved the data off
/dev/sdb1
, you can remove it from the volume group.# vgreduce myvg /dev/sdb1
Removed "/dev/sdb1" from volume group "myvg"
You can now reallocate the disk to another volume group or remove the disk from the system.
Displaying Information on Failed Devices
You can use the
-P
argument of the lvs
or vgs
command to display information about a failed volume that would otherwise not appear in the output. This argument permits some operations even though the metatdata is not completely consistent internally. For example, if one of the devices that made up the volume group vg
failed, the vgs
command might show the following output.# vgs -o +devices Volume group "vg" not found
If you specify the
-P
argument of the vgs
command, the volume group is still unusable but you can see more information about the failed device.vgs -P -o +devices Partial mode. Incomplete volume groups will be activated read-only. VG #PV #LV #SN Attr VSize VFree Devices vg 9 2 0 rz-pn- 2.11T 2.07T unknown device(0) vg 9 2 0 rz-pn- 2.11T 2.07T unknown device(5120),/dev/sda1(0)
In this example, the failed device caused both a linear and a striped logical volume in the volume group to fail. The
lvs
command without the -P
argument shows the following output.# lvs -a -o +devices Volume group "vg" not found
Using the
-P
argument shows the logical volumes that have failed.# lvs -P -a -o +devices Partial mode. Incomplete volume groups will be activated read-only. LV VG Attr LSize Origin Snap% Move Log Copy% Devices linear vg -wi-a- 20.00G unknown device(0) stripe vg -wi-a- 20.00G unknown device(5120),/dev/sda1(0)
The following examples show the output of the
pvs
and lvs
commands with the -P
argument specified when a leg of a mirrored logical volume has failed.# vgs -a -o +devices -P Partial mode. Incomplete volume groups will be activated read-only. VG #PV #LV #SN Attr VSize VFree Devices corey 4 4 0 rz-pnc 1.58T 1.34T my_mirror_mimage_0(0),my_mirror_mimage_1(0) corey 4 4 0 rz-pnc 1.58T 1.34T /dev/sdd1(0) corey 4 4 0 rz-pnc 1.58T 1.34T unknown device(0) corey 4 4 0 rz-pnc 1.58T 1.34T /dev/sdb1(0)
# lvs -a -o +devices -P
Partial mode. Incomplete volume groups will be activated read-only.
LV VG Attr LSize Origin Snap% Move Log Copy% Devices
my_mirror corey mwi-a- 120.00G my_mirror_mlog 1.95 my_mirror_mimage_0(0),my_mirror_mimage_1(0)
[my_mirror_mimage_0] corey iwi-ao 120.00G unknown device(0)
[my_mirror_mimage_1] corey iwi-ao 120.00G /dev/sdb1(0)
[my_mirror_mlog] corey lwi-ao 4.00M /dev/sdd1(0)
Recovering from LVM Mirror Failure
This section provides an example of recovering from a situation where one leg of an LVM mirrored volume fails because the underlying device for a physical volume goes down. When a mirror leg fails, LVM converts the mirrored volume into a linear volume, which continues to operate as before but without the mirrored redundancy. At that point, you can add a new disk device to the system to use as a replacement physical device and rebuild the mirror.
The following command creates the physical volumes which will be used for the mirror.
# pvcreate /dev/sd[abcdefgh][12] Physical volume "/dev/sda1" successfully created Physical volume "/dev/sda2" successfully created Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdb2" successfully created Physical volume "/dev/sdc1" successfully created Physical volume "/dev/sdc2" successfully created Physical volume "/dev/sdd1" successfully created Physical volume "/dev/sdd2" successfully created Physical volume "/dev/sde1" successfully created Physical volume "/dev/sde2" successfully created Physical volume "/dev/sdf1" successfully created Physical volume "/dev/sdf2" successfully created Physical volume "/dev/sdg1" successfully created Physical volume "/dev/sdg2" successfully created Physical volume "/dev/sdh1" successfully created Physical volume "/dev/sdh2" successfully created
The following commands creates the volume group
vg
and the mirrored volume groupfs
.# vgcreate vg /dev/sd[abcdefgh][12] Volume group "vg" successfully created # lvcreate -L 750M -n groupfs -m 1 vg /dev/sda1 /dev/sdb1 /dev/sdc1 Rounding up size to full physical extent 752.00 MB Logical volume "groupfs" created
You can use the
lvs
command to verify the layout of the mirrored volume and the underlying devices for the mirror leg and the mirror log. Note that in the first example the mirror is not yet completely synced; you should wait until the Copy%
field displays 100.00 before continuing.# lvs -a -o +devices LV VG Attr LSize Origin Snap% Move Log Copy% Devices groupfs vg mwi-a- 752.00M groupfs_mlog 21.28 groupfs_mimage_0(0),groupfs_mimage_1(0) [groupfs_mimage_0] vg iwi-ao 752.00M /dev/sda1(0) [groupfs_mimage_1] vg iwi-ao 752.00M /dev/sdb1(0) [groupfs_mlog] vg lwi-ao 4.00M /dev/sdc1(0) # lvs -a -o +devices LV VG Attr LSize Origin Snap% Move Log Copy% Devices groupfs vg mwi-a- 752.00M groupfs_mlog 100.00 groupfs_mimage_0(0),groupfs_mimage_1(0) [groupfs_mimage_0] vg iwi-ao 752.00M /dev/sda1(0) [groupfs_mimage_1] vg iwi-ao 752.00M /dev/sdb1(0) [groupfs_mlog] vg lwi-ao 4.00M i /dev/sdc1(0)
In this example, the primary leg of the mirror
/dev/sda1
fails. Any write activity to the mirrored volume causes LVM to detect the failed mirror. When this occurs, LVM converts the mirror into a single linear volume. In this case, to trigger the conversion, we execute a dd
command# dd if=/dev/zero of=/dev/vg/groupfs count=10 10+0 records in 10+0 records out
You can use the
lvs
command to verify that the device is now a linear device. Because of the failed disk, I/O errors occur.# lvs -a -o +devices /dev/sda1: read failed after 0 of 2048 at 0: Input/output error /dev/sda2: read failed after 0 of 2048 at 0: Input/output error LV VG Attr LSize Origin Snap% Move Log Copy% Devices groupfs vg -wi-a- 752.00M /dev/sdb1(0)
At this point you should still be able to use the logical volume, but there will be no mirror redundancy.
To rebuild the mirrored volume, you replace the broken drive and recreate the physical volume. If you use the same disk rather than replacing it with a new one, you will see "inconsistent" warnings when you run the
pvcreate
command.# pvcreate /dev/sda[12] Physical volume "/dev/sda1" successfully created Physical volume "/dev/sda2" successfully created # pvscan PV /dev/sdb1 VG vg lvm2 [67.83 GB / 67.10 GB free] PV /dev/sdb2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdc1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdc2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdd1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdd2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sde1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sde2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdf1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdf2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdg1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdg2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdh1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdh2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sda1 lvm2 [603.94 GB] PV /dev/sda2 lvm2 [603.94 GB] Total: 16 [2.11 TB] / in use: 14 [949.65 GB] / in no VG: 2 [1.18 TB]
Next you extend the original volume group with the new physical volume.
# vgextend vg /dev/sda[12] Volume group "vg" successfully extended # pvscan PV /dev/sdb1 VG vg lvm2 [67.83 GB / 67.10 GB free] PV /dev/sdb2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdc1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdc2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdd1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdd2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sde1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sde2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdf1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdf2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdg1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdg2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdh1 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sdh2 VG vg lvm2 [67.83 GB / 67.83 GB free] PV /dev/sda1 VG vg lvm2 [603.93 GB / 603.93 GB free] PV /dev/sda2 VG vg lvm2 [603.93 GB / 603.93 GB free] Total: 16 [2.11 TB] / in use: 16 [2.11 TB] / in no VG: 0 [0 ]
Convert the linear volume back to its original mirrored state.
# lvconvert -m 1 /dev/vg/groupfs /dev/sda1 /dev/sdb1 /dev/sdc1 Logical volume mirror converted.
You can use the
lvs
command to verify that the mirror is restored.# lvs -a -o +devices
LV VG Attr LSize Origin Snap% Move Log Copy% Devices
groupfs vg mwi-a- 752.00M groupfs_mlog 68.62 groupfs_mimage_0(0),groupfs_mimage_1(0)
[groupfs_mimage_0] vg iwi-ao 752.00M /dev/sdb1(0)
[groupfs_mimage_1] vg iwi-ao 752.00M /dev/sda1(0)
[groupfs_mlog] vg lwi-ao 4.00M /dev/sdc1(0)
Recovering Physical Volume Metadata
If the volume group metadata area of a physical volume is accidentally overwritten or otherwise destroyed, you will get an error message indicating that the metadata area is incorrect, or that the system was unable to find a physical volume with a particular UUID. You may be able to recover the data the physical volume by writing a new metadata area on the physical volume specifying the same UUID as the lost metadata.
The following example shows the sort of output you may see if the metadata area is missing or corrupted.
# lvs -a -o +devices Couldn't find device with uuid 'FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk'. Couldn't find all physical volumes for volume group VG. Couldn't find device with uuid 'FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk'. Couldn't find all physical volumes for volume group VG. ...
You may be able to find the UUID for the physical volume that was overwritten by looking in the
/etc/lvm/archive
directory. Look in the file VolumeGroupName_xxxx
.vg
for the last known valid archived LVM metadata for that volume group.
Alternately, you may find that deactivating the volume and setting the
partial
(-P
) argument will enable you to find the UUID of the missing corrupted physical volume.# vgchange -an --partial Partial mode. Incomplete volume groups will be activated read-only. Couldn't find device with uuid 'FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk'. Couldn't find device with uuid 'FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk'. ...
Use the
--uuid
and --restorefile
arguments of the pvcreate
command to restore the physical volume. The following example labels the /dev/sdh1
device as a physical volume with the UUID indicated above, FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk
. This command restores the physical volume label with the metadata information contained in VG_00050.vg
, the most recent good archived metatdata for volume group
. The restorefile
argument instructs the pvcreate
command to make the new physical volume compatible with the old one on the volume group, ensuring that the new metadata will not be placed where the old physical volume contained data (which could happen, for example, if the original pvcreate
command had used the command line arguments that control metadata placement, or it the physical volume was originally created using a different version of the software that used different defaults). The pvcreate
command overwrites only the LVM metadata areas and does not affect the existing data areas.# pvcreate --uuid "FmGRh3-zhok-iVI8-7qTD-S5BI-MAEN-NYM5Sk" --restorefile /etc/lvm/archive/VG_00050.vg /dev/sdh1 Physical volume "/dev/sdh1" successfully created
You can then use the
vgcfgrestore
command to restore the volume group's metadata.# vgcfgrestore VG Restored volume group VG
You can now display the logical volumes.
# lvs -a -o +devices LV VG Attr LSize Origin Snap% Move Log Copy% Devices stripe VG -wi--- 300.00G /dev/sdh1 (0),/dev/sda1(0) stripe VG -wi--- 300.00G /dev/sdh1 (34728),/dev/sdb1(0)
The following commands activate the volumes and display the active volumes.
# lvchange -ay /dev/VG/stripe # lvs -a -o +devices LV VG Attr LSize Origin Snap% Move Log Copy% Devices stripe VG -wi-a- 300.00G /dev/sdh1 (0),/dev/sda1(0) stripe VG -wi-a- 300.00G /dev/sdh1 (34728),/dev/sdb1(0)
If the on-disk LVM metadata takes as least as much space as what overrode it, this command can recover the physical volume. If what overrode the metadata went past the metadata area, the data on the volume may have been affected. You might be able to use the
fsck
command to recover that data.Replacing a Missing Physical Volume
If a physical volume fails or otherwise needs to be replaced, you can label a new physical volume to replace the one that has been lost in the existing volume group by following the same procedure as you would for recovering physical volume metadata. You can use the
--partial
and --verbose
arguments of the vgdisplay
command to display the UUIDs and sizes of any physical volumes that are no longer present. If you wish to substitute another physical volume of the same size, you can use the pvcreate
command with the --restorefile
and --uuid
arguments to initialize a new device with the same UUID as the missing physical volume. You can then use the vgcfgrestore
command to restore the volume group's metadata.Removing Lost Physical Volumes from a Volume Group
If you lose a physical volume, you can activate the remaining physical volumes in the volume group with the
--partial
argument of the vgchange
command. You can remove all the logical volumes that used that physical volume from the volume group with the --removemissing
argument of the vgreduce
command.
It is recommended that you run the
vgreduce
command with the --test
argument to verify what you will be destroying.
Like most LVM operations, the
vgreduce
command is reversible in a sense if you immediately use the vgcfgrestore
command to restore the volume group metadata to its previous state. For example, if you used the --removemissing
argument of the vgreduce
command without the --test
argument and find you have removed logical volumes you wanted to keep, you can still replace the physical volume and use another vgcfgrestore
command to return the volume group to its previous state.The Device Mapper
The Device Mapper is a kernel driver that provides a framework for volume management. It provides a generic way of creating mapped devices, which may be used as logical volumes. It does not specifically know about volume groups or metadata formats.
The Device Mapper provides the foundation for a number of higher-level technologies. In addition to LVM, Device-Mapper multipath and the
dmraid
command use the Device Mapper. The application interface to the Device Mapper is the ioctl
system call. The user interface is the dmsetup
command.
LVM logical volumes are activated using the Device Mapper. Each logical volume is translated into a mapped device. Each segment translates into a line in the mapping table that describes the device. The Device Mapper supports a variety of mapping targets, including linear mapping, striped mapping, and error mapping. So, for example, two disks may be concatenated into one logical volume with a pair of linear mappings, one for each disk. When LVM2 creates a volume, it creates an underlying device-mapper device that can be queried with the
dmsetup
command. The LVM Configuration Files
LVM supports multiple configuration files. At system startup, the
lvm.conf
configuration file is loaded from the directory specified by the environment variable LVM_SYSTEM_DIR
, which is set to /etc/lvm
by default.
The
lvm.conf
file can specify additional configuration files to load. Settings in later files override settings from earlier ones. To display the settings in use after loading all the configuration files, execute the lvm dumpconfig
command.The LVM Configuration Files
The following files are used for LVM configuration:
- /etc/lvm/lvm.conf
- Central configuration file read by the tools.
- /etc/lvm/lvm_
hosttag
.conf - For each host tag, an extra configuration file is read if it exists:
lvm_
. If that file defines new tags, then further configuration files will be appended to the list of tiles to read in.hosttag
.conf
In addition to the LVM configuration files, a system running LVM includes the following files that affect LVM system setup:
- /etc/lvm/.cache
- Device name filter cache file (configurable).
- /etc/lvm/backup/
- Directory for automatic volume group metadata backups (configurable).
- /etc/lvm/archive/
- Directory for automatic volume group metadata archives (configurable with regard to directory path and archive history depth).
- /var/lock/lvm/
- In single-host configuration, lock files to prevent parallel tool runs from corrupting the metadata; in a cluster, cluster-wide DLM is used.
- Information about how and when it was created
- Information about the volume group:
- Name and unique id
- A version number which is incremented whenever the metadata gets updated
- Any properties: Read/Write? Resizeable?
- Any administrative limit on the number of physical volumes and logical volumes it may contain
- The extent size (in units of sectors which are defined as 512 bytes)
- An unordered list of physical volumes making up the volume group, each with:
- Its UUID, used to determine the block device containing it
- Any properties, such as whether the physical volume is allocatable
- The offset to the start of the first extent within the physical volume (in sectors)
- The number of extents
- An unordered list of logical volumes. each consisting of
- An ordered list of logical volume segments. For each segment the metadata includes a mapping applied to an ordered list of physical volume segments or logical volume segments
Metadata Contents
The volume group metadata contains:
The volume group information contains:
No comments:
Post a Comment