|
LVM Mirroring Overview
Continuing with our LVM how to series, in this KB, we will build on the knowledge from our LVM Configuration KB, and explore two sided logical volume (LV) mirroring. In this KB, we will guide you through the creation of a two sided mirror from a new LV and the steps necessary to add mirroring to an existing LV.
Note: Mirroring is usually thought of as two way (in which two physical copies of the volume exist.) However, when creating LVM mirrors, you can define as many mirrors of a LV as you wish limited only by the number of physical volumes (PVs) available in the Volume Group (VG). Each side of the mirror requires one or more PVs.
LVM mirroring is most commonly used for data protection and high availability of mission critical data. Similar to RAID 1, LVM mirroring ensures fault tolerance without any associated downtime should either leg of the mirror experience a hardware failure. In the event of a failure, LVM converts the mirrored volume into a linear volume and continues to operate as before, but without the mirrored redundancy.
LVM mirroring at a minimum requires three physical volumes:
- A volume for one side of the mirror
- A volume for other side of the mirror
- A volume for the log
Note: We recommend for recoverability purposes that the PV's be three separate physical disks. Although not recommended, the PV's could also be a combination of partitions from one more physical disks but understand that a hardware failure could render the data on the LVM mirror useless - which somewhat defeats the purpose of LVM mirroring.
Creating New Mirror Volumes
For our first example, we will show you how to create a new mirrored logical volume (LV) from free space on our volume group (VG). We are going to create a new 3GB mirrored LV called DumpMirror on the volume group TCPDumpVolGRP Let's begin:
- Let's first check our TCPDumpVolGRP volume group to see if it has enough free space to support a 3GB mirrored LV
| [root@Linux01 ~]# vgs |
| VG |
#PV |
#LV |
#SN |
Attr |
VSize |
VFree |
| TCPDumpVolGRP |
3 |
1 |
0 |
wz--n- |
11.91G |
9.91G |
| VolGroup00 |
1 |
5 |
0 |
wz--n- |
9.88G |
0 |
| [root@Linux01 ~]# |
|
Note: Since our 3GB mirrored LV will require ~6GB (3GB x 2 legs = 6GB + Log Volume), the 9.91GB free should suffice.
- Let's also check to ensure the TCPDumpVolGRP volume group has enough free physical volumes (PV) available
| [root@Linux01 ~]# pvs |
| PV |
VG |
Fmt |
Attr |
PSize |
PFree |
/dev/sda2
|
VolGroup00 |
lvm2 |
a- |
9.88G
|
0 |
| /dev/sdb1 |
TCPDumpVolGRP |
lvm2 |
a- |
3.97G
|
3.97G |
/dev/sdc1
|
TCPDumpVolGRP |
lvm2 |
a- |
3.97G |
1.97G |
/dev/sdd1
|
TCPDumpVolGRP |
lvm2 |
a- |
3.97G |
3.97G |
| [root@Linux01 ~]# |
|
Note: Two sided mirrors require three physical volumes which we appear to have with free space available on them
- We will now create the mirrored LV. Creating a mirrored LV is much the same as the creation of a non-mirrored LV with the exception of the '-m 1' command line switch. The '-m 1' tells LVM you wish to create a two sided mirror
| [root@Linux01 ~]# lvcreate -L 3G -n DumpMirror -m 1 TCPDumpVolGRP |
Logical volume "DumpMirror" created
|
| [root@Linux01 ~]# |
|
- Creating the mirrored LV can take sometime. Monitor the sync process until it reaches 100%
| [root@Linux01 ~]# lvs |
| LV |
VG |
Attr |
LSize |
Origin |
Snap% |
Move |
Log |
Copy% |
Convert |
| 4GLV |
TCPDumpVolGRP |
-wi-ao |
2.00G |
|
|
|
|
|
|
| DumpMirror |
TCPDumpVolGRP |
mwi-ao |
3.00G |
|
|
|
DumpMirror_mlog |
5.21 |
|
| LogVol00 |
VolGroup00 |
-wi-ao |
1.00G |
|
|
|
|
|
|
| LogVol01 |
VolGroup00 |
-wi-ao |
1.94G |
|
|
|
|
|
|
| LogVol02 |
VolGroup00 |
-wi-ao |
1.00G |
|
|
|
|
|
|
| LogVol03 |
VolGroup00 |
-wi-ao |
2.00G |
|
|
|
|
|
|
| LogVol04 |
VolGroup00 |
-wi-ao |
3.94G |
|
|
|
|
|
|
| [root@Linux01 ~]# |
|
Note: The sync process is only ~5% complete, this could take a while
| [root@Linux01 ~]# lvs |
| LV |
VG |
Attr |
LSize |
Origin |
Snap% |
Move |
Log |
Copy% |
Convert |
| 4GLV |
TCPDumpVolGRP |
-wi-ao |
2.00G |
|
|
|
|
|
|
| DumpMirror |
TCPDumpVolGRP |
mwi-ao |
3.00G |
|
|
|
DumpMirror_mlog |
100.00 |
|
| LogVol00 |
VolGroup00 |
-wi-ao |
1.00G |
|
|
|
|
|
|
| LogVol01 |
VolGroup00 |
-wi-ao |
1.94G |
|
|
|
|
|
|
| LogVol02 |
VolGroup00 |
-wi-ao |
1.00G |
|
|
|
|
|
|
| LogVol03 |
VolGroup00 |
-wi-ao |
2.00G |
|
|
|
|
|
|
| LogVol04 |
VolGroup00 |
-wi-ao |
3.94G |
|
|
|
|
|
|
| [root@Linux01 ~]# |
|
Note: The LV is now synced and ready for use
- Inspect the LV to confirm the devices that are in use by the mirror
[root@Linux01 ~]# lvs -a -o +devices
|
| LV |
VG |
Attr |
LSize |
Log |
Copy% |
Devices |
| 4GLV |
TCPDumpVolGRP |
-wi-ao |
2.00G |
|
|
/dev/sdc1(0) |
| DumpMirror |
TCPDumpVolGRP |
mwi-a- |
3.00G |
DumpMirror_mlog |
100.00 |
DumpMirror_mimage_0(0), DumpMirror_mimage_1(0) |
| [DumpMirror_mimage_0] |
TCPDumpVolGRP |
iwi-ao |
3.00G |
|
|
/dev/sdb1(0) |
| [DumpMirror_mimage_1] |
TCPDumpVolGRP |
iwi-ao |
3.00G |
|
|
/dev/sdd1(0) |
| [DumpMirror_mlog] |
TCPDumpVolGRP |
lwi-ao |
32.00M |
|
|
/dev/sdc1(64) |
| LogVol00 |
VolGroup00 |
-wi-ao |
1.00G |
|
|
/dev/sda2(126) |
| LogVol01 |
VolGroup00 |
-wi-ao |
1.94G |
|
|
/dev/sda2(254) |
| LogVol02 |
VolGroup00 |
-wi-ao |
1.00G |
|
|
/dev/sda2(158) |
| LogVol03 |
VolGroup00 |
-wi-ao |
2.00G |
|
|
/dev/sda2(190) |
| LogVol04 |
VolGroup00 |
-wi-ao |
3.94G |
|
|
/dev/sda2(0) |
| [root@Linux01 ~]# |
|
Note: Some columns were removed from the above output. You will notice DumpMirror uses /dev/sdb1 and /dev/sdd1. You will also notice the logs for DumpMirror are held on /dev/sdc1
- Format DumpMirror
[root@Linux01 ~]# mke2fs -j /dev/TCPDumpVolGRP/DumpMirror mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 393216 inodes, 786432 blocks 39321 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=805306368 24 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 21 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@Linux01 ~]#
|
- Mount DumpMirror on the mount point of /mirror
[root@Linux01 ~]# mkdir /mirror [root@Linux01 ~]# mount /dev/TCPDumpVolGRP/DumpMirror /mirror
|
- Add DumpMirror to the /etc/fstab file
| /dev/TCPDumpVolGRP/DumpMirror |
/mirror
|
ext3 |
defaults |
0 |
0 |
|
Nice work. You know have a fault tolerant logical volume! We are now going to continue with the KB and show you how to add mirroring to an existing logical volume.
Mirror From Existing Volume
We are now going to look at how to create a mirror from an existing logical volume (LV.) For this portion of the KB, we will assume you have an LV in use on your system and would like it mirrored.
Note: If you do not have any LV's on your system and need help creating your first LV, see our LVM Configuration KB.
In the following example, we will convert the logical volume DataLV from a linear to mirrored LV. Lets begin!
- Review the output of pvs, vgs and lvs so we know the layout of DataLV and confirm the requirements for the mirror
[root@Linux01 ~]# lvs -a -o +devices
|
| LV |
VG |
Attr |
LSize |
Origin |
Snap% |
Move |
Log |
Copy% |
Convert |
Devices |
| DataLV |
TCPDumpVolGRP |
-wi-ao |
2.5G |
|
|
|
|
|
|
/dev/sdb1(0) |
| LogVol00 |
VolGroup00 |
-wi-ao |
1.00G |
|
|
|
|
|
|
/dev/sda2(126) |
| LogVol01 |
VolGroup00 |
-wi-ao |
1.94G |
|
|
|
|
|
|
/dev/sda2(254) |
| LogVol02 |
VolGroup00 |
-wi-ao |
1.00G |
|
|
|
|
|
|
/dev/sda2(158) |
| LogVol03 |
VolGroup00 |
-wi-ao |
2.00G |
|
|
|
|
|
|
/dev/sda2(190) |
| LogVol04 |
VolGroup00 |
-wi-ao |
3.94G |
|
|
|
|
|
|
/dev/sda2(0) |
| [root@Linux01 ~]# |
|
Note: You will notice that DataLV is 2.5GB in size and resides on /dev/sdb1.
| [root@Linux01 ~]# pvs |
| PV |
VG |
Fmt |
Attr |
PSize |
PFree |
/dev/sda2
|
VolGroup00 |
lvm2 |
a- |
9.88G
|
0 |
| /dev/sdb1 |
TCPDumpVolGRP |
lvm2 |
a- |
3.97G
|
1.47G |
/dev/sdc1
|
TCPDumpVolGRP |
lvm2 |
a- |
3.97G |
3.97G |
/dev/sdd1
|
TCPDumpVolGRP |
lvm2 |
a- |
3.97G |
3.97G |
| [root@Linux01 ~]# |
|
Note: pvs confirms our assumptions showing that some of sdb1 is consumed by DataLV. We are also able to confirm we have the three required PV's necessary for the mirror.
| [root@Linux01 ~]# vgs |
| VG |
#PV |
#LV |
#SN |
Attr |
VSize |
VFree |
| TCPDumpVolGRP |
3 |
1 |
0 |
wz--n- |
11.91G |
9.41G |
| VolGroup00 |
1 |
5 |
0 |
wz--n- |
9.88G |
0 |
| [root@Linux01 ~]# |
|
Note: A free space check on our volume group shows we have enough free space for the 2.5GB mirror required for DataLV
- Convert the logical volume to a mirror
[root@Linux01 Data]# lvconvert -m1 TCPDumpVolGRP/DataLV TCPDumpVolGRP/DataLV: Converted: 12.5% TCPDumpVolGRP/DataLV: Converted: 26.2% TCPDumpVolGRP/DataLV: Converted: 40.0% TCPDumpVolGRP/DataLV: Converted: 53.8% TCPDumpVolGRP/DataLV: Converted: 68.8% TCPDumpVolGRP/DataLV: Converted: 82.5% TCPDumpVolGRP/DataLV: Converted: 96.2% TCPDumpVolGRP/DataLV: Converted: 100.0% Logical volume DataLV converted. [root@Linux01 Data]#
|
Note: The lvconvert command can take a considerable amount of time depending on how big a mirror is to be created. Go grab a beer or read some more articles on TCPDump while you wait, but do not break out of the process.
- Confirm the mirror has been created
[root@Linux01 ~]# lvs -a -o +devices
|
| LV |
VG |
Attr |
LSize |
Log |
Copy% |
Devices |
| DataLV |
TCPDumpVolGRP |
mwi-a- |
2.50G |
DataLV_mlog |
100.00 |
DataLV_mimage_0(0), DataLV_mimage_1(0) |
| [DataLV_mimage_0] |
TCPDumpVolGRP |
iwi-ao |
2.50G |
|
|
/dev/sdb1(0) |
| [DataLV_mimage_1] |
TCPDumpVolGRP |
iwi-ao |
2.50G |
|
|
/dev/sdc1(0) |
| [DataLV_mlog] |
TCPDumpVolGRP |
lwi-ao |
32.00M |
|
|
/dev/sdd1(0) |
| LogVol00 |
VolGroup00 |
-wi-ao |
1.00G |
|
|
/dev/sda2(126) |
| LogVol01 |
VolGroup00 |
-wi-ao |
1.94G |
|
|
/dev/sda2(254) |
| LogVol02 |
VolGroup00 |
-wi-ao |
1.00G |
|
|
/dev/sda2(158) |
| LogVol03 |
VolGroup00 |
-wi-ao |
2.00G |
|
|
/dev/sda2(190) |
| LogVol04 |
VolGroup00 |
-wi-ao |
3.94G |
|
|
/dev/sda2(0) |
| [root@Linux01 ~]# |
|
Note: Some columns were removed from the above output. You will notice DataLV uses /dev/sdb1 and /dev/sdc1. You will also notice the mirror logs for DumpMirror are held on /dev/sdd1
Note: For additional details on the Attr column (LVM display attributes) of the lvs, vgs, and pvs commands, please see our LVM Attributes KB.
Nice work, your logical volume is now fault tolerant!
Add this page to your favorite website
|