4.4. Logical Volume Administration
4.4.1. Creating Linear Logical Volumes
lvcreate
command. 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.
vg1
.
# lvcreate -L 10G vg1
testlv
in the volume group testvg
, creating the block device /dev/testvg/testlv
.
# lvcreate -L 1500 -n testlv testvg
gfslv
from the free extents in volume group vg0
.
# lvcreate -L 50G -n gfslv vg0
-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 of the size of a related volume group, logical volume, or set of physical volumes. The suffix %VG denotes the total size of the volume group, the suffix %FREE the remaining free space in the volume group, and the suffix %PVS the free space in the specified physical volumes. For a snapshot, the size can be expressed as a percentage of the total size of the origin logical volume with the suffix %ORIGIN (100%ORIGIN provides space for the whole origin). When expressed as a percentage, the size defines an upper limit for the number of logical extents in the new logical volume. The precise number of logical extents in the new LV is not determined until the command has completed.
mylv
that uses 60% of the total space in volume group testvg
.
# lvcreate -l 60%VG -n mylv testvg
yourlv
that uses all of the unallocated space in the volume group testvg
.
# lvcreate -l 100%FREE -n yourlv testvg
-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.
mylv
that fills the volume group named testvg
.
#vgdisplay testvg | grep "Total PE"
Total PE 10230 #lvcreate -l 10230 -n mylv testvg
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 -n testlv testvg /dev/sdg1
/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
/dev/sda1
and then continues laying out the logical volume at extent 100.
# lvcreate -l 100 -n testlv testvg /dev/sda1:0-25:100-
inherit
, which applies the same policy as for the volume group. These policies can be changed using the lvchange
command. For information on allocation policies, see Section 4.3.1, “Creating Volume Groups”.
4.4.2. Creating Striped Volumes
-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).
gfslv
, and is carved out of volume group vg0
.
# lvcreate -L 50G -i 2 -I 64 -n gfslv vg0
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 -i 2 -n stripelv testvg /dev/sda1:0-49 /dev/sdb1:50-99
Using default stripesize 64.00 KB
Logical volume "stripelv" created
4.4.3. RAID Logical Volumes
Note
mirror
segment type, as described in Section 4.4.4, “Creating Mirrored Volumes”.
--type
argument of the lvcreate
command. Table 4.1, “RAID Segment Types” describes the possible RAID segment types.
Table 4.1. RAID Segment Types
Segment type | Description | ||
---|---|---|---|
raid1 | RAID1 mirroring. This is the default value for the --type argument of the lvcreate command when you specify the -m but you do not specify striping. | ||
raid4 | RAID4 dedicated parity disk | ||
raid5 | Same as raid5_ls | ||
raid5_la |
| ||
raid5_ra |
| ||
raid5_ls |
| ||
raid5_rs |
| ||
raid6 | Same as raid6_zr | ||
raid6_zr |
| ||
raid6_nr |
| ||
raid6_nc |
| ||
raid10 |
| ||
raid0/raid0_meta (Red Hat Enterprise Linux 7.3 and later) | Striping. RAID0 spreads logical volume data across multiple data subvolumes in units of stripe size. This is used to increase performance. Logical volume data will be lost if any of the data subvolumes fail. For information on creating RAID0 volumes, see Section 4.4.3.1, “Creating RAID0 Volumes (Red Hat Enterprise Linux 7.3 and Later)”. |
raid1
, raid4
, raid5
, raid6
, raid10
) should be sufficient.
lv_rmeta_0
and lv_rmeta_1
) and two data subvolumes (lv_rimage_0
and lv_rimage_1
). Similarly, creating a 3-way stripe (plus 1 implicit parity device) RAID4 results in 4 metadata subvolumes (lv_rmeta_0
, lv_rmeta_1
, lv_rmeta_2
, and lv_rmeta_3
) and 4 data subvolumes (lv_rimage_0
, lv_rimage_1
, lv_rimage_2
, and lv_rimage_3
).
my_lv
in the volume group my_vg
that is one gigabyte in size.
# lvcreate --type raid1 -m 1 -L 1G -n my_lv my_vg
-m
argument. Similarly, you specify the number of stripes for a RAID 4/5/6 logical volume with the -i argument
. You can also specify the stripe size with the -I
argument.
my_lv
in the volume group my_vg
that is one gigabyte in size. Note that you specify the number of stripes just as you do for an LVM striped volume; the correct number of parity drives is added automatically.
# lvcreate --type raid5 -i 3 -L 1G -n my_lv my_vg
my_lv
in the volume group my_vg
that is one gigabyte in size.
# lvcreate --type raid6 -i 3 -L 1G -n my_lv my_vg
sync
operation can crowd out other I/O operations to LVM devices, such as updates to volume group metadata, particularly when you are creating many RAID logical volumes. This can cause the other LVM operations to slow down.
sync
operations are performed by setting the minimum and maximum I/O rate for those operations with the --minrecoveryrate
and --maxrecoveryrate
options of the lvcreate
command. You specify these options as follows.
--maxrecoveryrate Rate[bBsSkKmMgG]
Sets the maximum recovery rate for a RAID logical volume so that it will not crowd out nominal I/O operations. The Rate is specified as an amount per second for each device in the array. If no suffix is given, then kiB/sec/device is assumed. Setting the recovery rate to 0 means it will be unbounded.--minrecoveryrate Rate[bBsSkKmMgG]
Sets the minimum recovery rate for a RAID logical volume to ensure that I/O forsync
operations achieves a minimum throughput, even when heavy nominal I/O is present. The Rate is specified as an amount per second for each device in the array. If no suffix is given, then kiB/sec/device is assumed.
my_lv
and is in the volume group my_vg
.
# lvcreate --type raid10 -i 2 -m 1 -L 10G --maxrecoveryrate 128 -n my_lv my_vg
Note
4.4.3.1. Creating RAID0 Volumes (Red Hat Enterprise Linux 7.3 and Later)
lvcreate --type raid0[_meta] --stripes Stripes --stripesize StripeSize VolumeGroup [PhysicalVolumePath ...]
Table 4.2. RAID0 Command Creation parameters
Parameter | Description |
---|---|
--type raid0[_meta] | Specifying raid0 creates a RAID0 volume without metadata volumes. Specifying raid0_meta creates a RAID0 volume with metadata volumes. Because RAID0 is non-resilient, it does not have to store any mirrored data blocks as RAID1/10 or calculate and store any parity blocks as RAID4/5/6 do. Hence, it does not need metadata volumes to keep state about resynchronization progress of mirrored or parity blocks. Metadata volumes become mandatory on a conversion from RAID0 to RAID4/5/6/10, however, and specifying raid0_meta preallocates those metadata volumes to prevent a respective allocation failure. |
--stripes Stripes | Specifies the number of devices to spread the logical volume across. |
--stripesize StripeSize | Specifies the size of each stripe in kilobytes. This is the amount of data that is written to one device before moving to the next device. |
VolumeGroup | Specifies the volume group to use. |
PhysicalVolumePath ... | Specifies the devices to use. If this is not specified, LVM will choose the number of devices specified by the Stripes option, one for each stripe. |
4.4.3.2. Converting a Linear Device to a RAID Device
--type
argument of the lvconvert
command.
my_lv
in volume group my_vg
to a 2-way RAID1 array.
# lvconvert --type raid1 -m 1 my_vg/my_lv
# lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices
my_lv /dev/sde1(0)
#lvconvert --type raid1 -m 1 my_vg/my_lv
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 6.25 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sde1(0) [my_lv_rimage_1] /dev/sdf1(1) [my_lv_rmeta_0] /dev/sde1(256) [my_lv_rmeta_1] /dev/sdf1(0)
lvconvert
will fail.
4.4.3.3. Converting an LVM RAID1 Logical Volume to an LVM Linear Logical Volume
lvconvert
command by specifying the -m0
argument. This removes all the RAID data subvolumes and all the RAID metadata subvolumes that make up the RAID array, leaving the top-level RAID1 image as the linear logical volume.
# lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices
my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0)
[my_lv_rimage_0] /dev/sde1(1)
[my_lv_rimage_1] /dev/sdf1(1)
[my_lv_rmeta_0] /dev/sde1(0)
[my_lv_rmeta_1] /dev/sdf1(0)
my_vg/my_lv
to an LVM linear device.
#lvconvert -m0 my_vg/my_lv
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv /dev/sde1(1)
/dev/sda1
and /dev/sdb1
. In this example, the lvconvert
command specifies that you want to remove /dev/sda1
, leaving /dev/sdb1
as the physical volume that makes up the linear device.
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sda1(1) [my_lv_rimage_1] /dev/sdb1(1) [my_lv_rmeta_0] /dev/sda1(0) [my_lv_rmeta_1] /dev/sdb1(0) #lvconvert -m0 my_vg/my_lv /dev/sda1
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv /dev/sdb1(1)
4.4.3.4. Converting a Mirrored LVM Device to a RAID1 Device
mirror
to a RAID1 LVM device with the lvconvert
command by specifying the --type raid1
argument. This renames the mirror subvolumes (*_mimage_*
) to RAID subvolumes (*_rimage_*
). In addition, the mirror log is removed and metadata subvolumes (*_rmeta_*
) are created for the data subvolumes on the same physical volumes as the corresponding data subvolumes.
my_vg/my_lv
.
# lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices
my_lv 15.20 my_lv_mimage_0(0),my_lv_mimage_1(0)
[my_lv_mimage_0] /dev/sde1(0)
[my_lv_mimage_1] /dev/sdf1(0)
[my_lv_mlog] /dev/sdd1(0)
my_vg/my_lv
to a RAID1 logical volume.
#lvconvert --type raid1 my_vg/my_lv
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sde1(0) [my_lv_rimage_1] /dev/sdf1(0) [my_lv_rmeta_0] /dev/sde1(125) [my_lv_rmeta_1] /dev/sdf1(125)
4.4.3.5. Resizing a RAID Logical Volume
- You can increase the size of a RAID logical volume of any type with the
lvresize
orlvextend
command. This does not change the number of RAID images. For striped RAID logical volumes the same stripe rounding constraints apply as when you create a striped RAID logical volume. For more information on extending a RAID volume, see Section 4.4.18, “Extending a RAID Volume”. - You can reduce the size of a RAID logical volume of any type with the
lvresize
orlvreduce
command. This does not change the number of RAID images. As with thelvextend
command, the same stripe rounding constraints apply as when you create a striped RAID logical volume. For an example of a command to reduce the size of a logical volume, see Section 4.4.16, “Shrinking Logical Volumes”. - As of Red Hat Enterprise Linux 7.4, you can change the number of stripes on a striped RAID logical volume (
raid4/5/6/10
) with the--stripes N
parameter of thelvconvert
command. This increases or reduces the size of the RAID logical volume by the capacity of the stripes added or removed. Note thatraid10
volumes are capable only of adding stripes. This capability is part of the RAID reshaping feature that allows you to change attributes of a RAID logical volume while keeping the same RAID level. For information on RAID reshaping and examples of using thelvconvert
command to reshape a RAID logical volume, see thelvmraid
(7) man page.
4.4.3.6. Changing the Number of Images in an Existing RAID1 Device
lvconvert
command to specify the number of additional metadata/data subvolume pairs to add or remove. For information on changing the volume configuration in the earlier implementation of LVM mirroring, see Section 4.4.4.4, “Changing Mirrored Volume Configuration”.
lvconvert
command, you can specify the total number of images for the resulting device, or you can specify how many images to add to the device. You can also optionally specify on which physical volumes the new metadata/data image pairs will reside.
*_rmeta_*
) always exist on the same physical devices as their data subvolume counterparts *_rimage_*
). The metadata/data subvolume pairs will not be created on the same physical volumes as those from another metadata/data subvolume pair in the RAID array (unless you specify --alloc anywhere
).
lvconvert -m new_absolute_count vg/lv [removable_PVs] lvconvert -m +num_additional_images vg/lv [removable_PVs]
my_vg/my_lv
, which is a 2-way RAID1 array:
# lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices
my_lv 6.25 my_lv_rimage_0(0),my_lv_rimage_1(0)
[my_lv_rimage_0] /dev/sde1(0)
[my_lv_rimage_1] /dev/sdf1(1)
[my_lv_rmeta_0] /dev/sde1(256)
[my_lv_rmeta_1] /dev/sdf1(0)
my_vg/my_lv
to a 3-way RAID1 device:
#lvconvert -m 2 my_vg/my_lv
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 6.25 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0) [my_lv_rimage_0] /dev/sde1(0) [my_lv_rimage_1] /dev/sdf1(1) [my_lv_rimage_2] /dev/sdg1(1) [my_lv_rmeta_0] /dev/sde1(256) [my_lv_rmeta_1] /dev/sdf1(0) [my_lv_rmeta_2] /dev/sdg1(0)
my_vg/my_lv
to a 3-way RAID1 device, specifying that the physical volume /dev/sdd1
be used for the array:
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 56.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sda1(1) [my_lv_rimage_1] /dev/sdb1(1) [my_lv_rmeta_0] /dev/sda1(0) [my_lv_rmeta_1] /dev/sdb1(0) #lvconvert -m 2 my_vg/my_lv /dev/sdd1
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 28.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0) [my_lv_rimage_0] /dev/sda1(1) [my_lv_rimage_1] /dev/sdb1(1) [my_lv_rimage_2] /dev/sdd1(1) [my_lv_rmeta_0] /dev/sda1(0) [my_lv_rmeta_1] /dev/sdb1(0) [my_lv_rmeta_2] /dev/sdd1(0)
lvconvert
command, you can specify the total number of images for the resulting device, or you can specify how many images to remove from the device. You can also optionally specify the physical volumes from which to remove the device.
lvconvert -m new_absolute_count vg/lv [removable_PVs] lvconvert -m -num_fewer_images vg/lv [removable_PVs]
lv_rimage_1
from a 3-way RAID1 array that consists of lv_rimage_0
, lv_rimage_1
, and lv_rimage_2
, this results in a RAID1 array that consists of lv_rimage_0
and lv_rimage_1
. The subvolume lv_rimage_2
will be renamed and take over the empty slot, becoming lv_rimage_1
.
my_vg/my_lv
.
# lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices
my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0)
[my_lv_rimage_0] /dev/sde1(1)
[my_lv_rimage_1] /dev/sdf1(1)
[my_lv_rimage_2] /dev/sdg1(1)
[my_lv_rmeta_0] /dev/sde1(0)
[my_lv_rmeta_1] /dev/sdf1(0)
[my_lv_rmeta_2] /dev/sdg1(0)
#lvconvert -m1 my_vg/my_lv
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sde1(1) [my_lv_rimage_1] /dev/sdf1(1) [my_lv_rmeta_0] /dev/sde1(0) [my_lv_rmeta_1] /dev/sdf1(0)
/dev/sde1
.
#lvconvert -m1 my_vg/my_lv /dev/sde1
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sdf1(1) [my_lv_rimage_1] /dev/sdg1(1) [my_lv_rmeta_0] /dev/sdf1(0) [my_lv_rmeta_1] /dev/sdg1(0)
4.4.3.7. Splitting off a RAID Image as a Separate Logical Volume
lvconvert --splitmirrors count -n splitname vg/lv [removable_PVs]
Note
my_lv
, into two linear logical volumes, my_lv
and new
.
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 12.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sde1(1) [my_lv_rimage_1] /dev/sdf1(1) [my_lv_rmeta_0] /dev/sde1(0) [my_lv_rmeta_1] /dev/sdf1(0) #lvconvert --splitmirror 1 -n new my_vg/my_lv
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv /dev/sde1(1) new /dev/sdf1(1)
my_lv
, into a 2-way RAID1 logical volume, my_lv
, and a linear logical volume, new
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0) [my_lv_rimage_0] /dev/sde1(1) [my_lv_rimage_1] /dev/sdf1(1) [my_lv_rimage_2] /dev/sdg1(1) [my_lv_rmeta_0] /dev/sde1(0) [my_lv_rmeta_1] /dev/sdf1(0) [my_lv_rmeta_2] /dev/sdg1(0) #lvconvert --splitmirror 1 -n new my_vg/my_lv
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sde1(1) [my_lv_rimage_1] /dev/sdf1(1) [my_lv_rmeta_0] /dev/sde1(0) [my_lv_rmeta_1] /dev/sdf1(0) new /dev/sdg1(1)
4.4.3.8. Splitting and Merging a RAID Image
--trackchanges
argument in conjunction with the --splitmirrors
argument of the lvconvert
command. This allows you to merge the image back into the array at a later time while resyncing only those portions of the array that have changed since the image was split.
lvconvert
command to split off a RAID image is as follows.
lvconvert --splitmirrors count --trackchanges vg/lv [removable_PVs]
--trackchanges
argument, you can specify which image to split but you cannot change the name of the volume being split. In addition, the resulting volumes have the following constraints.
- The new volume you create is read-only.
- You cannot resize the new volume.
- You cannot rename the remaining array.
- You cannot resize the remaining array.
- You can activate the new volume and the remaining array independently.
--trackchanges
argument specified by executing a subsequent lvconvert
command with the --merge
argument. When you merge the image, only the portions of the array that have changed since the image was split are resynced.
lvconvert
command to merge a RAID image is as follows.
lvconvert --merge raid_image
#lvcreate --type raid1 -m 2 -L 1G -n my_lv .vg
Logical volume "my_lv" created #lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0) [my_lv_rimage_0] /dev/sdb1(1) [my_lv_rimage_1] /dev/sdc1(1) [my_lv_rimage_2] /dev/sdd1(1) [my_lv_rmeta_0] /dev/sdb1(0) [my_lv_rmeta_1] /dev/sdc1(0) [my_lv_rmeta_2] /dev/sdd1(0) #lvconvert --splitmirrors 1 --trackchanges my_vg/my_lv
my_lv_rimage_2 split from my_lv for read-only purposes. Use 'lvconvert --merge my_vg/my_lv_rimage_2' to merge back into my_lv #lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0) [my_lv_rimage_0] /dev/sdb1(1) [my_lv_rimage_1] /dev/sdc1(1) my_lv_rimage_2 /dev/sdd1(1) [my_lv_rmeta_0] /dev/sdb1(0) [my_lv_rmeta_1] /dev/sdc1(0) [my_lv_rmeta_2] /dev/sdd1(0)
#lvconvert --splitmirrors 1 --trackchanges my_vg/my_lv
lv_rimage_1 split from my_lv for read-only purposes. Use 'lvconvert --merge my_vg/my_lv_rimage_1' to merge back into my_lv #lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sdc1(1) my_lv_rimage_1 /dev/sdd1(1) [my_lv_rmeta_0] /dev/sdc1(0) [my_lv_rmeta_1] /dev/sdd1(0) #lvconvert --merge my_vg/my_lv_rimage_1
my_vg/my_lv_rimage_1 successfully merged back into my_vg/my_lv #lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sdc1(1) [my_lv_rimage_1] /dev/sdd1(1) [my_lv_rmeta_0] /dev/sdc1(0) [my_lv_rmeta_1] /dev/sdd1(0)
lvconvert --splitmirrors
command, repeating the initial lvconvert
command that split the image without specifying the --trackchanges
argument. This breaks the link that the --trackchanges
argument created.
--trackchanges
argument, you cannot issue a subsequent lvconvert --splitmirrors
command on that array unless your intent is to permanently split the image being tracked.
#lvconvert --splitmirrors 1 --trackchanges my_vg/my_lv
my_lv_rimage_1 split from my_lv for read-only purposes. Use 'lvconvert --merge my_vg/my_lv_rimage_1' to merge back into my_lv #lvconvert --splitmirrors 1 -n new my_vg/my_lv
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv /dev/sdc1(1) new /dev/sdd1(1)
#lvconvert --splitmirrors 1 --trackchanges my_vg/my_lv
my_lv_rimage_1 split from my_lv for read-only purposes. Use 'lvconvert --merge my_vg/my_lv_rimage_1' to merge back into my_lv #lvconvert --splitmirrors 1 --trackchanges my_vg/my_lv
Cannot track more than one split image at a time
#lvconvert --splitmirrors 1 --trackchanges my_vg/my_lv
my_lv_rimage_1 split from my_lv for read-only purposes. Use 'lvconvert --merge my_vg/my_lv_rimage_1' to merge back into my_lv #lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sdc1(1) my_lv_rimage_1 /dev/sdd1(1) [my_lv_rmeta_0] /dev/sdc1(0) [my_lv_rmeta_1] /dev/sdd1(0) #lvconvert --splitmirrors 1 -n new my_vg/my_lv /dev/sdc1
Unable to split additional image from my_lv while tracking changes for my_lv_rimage_1
4.4.3.9. Setting a RAID fault policy
raid_fault_policy
field in the lvm.conf
file.
- If the
raid_fault_policy
field is set toallocate
, the system will attempt to replace the failed device with a spare device from the volume group. If there is no available spare device, this will be reported to the system log. - If the
raid_fault_policy
field is set towarn
, the system will produce a warning and the log will indicate that a device has failed. This allows the user to determine the course of action to take.
4.4.3.9.1. The allocate RAID Fault Policy
raid_fault_policy
field has been set to allocate
in the lvm.conf
file. The RAID logical volume is laid out as follows.
# lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices
my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0)
[my_lv_rimage_0] /dev/sde1(1)
[my_lv_rimage_1] /dev/sdf1(1)
[my_lv_rimage_2] /dev/sdg1(1)
[my_lv_rmeta_0] /dev/sde1(0)
[my_lv_rmeta_1] /dev/sdf1(0)
[my_lv_rmeta_2] /dev/sdg1(0)
/dev/sde
device fails, the system log will display error messages.
# grep lvm /var/log/messages
Jan 17 15:57:18 bp-01 lvm[8599]: Device #0 of raid1 array, my_vg-my_lv, has failed.
Jan 17 15:57:18 bp-01 lvm[8599]: /dev/sde1: read failed after 0 of 2048 at
250994294784: Input/output error
Jan 17 15:57:18 bp-01 lvm[8599]: /dev/sde1: read failed after 0 of 2048 at
250994376704: Input/output error
Jan 17 15:57:18 bp-01 lvm[8599]: /dev/sde1: read failed after 0 of 2048 at 0:
Input/output error
Jan 17 15:57:18 bp-01 lvm[8599]: /dev/sde1: read failed after 0 of 2048 at
4096: Input/output error
Jan 17 15:57:19 bp-01 lvm[8599]: Couldn't find device with uuid
3lugiV-3eSP-AFAR-sdrP-H20O-wM2M-qdMANy.
Jan 17 15:57:27 bp-01 lvm[8599]: raid1 array, my_vg-my_lv, is not in-sync.
Jan 17 15:57:36 bp-01 lvm[8599]: raid1 array, my_vg-my_lv, is now in-sync.
raid_fault_policy
field has been set to allocate
, the failed device is replaced with a new device from the volume group.
# lvs -a -o name,copy_percent,devices vg
Couldn't find device with uuid 3lugiV-3eSP-AFAR-sdrP-H20O-wM2M-qdMANy.
LV Copy% Devices
lv 100.00 lv_rimage_0(0),lv_rimage_1(0),lv_rimage_2(0)
[lv_rimage_0] /dev/sdh1(1)
[lv_rimage_1] /dev/sdf1(1)
[lv_rimage_2] /dev/sdg1(1)
[lv_rmeta_0] /dev/sdh1(0)
[lv_rmeta_1] /dev/sdf1(0)
[lv_rmeta_2] /dev/sdg1(0)
vgreduce --removemissing VG
.
raid_fault_policy
has been set to allocate
but there are no spare devices, the allocation will fail, leaving the logical volume as it is. If the allocation fails, you have the option of fixing the drive, then deactivating and activating the logical volume; this is described in Section 4.4.3.9.2, “The warn RAID Fault Policy”. Alternately, you can replace the failed device, as described in Section 4.4.3.10, “Replacing a RAID device”.
4.4.3.9.2. The warn RAID Fault Policy
raid_fault_policy
field has been set to warn
in the lvm.conf
file. The RAID logical volume is laid out as follows.
# lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices
my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0)
[my_lv_rimage_0] /dev/sdh1(1)
[my_lv_rimage_1] /dev/sdf1(1)
[my_lv_rimage_2] /dev/sdg1(1)
[my_lv_rmeta_0] /dev/sdh1(0)
[my_lv_rmeta_1] /dev/sdf1(0)
[my_lv_rmeta_2] /dev/sdg1(0)
/dev/sdh
device fails, the system log will display error messages. In this case, however, LVM will not automatically attempt to repair the RAID device by replacing one of the images. Instead, if the device has failed you can replace the device with the --repair
argument of the lvconvert
command, as shown below.
#lvconvert --repair my_vg/my_lv
/dev/sdh1: read failed after 0 of 2048 at 250994294784: Input/output error /dev/sdh1: read failed after 0 of 2048 at 250994376704: Input/output error /dev/sdh1: read failed after 0 of 2048 at 0: Input/output error /dev/sdh1: read failed after 0 of 2048 at 4096: Input/output error Couldn't find device with uuid fbI0YO-GX7x-firU-Vy5o-vzwx-vAKZ-feRxfF. Attempt to replace failed RAID images (requires full device resync)? [y/n]:y
#lvs -a -o name,copy_percent,devices my_vg
Couldn't find device with uuid fbI0YO-GX7x-firU-Vy5o-vzwx-vAKZ-feRxfF. LV Copy% Devices my_lv 64.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0) [my_lv_rimage_0] /dev/sde1(1) [my_lv_rimage_1] /dev/sdf1(1) [my_lv_rimage_2] /dev/sdg1(1) [my_lv_rmeta_0] /dev/sde1(0) [my_lv_rmeta_1] /dev/sdf1(0) [my_lv_rmeta_2] /dev/sdg1(0)
vgreduce --removemissing VG
.
--refresh
option of the lvchange
command. Previously it was necessary to deactivate and then activate the logical volume.
# lvchange --refresh my_vg/my_lv
4.4.3.10. Replacing a RAID device
--replace
argument of the lvconvert
command.
lvconvert --replace
is as follows.
lvconvert --replace dev_to_remove vg/lv [possible_replacements]
#lvcreate --type raid1 -m 2 -L 1G -n my_lv my_vg
Logical volume "my_lv" created #lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0) [my_lv_rimage_0] /dev/sdb1(1) [my_lv_rimage_1] /dev/sdb2(1) [my_lv_rimage_2] /dev/sdc1(1) [my_lv_rmeta_0] /dev/sdb1(0) [my_lv_rmeta_1] /dev/sdb2(0) [my_lv_rmeta_2] /dev/sdc1(0) #lvconvert --replace /dev/sdb2 my_vg/my_lv
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 37.50 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0) [my_lv_rimage_0] /dev/sdb1(1) [my_lv_rimage_1] /dev/sdc2(1) [my_lv_rimage_2] /dev/sdc1(1) [my_lv_rmeta_0] /dev/sdb1(0) [my_lv_rmeta_1] /dev/sdc2(0) [my_lv_rmeta_2] /dev/sdc1(0)
#lvcreate --type raid1 -m 1 -L 100 -n my_lv my_vg
Logical volume "my_lv" created #lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sda1(1) [my_lv_rimage_1] /dev/sdb1(1) [my_lv_rmeta_0] /dev/sda1(0) [my_lv_rmeta_1] /dev/sdb1(0) #pvs
PV VG Fmt Attr PSize PFree /dev/sda1 my_vg lvm2 a-- 1020.00m 916.00m /dev/sdb1 my_vg lvm2 a-- 1020.00m 916.00m /dev/sdc1 my_vg lvm2 a-- 1020.00m 1020.00m /dev/sdd1 my_vg lvm2 a-- 1020.00m 1020.00m #lvconvert --replace /dev/sdb1 my_vg/my_lv /dev/sdd1
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 28.00 my_lv_rimage_0(0),my_lv_rimage_1(0) [my_lv_rimage_0] /dev/sda1(1) [my_lv_rimage_1] /dev/sdd1(1) [my_lv_rmeta_0] /dev/sda1(0) [my_lv_rmeta_1] /dev/sdd1(0)
replace
arguments, as in the following example.
#lvcreate --type raid1 -m 2 -L 100 -n my_lv my_vg
Logical volume "my_lv" created #lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 100.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0) [my_lv_rimage_0] /dev/sda1(1) [my_lv_rimage_1] /dev/sdb1(1) [my_lv_rimage_2] /dev/sdc1(1) [my_lv_rmeta_0] /dev/sda1(0) [my_lv_rmeta_1] /dev/sdb1(0) [my_lv_rmeta_2] /dev/sdc1(0) #lvconvert --replace /dev/sdb1 --replace /dev/sdc1 my_vg/my_lv
#lvs -a -o name,copy_percent,devices my_vg
LV Copy% Devices my_lv 60.00 my_lv_rimage_0(0),my_lv_rimage_1(0),my_lv_rimage_2(0) [my_lv_rimage_0] /dev/sda1(1) [my_lv_rimage_1] /dev/sdd1(1) [my_lv_rimage_2] /dev/sde1(1) [my_lv_rmeta_0] /dev/sda1(0) [my_lv_rmeta_1] /dev/sdd1(0) [my_lv_rmeta_2] /dev/sde1(0)
Note
lvconvert --replace
command, the replacement drives should never be allocated from extra space on drives already used in the array. For example, lv_rimage_0
and lv_rimage_1
should not be located on the same physical volume.
4.4.3.11. Scrubbing a RAID Logical Volume
--syncaction
option of the lvchange
command. You specify either a check
or repair
operation. A check
operation goes over the array and records the number of discrepancies in the array but does not repair them. A repair
operation corrects the discrepancies as it finds them.
lvchange --syncaction {check|repair} vg/raid_lv
Note
lvchange --syncaction repair vg/raid_lv
operation does not perform the same function as the lvconvert --repair vg/raid_lv
operation. The lvchange --syncaction repair
operation initiates a background synchronization operation on the array, while the lvconvert --repair
operation is designed to repair/replace failed devices in a mirror or RAID logical volume.
lvs
command now supports two new printable fields: raid_sync_action
and raid_mismatch_count
. These fields are not printed by default. To display these fields you specify them with the -o
parameter of the lvs
, as follows.
lvs -o +raid_sync_action,raid_mismatch_count vg/lv
raid_sync_action
field displays the current synchronization operation that the raid volume is performing. It can be one of the following values:
idle
: All sync operations complete (doing nothing)resync
: Initializing an array or recovering after a machine failurerecover
: Replacing a device in the arraycheck
: Looking for array inconsistenciesrepair
: Looking for and repairing inconsistencies
raid_mismatch_count
field displays the number of discrepancies found during a check
operation.
Cpy%Sync
field of the lvs
command now prints the progress of any of the raid_sync_action
operations, including check
and repair
.
lv_attr
field of the lvs
command output now provides additional indicators in support of the RAID scrubbing operation. Bit 9 of this field displays the health of the logical volume, and it now supports the following indicators.
- (m)ismatches indicates that there are discrepancies in a RAID logical volume. This character is shown after a scrubbing operation has detected that portions of the RAID are not coherent.
- (r)efresh indicates that a device in a RAID array has suffered a failure and the kernel regards it as failed, even though LVM can read the device label and considers the device to be operational. The logical volume should be (r)efreshed to notify the kernel that the device is now available, or the device should be (r)eplaced if it is suspected of having failed.
lvs
command, see Section 4.8.2, “Object Display Fields”.
sync
operations can crowd out other I/O operations to LVM devices, such as updates to volume group metadata. This can cause the other LVM operations to slow down. You can control the rate at which the RAID logical volume is scrubbed by implementing recovery throttling.
sync
operations are performed by setting the minimum and maximum I/O rate for those operations with the --minrecoveryrate
and --maxrecoveryrate
options of the lvchange
command. You specify these options as follows.
--maxrecoveryrate Rate[bBsSkKmMgG]
Sets the maximum recovery rate for a RAID logical volume so that it will not crowd out nominal I/O operations. The Rate is specified as an amount per second for each device in the array. If no suffix is given, then kiB/sec/device is assumed. Setting the recovery rate to 0 means it will be unbounded.--minrecoveryrate Rate[bBsSkKmMgG]
Sets the minimum recovery rate for a RAID logical volume to ensure that I/O forsync
operations achieves a minimum throughput, even when heavy nominal I/O is present. The Rate is specified as an amount per second for each device in the array. If no suffix is given, then kiB/sec/device is assumed.
4.4.3.12. RAID Takeover (Red Hat Enterprise Linux 7.4 and Later)
lvconvert
for RAID takeover. For information on RAID takeover and for examples of using the lvconvert
to convert a RAID logical volume, see the lvmraid
(7) man page.
4.4.3.13. Reshaping a RAID Logical Volume (Red Hat Enterprise Linux 7.4 and Later)
lvconvert
command to reshape a RAID logical volume, see the lvmraid
(7) man page.
4.4.3.14. Controlling I/O Operations on a RAID1 Logical Volume
--writemostly
and --writebehind
parameters of the lvchange
command. The format for using these parameters is as follows.
--[raid]writemostly PhysicalVolume[:{t|y|n}]
Marks a device in a RAID1 logical volume aswrite-mostly
. All reads to these drives will be avoided unless necessary. Setting this parameter keeps the number of I/O operations to the drive to a minimum. By default, thewrite-mostly
attribute is set to yes for the specified physical volume in the logical volume. It is possible to remove thewrite-mostly
flag by appending:n
to the physical volume or to toggle the value by specifying:t
. The--writemostly
argument can be specified more than one time in a single command, making it possible to toggle the write-mostly attributes for all the physical volumes in a logical volume at once.--[raid]writebehind IOCount
Specifies the maximum number of outstanding writes that are allowed to devices in a RAID1 logical volume that are marked aswrite-mostly
. Once this value is exceeded, writes become synchronous, causing all writes to the constituent devices to complete before the array signals the write has completed. Setting the value to zero clears the preference and allows the system to choose the value arbitrarily.
4.4.3.15. Changing the region size on a RAID Logical Volume (Red Hat Enterprise Linux 7.4 and later)
raid_region_size
parameter in the /etc/lvm/lvm.conf
file. You can override this default value with the -R
option of the lvcreate
command.
-R
option of the lvconvert
command. The following example changes the region size of logical volume vg/raidlv
to 4096K. The RAID volume must be synced in order to change the region size.
#lvconvert -R 4096K vg/raid1
Do you really want to change the region_size 512.00 KiB of LV vg/raid1 to 4.00 MiB? [y/n]:y
Changed region size on RAID LV vg/raid1 to 4.00 MiB.
4.4.4. Creating Mirrored Volumes
mirror
segment type, as described in this section.
Note
mirror
to a RAID1 LVM device, see Section 4.4.3.4, “Converting a Mirrored LVM Device to a RAID1 Device”.
Note
mirror
on a single node. However, in order to create a mirrored LVM volume in a cluster, the cluster and cluster mirror infrastructure must be running, the cluster must be quorate, and the locking type in the lvm.conf
file must be set correctly to enable cluster locking. For an example of creating a mirrored volume in a cluster, see Section 5.5, “Creating a Mirrored LVM Logical Volume in a Cluster”.
-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.
mirrorlv
, and is carved out of volume group vg0
:
# lvcreate --type mirror -L 50G -m 1 -n mirrorlv vg0
-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.
Note
-R
argument to the lvcreate
command. For example, if your mirror size is 1.5TB, you could specify -R 2
. If your mirror size is 3TB, you could specify -R 4
. For a mirror size of 5TB, you could specify -R 8
.
# lvcreate --type mirror -m 1 -L 2T -R 2 -n mirror vol_group
--nosync
argument to indicate that an initial synchronization from the first device is not required.
--mirrorlog core
argument; this eliminates the need for an extra log device, but it requires that the entire mirror be resynchronized at every reboot.
bigvg
. The logical volume is named ondiskmirvol
and has a single mirror. The volume is 12MB in size and keeps the mirror log in memory.
# lvcreate --type mirror -L 12MB -m 1 --mirrorlog core -n ondiskmirvol bigvg
Logical volume "ondiskmirvol" created
--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.
vg0
consists of only two devices. This command creates a 500 MB volume named mirrorlv
in the vg0
volume group.
# lvcreate --type mirror -L 500M -m 1 -n mirrorlv -alloc anywhere vg0
Note
--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 12MB in size and the mirror log is mirrored, with each log kept on a separate device.
# lvcreate --type mirror -L 12MB -m 1 --mirrorlog mirrored -n twologvol bigvg
Logical volume "twologvol" created
--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.
--nosync
argument to indicate that an initial synchronization from the first device is not required.
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 --type mirror -L 500M -m 1 -n mirrorlv vg0 /dev/sda1 /dev/sdb1 /dev/sdc1
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 1MB extents. If any of the specified extents have already been allocated, they will be ignored.
# lvcreate --type mirror -L 500M -m 1 -n mirrorlv vg0 /dev/sda1:0-499 /dev/sdb1:0-499 /dev/sdc1:0
Note
--mirrors X
) and the number of stripes (--stripes Y
) results in a mirror device whose constituent devices are striped.
4.4.4.1. Mirrored Logical Volume Failure Policy
mirror_image_fault_policy
and mirror_log_fault_policy
parameters in the activation
section of the lvm.conf
file. When these parameters are set to remove
, the system attempts to remove the faulty device and run without it. When these parameters are set to allocate
, the system attempts to remove the faulty device and tries to allocate space on a new device to be a replacement for the failed device. This policy acts like the remove
policy if no suitable device and space can be allocated for the replacement.
mirror_log_fault_policy
parameter is set to allocate
. Using this policy for the log is fast and maintains the ability to remember the sync state through crashes and reboots. If you set this policy to remove
, when a log device fails the mirror converts to using an in-memory log; in this instance, the mirror will not remember its sync status across crashes and reboots and the entire mirror will be re-synced.
mirror_image_fault_policy
parameter is set to remove
. With this policy, if a mirror image fails the mirror will convert to a non-mirrored device if there is only one remaining good copy. Setting this policy to allocate
for a mirror device requires the mirror to resynchronize the devices; this is a slow process, but it preserves the mirror characteristic of the device.
Note
mirror_log_fault_policy
parameter is set to allocate
, is to attempt to replace any of the failed devices. Note, however, that there is no guarantee that the second stage will choose devices previously in-use by the mirror that had not been part of the failure if others are available.
4.4.4.2. Splitting Off a Redundant Image of a Mirrored Logical Volume
--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.
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
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
4.4.4.3. Repairing a Mirrored Logical Device
lvconvert --repair
command to repair a mirror after a disk failure. This brings the mirror back into a consistent state. The lvconvert --repair
command is an interactive command that prompts you to indicate whether you want the system to attempt to replace any failed devices.
- To skip the prompts and replace all of the failed devices, specify the
-y
option on the command line. - To skip the prompts and replace none of the failed devices, specify the
-f
option on the command line. - To skip the prompts and still indicate different replacement policies for the mirror image and the mirror log, you can specify the
--use-policies
argument to use the device replacement policies specified by themirror_log_fault_policy
andmirror_device_fault_policy
parameters in thelvm.conf
file.
4.4.4.4. Changing Mirrored Volume Configuration
lvconvert
command. This allows you to convert a logical volume from a mirrored volume to a linear volume or from a linear volume to a mirrored volume. You can also use this command to reconfigure other mirror parameters of an existing logical volume, such as corelog
.
lvconvert
command to restore the mirror. This procedure is provided in Section 6.3, “Recovering from LVM Mirror Failure”.
vg00/lvol1
to a mirrored logical volume.
# lvconvert -m1 vg00/lvol1
vg00/lvol1
to a linear logical volume, removing the mirror leg.
# lvconvert -m0 vg00/lvol1
vg00/lvol1
. This example shows the configuration of the volume before and after the lvconvert
command changed the volume to a volume with two mirror legs.
#lvs -a -o name,copy_percent,devices vg00
LV Copy% Devices lvol1 100.00 lvol1_mimage_0(0),lvol1_mimage_1(0) [lvol1_mimage_0] /dev/sda1(0) [lvol1_mimage_1] /dev/sdb1(0) [lvol1_mlog] /dev/sdd1(0) #lvconvert -m 2 vg00/lvol1
vg00/lvol1: Converted: 13.0% vg00/lvol1: Converted: 100.0% Logical volume lvol1 converted. #lvs -a -o name,copy_percent,devices vg00
LV Copy% Devices lvol1 100.00 lvol1_mimage_0(0),lvol1_mimage_1(0),lvol1_mimage_2(0) [lvol1_mimage_0] /dev/sda1(0) [lvol1_mimage_1] /dev/sdb1(0) [lvol1_mimage_2] /dev/sdc1(0) [lvol1_mlog] /dev/sdd1(0)
4.4.5. Creating Thinly-Provisioned Logical Volumes
Note
lvmthin
(7) man page.
Note
- Create a volume group with the
vgcreate
command. - Create a thin pool with the
lvcreate
command. - Create a thin volume in the thin pool with the
lvcreate
command.
-T
(or --thin
) option of the lvcreate
command to create either a thin pool or a thin volume. You can also use -T
option of the lvcreate
command to create both a thin pool and a thin volume in that pool at the same time with a single command.
-T
option of the lvcreate
command to create a thin pool named mythinpool
in the volume group vg001
and that is 100M in size. Note that since you are creating a pool of physical space, you must specify the size of the pool. The -T
option of the lvcreate
command does not take an argument; it deduces what type of device is to be created from the other options the command specifies.
#lvcreate -L 100M -T vg001/mythinpool
Rounding up size to full physical extent 4.00 MiB Logical volume "mythinpool" created #lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert my mythinpool vg001 twi-a-tz 100.00m 0.00
-T
option of the lvcreate
command to create a thin volume named thinvolume
in the thin pool vg001/mythinpool
. Note that in this case you are specifying virtual size, and that you are specifying a virtual size for the volume that is greater than the pool that contains it.
#lvcreate -V 1G -T vg001/mythinpool -n thinvolume
Logical volume "thinvolume" created #lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert mythinpool vg001 twi-a-tz 100.00m 0.00 thinvolume vg001 Vwi-a-tz 1.00g mythinpool 0.00
-T
option of the lvcreate
command to create a thin pool and a thin volume in that pool by specifying both a size and a virtual size argument for the lvcreate
command. This command creates a thin pool named mythinpool
in the volume group vg001
and it also creates a thin volume named thinvolume
in that pool.
#lvcreate -L 100M -T vg001/mythinpool -V 1G -n thinvolume
Rounding up size to full physical extent 4.00 MiB Logical volume "thinvolume" created #lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert mythinpool vg001 twi-a-tz 100.00m 0.00 thinvolume vg001 Vwi-a-tz 1.00g mythinpool 0.00
--thinpool
parameter of the lvcreate
command. Unlike the -T
option, the --thinpool
parameter requires an argument, which is the name of the thin pool logical volume that you are creating. The following example specifies the --thinpool
parameter of the lvcreate
command to create a thin pool named mythinpool
in the volume group vg001
and that is 100M in size:
#lvcreate -L 100M --thinpool mythinpool vg001
Rounding up size to full physical extent 4.00 MiB Logical volume "mythinpool" created #lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert mythinpool vg001 twi-a-tz 100.00m 0.00
- Smaller chunk size requires more metadata and hinders the performance, but it provides better space utilization with snapshots.
- Huge chunk size requires less metadata manipulation but makes the snapshot less efficient.
Warning
pool
in volume group vg001
with two 64 kB stripes and a chunk size of 256 kB. It also creates a 1T thin volume, vg00/thin_lv
.
# lvcreate -i 2 -I 64 -c 256 -L 100M -T vg00/pool -V 1T --name thin_lv
lvextend
command. You cannot, however, reduce the size of a thin pool.
#lvextend -L+100M vg001/mythinpool
Extending logical volume mythinpool to 200.00 MiB Logical volume mythinpool successfully resized #lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert mythinpool vg001 twi-a-tz 200.00m 0.00 thinvolume vg001 Vwi-a-tz 1.00g mythinpool 0.00
lvrename
, you can remove the volume with the lvremove
, and you can display information about the volume with the lvs
and lvdisplay
commands.
lvcreate
command sets the size of the thin pool's metadata logical volume according to the formula (Pool_LV_size / Pool_LV_chunk_size * 64). If you will have large numbers of snapshots or if you have small chunk sizes for your thin pool and thus expect significant growth of the size of the thin pool at a later time, you may need to increase the default value of the thin pool's metadata volume with the --poolmetadatasize
parameter of the lvcreate
command. The supported value for the thin pool's metadata logical volume is in the range between 2MiB and 16GiB.
--thinpool
parameter of the lvconvert
command to convert an existing logical volume to a thin pool volume. When you convert an existing logical volume to a thin pool volume, you must use the --poolmetadata
parameter in conjunction with the --thinpool
parameter of the lvconvert
to convert an existing logical volume to the thin pool volume's metadata volume.
Note
lvconvert
does not preserve the content of the devices but instead overwrites the content.
lv1
in volume group vg001
to a thin pool volume and converts the existing logical volume lv2
in volume group vg001
to the metadata volume for that thin pool volume.
# lvconvert --thinpool vg001/lv1 --poolmetadata vg001/lv2
Converted vg001/lv1 to thin pool.
4.4.6. Creating Snapshot Volumes
Note
-s
argument of the lvcreate
command to create a snapshot volume. A snapshot volume is writable.
Note
Note
/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
lvdisplay
command yields output that includes a list of all snapshot logical volumes and their status (active or inactive).
/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
lvs
command, by default, displays the origin volume and the current percentage of the snapshot volume being used. 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
Warning
lvs
command to be sure it does not fill. A snapshot that is 100% full is lost completely, as a write to unchanged parts of the origin would be unable to succeed without corrupting the snapshot.
snapshot_autoextend_threshold
option in the lvm.conf
file. This option allows automatic extension of a snapshot whenever the remaining snapshot space drops below the threshold you set. This feature requires that there be unallocated space in the volume group.
snapshot_autoextend_threshold
and snapshot_autoextend_percent
is provided in the lvm.conf
file itself. For information about the lvm.conf
file, see Appendix B, The LVM Configuration Files.
4.4.7. Creating Thinly-Provisioned Snapshot Volumes
Note
lvmthin
(7) man page.
Important
lvcreate -s vg/thinvolume -L10M
will not create a thin snapshot, even though the origin volume is a thin volume.
--name
option of the lvcreate
command. The following command creates a thinly-provisioned snapshot volume of the thinly-provisioned logical volume vg001/thinvolume
that is named mysnapshot1
.
#lvcreate -s --name mysnapshot1 vg001/thinvolume
Logical volume "mysnapshot1" created #lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert mysnapshot1 vg001 Vwi-a-tz 1.00g mythinpool thinvolume 0.00 mythinpool vg001 twi-a-tz 100.00m 0.00 thinvolume vg001 Vwi-a-tz 1.00g mythinpool 0.00
--thinpool
option. The following command creates a thin snapshot volume of the read-only inactive volume origin_volume
. The thin snapshot volume is named mythinsnap
. The logical volume origin_volume
then becomes the thin external origin for the thin snapshot volume mythinsnap
in volume group vg001
that will use the existing thin pool vg001/pool
. Because the origin volume must be in the same volume group as the snapshot volume, you do not need to specify the volume group when specifying the origin logical volume.
# lvcreate -s --thinpool vg001/pool origin_volume --name mythinsnap
# lvcreate -s vg001/mythinsnap --name my2ndthinsnap
lv_ancestors
and lv_descendants
reporting fields of the lvs
command.
stack1
is an origin volume in volume groupvg001
.stack2
is a snapshot ofstack1
stack3
is a snapshot ofstack2
stack4
is a snapshot ofstack3
stack5
is also a snapshot ofstack2
stack6
is a snapshot ofstack5
$ lvs -o name,lv_ancestors,lv_descendants vg001
LV Ancestors Descendants
stack1 stack2,stack3,stack4,stack5,stack6
stack2 stack1 stack3,stack4,stack5,stack6
stack3 stack2,stack1 stack4
stack4 stack3,stack2,stack1
stack5 stack2,stack1 stack6
stack6 stack5,stack2,stack1
pool
Note
lv_ancestors
and lv_descendants
fields display existing dependencies but do not track removed entries which can break a dependency chain if the entry was removed from the middle of the chain. For example, if you remove the logical volume stack3
from this sample configuration, the display is as follows.
$ lvs -o name,lv_ancestors,lv_descendants vg001
LV Ancestors Descendants
stack1 stack2,stack5,stack6
stack2 stack1 stack5,stack6
stack4
stack5 stack2,stack1 stack6
stack6 stack5,stack2,stack1
pool
lv_ancestors_full
and lv_descendants_full
fields. For information on tracking, displaying, and removing historical logical volumes, see Section 4.4.21, “Tracking and Displaying Historical Logical Volumes (Red Hat Enterprise Linux 7.3 and Later)”.
4.4.8. Creating LVM Cache Logical Volumes
- Origin logical volume — the large, slow logical volume
- Cache pool logical volume — the small, fast logical volume, which is composed of two devices: the cache data logical volume, and the cache metadata logical volume
- Cache data logical volume — the logical volume containing the data blocks for the cache pool logical volume
- Cache metadata logical volume — the logical volume containing the metadata for the cache pool logical volume, which holds the accounting information that specifies where data blocks are stored (for example, on the origin logical volume or the cache data logical volume).
- Cache logical volume — the logical volume containing the origin logical volume and the cache pool logical volume. This is the resultant usable device which encapsulates the various cache volume components.
- Create a volume group that contains a slow physical volume and a fast physical volume. In this example.
/dev/sde1
is a slow device and/dev/sdf1
is a fast device and both devices are contained in volume groupVG
.#
pvcreate /dev/sde1
#pvcreate /dev/sdf1
#vgcreate VG /dev/sde1 /dev/sdf1
- Create the origin volume. This example creates an origin volume named
lv
that is ten gigabytes in size and that consists of/dev/sde1
, the slow physical volume.#
lvcreate -L 10G -n lv VG /dev/sde1
- Create the cache pool logical volume. This example creates the cache pool logical volume named
cpool
on the fast device/dev/sdf1
, which is part of the volume groupVG
. The cache pool logical volume this command creates consists of the hidden cache data logical volumecpool_cdata
and the hidden cache metadata logical volumecpool_cmeta
.#
lvcreate --type cache-pool -L 5G -n cpool VG /dev/sdf1
Using default stripesize 64.00 KiB. Logical volume "cpool" created. #lvs -a -o name,size,attr,devices VG
LV LSize Attr Devices [cpool] 5.00g Cwi---C--- cpool_cdata(0) [cpool_cdata] 5.00g Cwi-ao---- /dev/sdf1(4) [cpool_cmeta] 8.00m ewi-ao---- /dev/sdf1(2)For more complicated configurations you may need to create the cache data and the cache metadata logical volumes individually and then combine the volumes into a cache pool logical volume. For information on this procedure, see thelvmcache
(7) man page. - Create the cache logical volume by linking the cache pool logical volume to the origin logical volume. The resulting user-accessible cache logical volume takes the name of the origin logical volume. The origin logical volume becomes a hidden logical volume with
_corig
appended to the original name. Note that this conversion can be done live, although you must ensure you have performed a backup first.#
lvconvert --type cache --cachepool cpool VG/lv
Logical volume cpool is now cached. #lvs -a -o name,size,attr,devices vg
LV LSize Attr Devices [cpool] 5.00g Cwi---C--- cpool_cdata(0) [cpool_cdata] 5.00g Cwi-ao---- /dev/sdf1(4) [cpool_cmeta] 8.00m ewi-ao---- /dev/sdf1(2) lv 10.00g Cwi-a-C--- lv_corig(0) [lv_corig] 10.00g owi-aoC--- /dev/sde1(0) [lvol0_pmspare] 8.00m ewi------- /dev/sdf1(0) - Optionally, as of Red Hat Enterprise Linux release 7.2, you can convert the cached logical volume to a thin pool logical volume. Note that any thin logical volumes created from the pool will share the cache.The following command uses the fast device,
/dev/sdf1
, for allocating the thin pool metadata (lv_tmeta
). This is the same device that is used by the cache pool volume, which means that the thin pool metadata volume shares that device with both the cache data logical volumecpool_cdata
and the cache metadata logical volumecpool_cmeta
.#
lvconvert --type thin-pool VG/lv /dev/sdf1
WARNING: Converting logical volume VG/lv to thin pool's data volume with metadata wiping. THIS WILL DESTROY CONTENT OF LOGICAL VOLUME (filesystem etc.) Do you really want to convert VG/lv? [y/n]:y
Converted VG/lv to thin pool. #lvs -a -o name,size,attr,devices vg
LV LSize Attr Devices [cpool] 5.00g Cwi---C--- cpool_cdata(0) [cpool_cdata] 5.00g Cwi-ao---- /dev/sdf1(4) [cpool_cmeta] 8.00m ewi-ao---- /dev/sdf1(2) lv 10.00g twi-a-tz-- lv_tdata(0) [lv_tdata] 10.00g Cwi-aoC--- lv_tdata_corig(0) [lv_tdata_corig] 10.00g owi-aoC--- /dev/sde1(0) [lv_tmeta] 12.00m ewi-ao---- /dev/sdf1(1284) [lvol0_pmspare] 12.00m ewi------- /dev/sdf1(0) [lvol0_pmspare] 12.00m ewi------- /dev/sdf1(1287)
lvmcache
(7) man page.
4.4.9. Merging Snapshot Volumes
--merge
option of the lvconvert
command to merge a snapshot into its origin volume. If both the origin and snapshot volume are not open, the merge will start immediately. Otherwise, the merge will start the first time either the origin or snapshot are activated and both are closed. Merging a snapshot into an origin that cannot be closed, for example a root file system, is deferred until the next time the origin volume is activated. When merging starts, the resulting logical volume will have the origin’s name, minor number and UUID. While the merge is in progress, reads or writes to the origin appear as they were directed to the snapshot being merged. When the merge finishes, the merged snapshot is removed.
vg00/lvol1_snap
into its origin.
# lvconvert --merge vg00/lvol1_snap
vg00/lvol1
, vg00/lvol2
, and vg00/lvol3
are all tagged with the tag @some_tag
. The following command merges the snapshot logical volumes for all three volumes serially: vg00/lvol1
, then vg00/lvol2
, then vg00/lvol3
. If the --background
option were used, all snapshot logical volume merges would start in parallel.
# lvconvert --merge @some_tag
lvconvert --merge
command, see the lvconvert
(8) man page.
4.4.10. Persistent Device Numbers
lvcreate
and the lvchange
commands by using the following arguments:
--persistent y --major major --minor minor
fsid
parameter in the exports file may avoid the need to set a persistent device number within LVM.
4.4.11. Changing the Parameters of a Logical Volume Group
lvchange
command. For a listing of the parameters you can change, see the lvchange
(8) man page.
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, as described in Section 4.3.9, “Changing the Parameters of a Volume Group”.
lvol1
in volume group vg00
to be read-only.
# lvchange -pr vg00/lvol1
4.4.12. Renaming Logical Volumes
lvrename
command.
lvold
in volume group vg02
to lvnew
.
# lvrename /dev/vg02/lvold /dev/vg02/lvnew
# lvrename vg02 lvold lvnew
4.4.13. Removing Logical Volumes
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.
/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
lvchange -an
command, in which case you would not see the prompt verifying whether you want to remove an active logical volume.
4.4.14. Displaying Logical Volumes
lvs
, lvdisplay
, and lvscan
.
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. For information on using the lvs
command to customize your output, see Section 4.8, “Customized Reporting for LVM”.
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.
# lvdisplay -v /dev/vg00/lvol2
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
4.4.15. Growing Logical Volumes
lvextend
command.
/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
/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
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
4.4.16. Shrinking Logical Volumes
lvreduce
command.
Note
--resizefs
option of the lvreduce
command when the logical volume contains a file system. When you use this option, the lvreduce
command attempts to reduce the file system before shrinking the logical volume. If shrinking the file system fails, as can occur if the file system is full or the file system does not support shrinking, then the lvreduce
command will fail and not attempt to shrink the logical volume.
Warning
lvreduce
command warns about possible data loss and asks for a confirmation. However, you should not rely on these confirmation prompts to prevent data loss because in some cases you will not see these prompts, such as when the logical volume is inactive or the --resizefs
option is not used.
--test
option of the lvreduce
command does not indicate where the operation is safe, as this option does not check the file system or test the file system resize.
lvol1
in volume group vg00
to be 64 megabytes. In this example, lvol1
contains a file system, which this command resizes together with the logical volume. This example shows the output to the command.
# lvreduce --resizefs -L 64M vg00/lvol1
fsck from util-linux 2.23.2
/dev/mapper/vg00-lvol1: clean, 11/25688 files, 8896/102400 blocks
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vg00-lvol1 to 65536 (1k) blocks.
The filesystem on /dev/mapper/vg00-lvol1 is now 65536 blocks long.
Size of logical volume vg00/lvol1 changed from 100.00 MiB (25 extents) to 64.00 MiB (16 extents).
Logical volume vg00/lvol1 successfully resized.
# lvreduce --resizefs -L -64M vg00/lvol1
4.4.17. Extending a Striped Volume
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
#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)
# vgs
VG #PV #LV #SN Attr VSize VFree
vg 2 1 0 wz--n- 271.31G 0
#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
# 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
#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
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
4.4.18. Extending a RAID Volume
lvextend
command without performing a synchronization of the new RAID regions.
--nosync
option when you create a RAID logical volume with the lvcreate
command, the RAID regions are not synchronized when the logical volume is created. If you later extend a RAID logical volume that you have created with the --nosync
option, the RAID extensions are not synchronized at that time, either.
--nosync
option by using the lvs
command to display the volume's attributes. A logical volume will show "R" as the first character in the attribute field if it is a RAID volume that was created without an initial synchronization, and it will show "r" if it was created with initial synchronization.
lv
that was created without initial synchronization, showing "R" as the first character in the attribute field. The seventh character in the attribute field is "r", indicating a target type of RAID. For information on the meaning of the attribute field, see Table 4.5, “lvs Display Fields”.
# lvs vg
LV VG Attr LSize Pool Origin Snap% Move Log Cpy%Sync Convert
lv vg Rwi-a-r- 5.00g 100.00
lvextend
command, the RAID extension will not be resynchronized.
--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.
--nosync
option, indicated that the RAID volume was synchronized when it was created. This example, however, specifies that the volume not be synchronized when the volume is extended. Note that the volume has an attribute of "r", but after executing the lvextend
command with the --nosync
option the volume has an attribute of "R".
#lvs vg
LV VG Attr LSize Pool Origin Snap% Move Log Cpy%Sync Convert lv vg rwi-a-r- 20.00m 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 Cpy%Sync Convert lv vg Rwi-a-r- 5.02g 100.00
--nosync
option specified. Instead, you will be prompted whether to do a full resync of the extended portion of the logical volume.
Note
--nosync
option specified. If you did not specify the --nosync
option, however, you can extend the RAID volume while it is recovering.
4.4.19. Extending a Logical Volume with the cling
Allocation Policy
--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.
@site1
and @site2
tags. You can then specify the following line in the lvm.conf
file:
cling_tag_list = [ "@site1", "@site2" ]
lvm.conf
file has been modified to contain the following line:
cling_tag_list = [ "@A", "@B" ]
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]
PV VG Fmt Attr PSize PFree PV Tags
/dev/sdb1 taft lvm2 a-- 15.00g 15.00g A
/dev/sdc1 taft lvm2 a-- 15.00g 15.00g B
/dev/sdd1 taft lvm2 a-- 15.00g 15.00g B
/dev/sde1 taft lvm2 a-- 15.00g 15.00g C
/dev/sdf1 taft lvm2 a-- 15.00g 15.00g C
/dev/sdg1 taft lvm2 a-- 15.00g 15.00g A
/dev/sdh1 taft lvm2 a-- 15.00g 15.00g A
taft
.
# lvcreate --type raid1 -m 1 -n mirror --nosync -L 10G taft
WARNING: New raid1 won't be synchronised. Don't read what you didn't write!
Logical volume "mirror" created
# lvs -a -o +devices
LV VG Attr LSize Log Cpy%Sync Devices
mirror taft Rwi-a-r--- 10.00g 100.00 mirror_rimage_0(0),mirror_rimage_1(0)
[mirror_rimage_0] taft iwi-aor--- 10.00g /dev/sdb1(1)
[mirror_rimage_1] taft iwi-aor--- 10.00g /dev/sdc1(1)
[mirror_rmeta_0] taft ewi-aor--- 4.00m /dev/sdb1(0)
[mirror_rmeta_1] taft ewi-aor--- 4.00m /dev/sdc1(0)
cling
allocation policy to indicate that the mirror legs should be extended using physical volumes with the same tag.
# lvextend --alloc cling -L +10G taft/mirror
Extending 2 mirror images.
Extending logical volume mirror to 20.00 GiB
Logical volume mirror successfully resized
C
were ignored.
# lvs -a -o +devices
LV VG Attr LSize Log Cpy%Sync Devices
mirror taft Rwi-a-r--- 20.00g 100.00 mirror_rimage_0(0),mirror_rimage_1(0)
[mirror_rimage_0] taft iwi-aor--- 20.00g /dev/sdb1(1)
[mirror_rimage_0] taft iwi-aor--- 20.00g /dev/sdg1(0)
[mirror_rimage_1] taft iwi-aor--- 20.00g /dev/sdc1(1)
[mirror_rimage_1] taft iwi-aor--- 20.00g /dev/sdd1(0)
[mirror_rmeta_0] taft ewi-aor--- 4.00m /dev/sdb1(0)
[mirror_rmeta_1] taft ewi-aor--- 4.00m /dev/sdc1(0)
4.4.20. Controlling Logical Volume Activation
-k
or --setactivationskip {y|n}
option of the lvcreate
or lvchange
command. This flag is not applied during deactivation.
lvs
command, which displays the k
attribute as in the following example.
# lvs vg/thin1s1
LV VG Attr LSize Pool Origin
thin1s1 vg Vwi---tz-k 1.00t pool0 thin1
k
attribute set by using the -K
or --ignoreactivationskip
option in addition to the standard -ay
or --activate y
option.
# lvchange -ay -K VG/SnapLV
-kn
or --setactivationskip n
option of the lvcreate
command. You can turn the flag off for an existing logical volume by specifying the -kn
or --setactivationskip n
option of the lvchange
command. You can turn the flag on again with the -ky
or --setactivationskip y
option.
# lvcreate --type thin -n SnapLV -kn -s ThinLV --thinpool VG/ThinPoolLV
# lvchange -kn VG/SnapLV
auto_set_activation_skip
setting in the /etc/lvm/lvm.conf
file.
4.4.21. Tracking and Displaying Historical Logical Volumes (Red Hat Enterprise Linux 7.3 and Later)
record_lvs_history
metadata option in the lvm.conf
configuration file. This allows you to display a full thin snapshot dependency chain that includes logical volumes that have been removed from the original dependency chain and have become historical logical volumes.
lvs_history_retention_time
metadata option in the lvm.conf
configuration file.
lv_time_removed
: the removal time of the logical volumelv_time
: the creation time of the logical volumelv_name
: the name of the logical volumelv_uuid
: the UUID of the logical volumevg_name
: the volume group that contains the logical volume.
lvol1
, the name of the historical volume is -lvol1
. A historical logical volume cannot be reactivated.
record_lvs_history
metadata option enabled, you can prevent the retention of historical logical volumes on an individual basis when you remove a logical volume by specifying the --nohistory
option of the lvremove
command.
-H|--history
option of an LVM display command. You can display a full thin snapshot dependency chain that includes historical volumes by specifying the lv_full_ancestors
and lv_full_descendants
reporting fields along with the -H
option.
- Ensure that historical logical volumes are retained by setting
record_lvs_history=1
in thelvm.conf
file. This metadata option is not enabled by default. - Enter the following command to display a thin provisioned snapshot chain.In this example:
lvol1
is an origin volume, the first volume in the chain.lvol2
is a snapshot oflvol1
.lvol3
is a snapshot oflvol2
.lvol4
is a snapshot oflvol3
.lvol5
is also a snapshot oflvol3
.
Note that even though the examplelvs
display command includes the-H
option, no thin snapshot volume has yet been removed and there are no historical logical volumes to display.#
lvs -H -o name,full_ancestors,full_descendants
LV FAncestors FDescendants lvol1 lvol2,lvol3,lvol4,lvol5 lvol2 lvol1 lvol3,lvol4,lvol5 lvol3 lvol2,lvol1 lvol4,lvol5 lvol4 lvol3,lvol2,lvol1 lvol5 lvol3,lvol2,lvol1 pool - Remove logical volume
lvol3
from the snapshot chain, then run the followinglvs
command again to see how historical logical volumes are displayed, along with their ancestors and descendants.#
lvremove -f vg/lvol3
Logical volume "lvol3" successfully removed #lvs -H -o name,full_ancestors,full_descendants
LV FAncestors FDescendants lvol1 lvol2,-lvol3,lvol4,lvol5 lvol2 lvol1 -lvol3,lvol4,lvol5 -lvol3 lvol2,lvol1 lvol4,lvol5 lvol4 -lvol3,lvol2,lvol1 lvol5 -lvol3,lvol2,lvol1 pool - You can use the
lv_time_removed
reporting field to display the time a historical volume was removed.#
lvs -H -o name,full_ancestors,full_descendants,time_removed
LV FAncestors FDescendants RTime lvol1 lvol2,-lvol3,lvol4,lvol5 lvol2 lvol1 -lvol3,lvol4,lvol5 -lvol3 lvol2,lvol1 lvol4,lvol5 2016-03-14 14:14:32 +0100 lvol4 -lvol3,lvol2,lvol1 lvol5 -lvol3,lvol2,lvol1 pool - You can reference historical logical volumes individually in a display command by specifying the vgname/lvname format, as in the following example. Note that the fifth bit in the
lv_attr
field is set toh
to indicate the volume is a historical volume.#
lvs -H vg/-lvol3
LV VG Attr LSize -lvol3 vg ----h----- 0 - LVM does not keep historical logical volumes if the volume has no live descendant. This means that if you remove a logical volume at the end of a snapshot chain, the logical volume is not retained as a historical logical volume.
#
lvremove -f vg/lvol5
Automatically removing historical logical volume vg/-lvol5. Logical volume "lvol5" successfully removed #lvs -H -o name,full_ancestors,full_descendants
LV FAncestors FDescendants lvol1 lvol2,-lvol3,lvol4 lvol2 lvol1 -lvol3,lvol4 -lvol3 lvol2,lvol1 lvol4 lvol4 -lvol3,lvol2,lvol1 pool - Run the following commands to remove the volume
lvol1
andlvol2
and to see how thelvs
command displays the volumes once they have been removed.#
lvremove -f vg/lvol1 vg/lvol2
Logical volume "lvol1" successfully removed Logical volume "lvol2" successfully removed #lvs -H -o name,full_ancestors,full_descendants
LV FAncestors FDescendants -lvol1 -lvol2,-lvol3,lvol4 -lvol2 -lvol1 -lvol3,lvol4 -lvol3 -lvol2,-lvol1 lvol4 lvol4 -lvol3,-lvol2,-lvol1 pool - To remove a historical logical volume completely, you can run the
lvremove
command again, specifying the name of the historical volume that now includes the hyphen, as in the following example.#
lvremove -f vg/-lvol3
Historical logical volume "lvol3" successfully removed #lvs -H -o name,full_ancestors,full_descendants
LV FAncestors FDescendants -lvol1 -lvol2,lvol4 -lvol2 -lvol1 lvol4 lvol4 -lvol2,-lvol1 pool - A historical logical volumes is retained as long as there is a chain that includes live volumes in its descendants. This means that removing a historical logical volume also removes all of the logical volumes in the chain if no existing descendant is linked to them, as shown in the following example.
#
lvremove -f vg/lvol4
Automatically removing historical logical volume vg/-lvol1. Automatically removing historical logical volume vg/-lvol2. Automatically removing historical logical volume vg/-lvol4. Logical volume "lvol4" successfully removed