此内容没有您所选择的语言版本。
5.4.3. Creating Mirrored Volumes
Note
As of the Red Hat Enterprise Linux 6.3 release, LVM supports RAID4/5/6 and a new implementation of mirroring. For information on this new implementation, see Section 5.4.16, “RAID Logical Volumes”.
Note
Creating a mirrored LVM logical volume in a cluster requires the same commands and procedures as creating a mirrored LVM logical volume 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 6.5, “Creating a Mirrored LVM Logical Volume in a Cluster”.
Attempting to run multiple LVM mirror creation and conversion commands in quick succession from multiple nodes in a cluster might cause a backlog of these commands. This might cause some of the requested operations to time-out and, subsequently, fail. To avoid this issue, it is recommended that cluster mirror creation commands be executed from one node of the cluster.
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.
Note
Due to limitations in the cluster infrastructure, cluster mirrors greater than 1.5TB cannot be created with the default region size of 512KB. Users that require larger mirrors should increase the region size from its default to something larger. Failure to increase the region size will cause LVM creation to hang and may hang other LVM commands as well.
As a general guideline for specifying the region size for mirrors that are larger than 1.5TB, you could take your mirror size in terabytes and round up that number to the next power of 2, using that number as the
-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
.
The following command creates a mirrored logical volume with a region size of 2MB:
# lvcreate -m1 -L 2T -R 2 -n mirror vol_group
When a mirror is created, the mirror regions are synchronized. For large mirror components, the sync process may take a long time. As of the Red Hat Enterprise Linux 6.3 release, 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 and ensures that the mirror does not need to be resynced every time a machine reboots or crashes. You can specify instead that this log be kept in memory with the
--mirrorlog core
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 volume is named ondiskmirvol
and has a single mirror. The volume is 12MB in size and keeps the mirror log in memory.
# lvcreate -L 12MB -m1 --mirrorlog core -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
Note
With clustered mirrors, the mirror log management is completely the responsibility of the cluster node with the currently lowest cluster ID. Therefore, when the device holding the cluster mirror log becomes unavailable on a subset of the cluster, the clustered mirror can continue operating without any impact, as long as the cluster node with lowest ID retains access to the mirror log. Since the mirror is undisturbed, no automatic corrective action (repair) is issued, either. When the lowest-ID cluster node loses access to the mirror log, however, automatic action will kick in (regardless of accessibility of the log from other nodes).
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 12MB 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.
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.
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 and a single log that is not mirrored. 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 1MB 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
Note
As of the Red Hat Enterprise Linux 6.1 release, you can combine striping and mirroring in a single logical volume. Creating a logical volume while simultaneously specifying the number of mirrors (
--mirrors X
) and the number of stripes (--stripes Y
) results in a mirror device whose constituent devices are striped.
5.4.3.1. Mirrored Logical Volume Failure Policy
You can define how a mirrored logical volume behaves in the event of a device failure with the
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 this parameter is 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.
By default, the
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 and the mirror will not remember its sync status across crashes and reboots and the entire mirror will be resynced.
By default, the
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
When an LVM mirror suffers a device failure, a two-stage recovery takes place. The first stage involves removing the failed devices. This can result in the mirror being reduced to a linear device. The second stage, if the
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.
For information on manually recovering from an LVM mirror failure, see Section 7.3, “Recovering from LVM Mirror Failure”.