Logical volume image implemented by LVM

Source: Internet
Author: User

Logical volume image implemented by LVM

System CentOS 6.5x64

The image function of LVM is similar to Raid1, that is, multiple disks synchronize with each other to ensure that data is not lost.

1. Add four physical hard disks and 2 GB space each here

2. Create a physical volume for sdb, sdc, sdd, and sde, and add sdb, sdc, and sdd to the vmTest

[Root @ node4 ~] # Pvcreate/dev/sdb
Physical volume "/dev/sdb" successfully created
[Root @ node4 ~] # Pvcreate/dev/sdc
Physical volume "/dev/sdc" successfully created
[Root @ node4 ~] # Pvcreate/dev/sdd
Physical volume "/dev/sdd" successfully created
[Root @ node4 ~] # Pvcreate/dev/sde
Physical volume "/dev/sde" successfully created

[Root @ node4 ~] # Vgcreate vgTest/dev/sdb/dev/sdc/dev/sdd
Volume group "vgTest" successfully created
[Root @ node4 ~] #

3. Create a logical volume

[Root @ node4 ~] # Lvcreate-L 1G-m1-n lvTest vgTest/dev/sdb/dev/sdc/dev/sdd
Logical volume "lvTest" created

View lvs Information

[Root @ node4 ~] # Lvs-a-o + devices
Lv vg Attr LSize Pool Origin Data % Move Log Cpy % Sync Convert Devices
Lv_root VolGroup-wi-ao ---- 8.54g/dev/sda2 (0)
Lv_swap VolGroup-wi-ao ---- 992.00 m/dev/sda2 (2186)
LvTest vgTest mwi-a-m --- 1.00g lvTest_mlog 100.00 lvTest_mimage_0 (0), lvTest_mimage_1 (0)
[LvTest_mimage_0] vgTest iwi-aom --- 1.00g/dev/sdb (0)
[LvTest_mimage_1] vgTest iwi-aom --- 1.00g/dev/sdc (0)
[LvTest_mlog] vgTest lwi-aom --- 4.00 m/dev/sdd (0)

The-m1 parameter is required for LVM images. As shown above, the/dev/sdb and/dev/sdc images are used for log storage.

4. format the partition and create a file on the logical volume. Destroys/dev/sdc.

[Root @ node4 ~] # Mkfs. ext4/dev/vgTest/lvTest
Mke2fs 1.41.12 (17-May-2010)
File System tag =
Operating System: Linux
Block size = 4096 (log = 2)
Part size = 4096 (log = 2)
Stride = 0 blocks, Stripe width = 0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block = 0
Maximum filesystem blocks = 268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768,983 04, 163840,229 376
 
Writing to inode table: complete
Creating journal (8192 blocks): Done
Writing superblocks and filesystem accounting information: complete
 
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.

[Root @ node4 ~] # Dd if =/dev/zero of =/dev/sdc count = 10 bs = 20 M
Read records of 10 + 0
Records 10 + 0 writes
209715200 bytes (210 MB) Copied, 2.08666 seconds, 101 MB/second
[Root @ node4 ~] # Lvs-a-o + devices
Couldn't find device with uuid zecO8D-2Suc-rnmK-a2Z7-6613-Zy1X-whVS0X.
Lv vg Attr LSize Pool Origin Data % Move Log Cpy % Sync Convert Devices
Lv_root VolGroup-wi-ao ---- 8.54g/dev/sda2 (0)
Lv_swap VolGroup-wi-ao ---- 992.00 m/dev/sda2 (2186)
LvTest vgTest mwi-a-m-p-1.00g lvTest_mlog 100.00 lvTest_mimage_0 (0), lvTest_mimage_1 (0)
[LvTest_mimage_0] vgTest iwi-aom --- 1.00g/dev/sdb (0)
[LvTest_mimage_1] vgTest iwi-aom-p-1.00g unknown device (0)
[LvTest_mlog] vgTest lwi-aom --- 4.00 m/dev/sdd (0)
[Root @ node4 ~] # Lvscan
Couldn't find device with uuid zecO8D-2Suc-rnmK-a2Z7-6613-Zy1X-whVS0X.
ACTIVE '/dev/vgTest/lvtest' [1.00 GiB] inherit
ACTIVE '/dev/VolGroup/lv_root' [8.54 GiB] inherit
ACTIVE '/dev/VolGroup/lv_swap' [992.00 MiB] inherit
[Root @ node4 ~] #

Remount the logical volume and check whether the file can be read normally.

1
2
3
4
5
6
7
8
9 [root @ node4 ~] # Mkdir/lvmTest
[Root @ node4 ~] # Mount/dev/vgTest/lvTest/lvmTest/
[Root @ node4 ~] # Cd/lvmTest/
[Root @ node4 lvmTest] # ls
Lost + found
[Root @ node4 lvmTest] # echo "ac"> ac
[Root @ node4 lvmTest] # cat ac
Ac
[Root @ node4 lvmTest] #

Remove the broken physical volume (/dev/sdc) from the volume group:

[Root @ node4 lvmTest] # vgdisplay
Couldn't find device with uuid zecO8D-2Suc-rnmK-a2Z7-6613-Zy1X-whVS0X.
--- Volume group ---
VG Name vgTest
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
Max lv 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 2
VG Size 5.99 GiB
PE Size 4.00 MiB
Total PE 1533
Alloc PE/Size 513/2 .00 GiB
Free PE/Size 1020/3 .98 GiB
Vg uuid 1qzO3A-Tjvi-by9l-Oq49-byz3-tIkx-rfSqex

[Root @ node4 lvmTest] # vgreduce -- removemissing -- force vgTest
Couldn't find device with uuid zecO8D-2Suc-rnmK-a2Z7-6613-Zy1X-whVS0X.
Wrote out consistent volume group vgTest
[Root @ node4 lvmTest] #

5. Add a new physical volume (/dev/sde) to the volume group ):

[Root @ node4 lvmTest] # vgextend vgTest/dev/sde
Volume group "vgTest" successfully extended
[Root @ node4 lvmTest] #

6. Data Recovery (logical volume mounting is not required during the process)

[Root @ node4 lvmTest] # lvconvert-m1/dev/vgTest/lvTest/dev/sdb/dev/sdd/dev/sde
VgTest/lvTest: Converted: 0.0%
VgTest/lvTest: Converted: 100.0%
[Root @ node4 lvmTest] # lvs-a-o + devices
Lv vg Attr LSize Pool Origin Data % Move Log Cpy % Sync Convert Devices
Lv_root VolGroup-wi-ao ---- 8.54g/dev/sda2 (0)
Lv_swap VolGroup-wi-ao ---- 992.00 m/dev/sda2 (2186)
LvTest vgTest mwi-aom --- 1.00g lvTest_mlog 100.00 lvTest_mimage_0 (0), lvTest_mimage_1 (0)
[LvTest_mimage_0] vgTest iwi-aom --- 1.00g/dev/sdb (0)
[LvTest_mimage_1] vgTest iwi-aom --- 1.00g/dev/sdd (0)
[LvTest_mlog] vgTest lwi-aom --- 4.00 m/dev/sde (0)

7. Verify the original data

[Root @ node4 lvmTest] # cat ac
Ac
[Root @ node4 lvmTest] # echo "abcde"> ac
[Root @ node4 lvmTest] # cat ac
Ac
Abcde
[Root @ node4 lvmTest] #

[Root @ node4 lvmTest] # lvdisplay
--- Logical volume ---
LV Path/dev/vgTest/lvTest
LV Name lvTest
VG Name vgTest
Lvuuid a8kDmI-R3ls-SfKJ-qx3d-1Tbb-wPAd-TJcQfn
LV Write Access read/write
LV Creation host, time node4.lansgg.com, 20:50:41 + 0800
LV Status available
# Open 1
LV Size 1.00 GiB
Current LE 256
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 5

  • Use LVM to create elastic disk storage-Part 1
  • Expanding/downgrading LVM in Linux (Part 2)
  • Recording and restoring logical volume snapshots in LVM (part 3)
  • Set a streamlined resource allocation volume in LVM (part 4)
  • Use fragmented I/O to manage multiple LVM disks (Part 5)

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.