Comprehensive Introduction and implementation of LVM

Source: Internet
Author: User

1. LVM: a mechanism for managing disk partitions in Linux. LVM is a logical layer built on hard disks and partitions to improve disk partition management flexibility.

Introduction to DM logical devices

1.1 volume Group Voume Group): A Group composed of multiple physical volumes. It is a combination and cannot be used directly. To use the combined space, you must create a logical volume; the VG size depends on the physical volume, and multiple logical volumes in the VG can be dynamically scaled)

1.2 logical volume: It can be all the available space of a volume group. It is a real dynamically scaled-down device with two boundaries: physical boundaries and logical boundaries; it can also be said that each logical volume is a file system or an independent partition. Creating a snapshot for a volume is actually creating a snapshot for a logical volume, that is, the snapshot volume is in the same volume group as its logical volume.

1.3 a snapshot can be understood as an access to another path of the same file size. The data stays at a certain time point in the past and is mainly used for data backup.

1.4 physical volume: It is a real disk. A volume group is created on a physical volume, and a logical volume is created on a volume group. The size of a logical volume can be larger than that of a physical volume.

2 command Introduction

2.1 volume group command

2.1.1 Vgcreate create vg) vgremove Delete vg) vg vgextended vg) vgreduce contract vg) vgs view vg information), vgdisplay view vg details), vgscan scan vg)

-S: Specifies the pe size. The default value is 4 M pvs. You can view the vg of a pv.

2.1.2 example: vgcreate myvg/dev/sda {#,#} create

Vgdisplay myvg: view only myvg

Vgcreate VG_name/path/to/pv

Vgremove myvg: delete myvg and delete a vg)

Vgreduce: to narrow down the vg, it means to remove the pv data)

Pvmove/dev/sda11 removed sda11

Vgreduce myvg/dev/sda11 removed from myvg/dev/sda11

Pvremove/dev/sda11 Erase/dev/sda11

Extension vg: vgextend myvg/dev/sda12 extension myvg volume group

2.13 lv command

Lvcreate-n lv_name name)-L # G specifies the space size) will automatically expand VG_name

Lvcreat-L 50 M-n testlv myvg create a size of 50 M name is testlv volume group is myvg

Lvs: View lv

Lvdisplay: displays all lv paths, such as dev/myvg/testlv)

3. logical volume expansion and reduction

3.1 expansion requirements

1) Check the file system before expansion.

2) logical boundaries are created close to physical boundaries.

3) expand physical boundaries first and expand logical boundaries

3.2 requirements for logical volume reduction

1) Online scale-down is not allowed. You need to uninstall it first.

2) ensure that the reduced space size can still store all the original data

3) files should be forcibly checked before reduction to ensure consistency of the file system

3.3 snapshot volume

1) The lifecycle is the entire data duration. During this period, the data growth cannot exceed the snapshot volume size.

2) the snapshot volume should be read-only and cannot be modified. The state of the stored data at that moment is

(3) In the same volume group as the original volume

4 exercises:

4.1 create a 10 Gb vg

1) create two disks: 3G and 7G 1.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220334034-0.png "/>

Create two partitions

2) Change disk type 2

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220336210-1.png "/>

Change Disk Type

3) Let the kernel repeat the partition and view result 3.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/02203361J-2.png "/>

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220335S3-3.png "/>

Repeat the partition

4) Create pv 4

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/022033NV-4.jpg "/>

Create two PVS

(5) view pvsda2. The default value is 5.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220334628-5.png "/>

It is normal that the difference between pv size and creation cannot exceed 20%)

6) create a vg named myvg 6.

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201303/135842928.png "/>

Create myvg

7) view myvg information 7

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/022033J01-7.png "/>

The myvg information is successfully created. The PE here is 4 MB by default.

4.2 Delete the myvg created above and recreate myvg. The specified PE size is 8 Mb.

1) Delete myvg 8.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/022033I10-8.jpg "/>

Figure 8 deleting myvg

2) create myvg and specify PE as 8M9.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/022033O06-9.png "/>

Figure 9 create myvg

3) Verify creation result 10

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/02203320R-10.jpg "/>

0. view the details of myvg. The PE size is 8 Mb.

4.3 Delete a pv from mypv 11

1) Remove Data from sda6, as shown in Figure 11.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220335C9-11.png "/>

1. Data is removed. No data is displayed on the disk)

2) Delete sda6 12 from myvg.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220333528-12.jpg "/>

2. Delete sda6

3) view result 13

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/022033A24-13.png "/>

3. sda6 is successfully removed.

4.4 Add a new pv to myvg

1) Create a New pv first, as shown in figure 14.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/02203335K-14.png "/>

4. The size of sda7 created for adding pv is 5 Gb)

2) Add pv to myvg, as shown in Figure 15.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220335217-15.png "/>

5. added successfully.

3) view the Add result 16.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/02203363I-16.png "/>

6. The 5G sda7 is successfully added.

4.5 create a 50 m logical volume

1) create a logical volume named testlv 17

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220333L9-17.png "/>

7. Create testlv

2) view testlv details 18

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220334K4-18.png "/>

8. The testlv information path is testlv under myvg)

3) format testlv 19.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220334494-19.jpg "/>

9 format testlv

4) Mount testlv to 20 under mnt.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220336331-20.png "/>

0. testlv mounting is successful.

5) modify the/etc/fstab file to enable automatic mounting of testlv upon startup and enable acl function 21, as shown in Figure 21.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220332628-21.png "/>

1. Use vim to edit the/etc/fstab file

4.6 extended testlv

(1) extended testlv to 5G 22, as shown in

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220334028-22.png "/>

2. Expand physical boundaries first

(2) Expand the logical boundary 23.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220334261-23.png "/>

3. Expand logical boundaries

3) view verification 24

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/02203352Y-24.png "/>

24. Expansion successful

4.7 reduce logical volume

1) scale down to 3 GB. Execute the force check Command 25 first.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220335C6-25.png "/>

5. Forward check Command

2) reduce logical volume 26

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/02203361J-26.png "/>

6 to 3G

3) view verification 27 mounted to/mnt Detection

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220333151-27.png "/>

7. scale down successfully

4,. 8 create a snapshot volume

1) create a snapshot and copy a file to the mount point before the extension and reduction, whether the application can open the file for verification) 28

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/022033F15-28.png "/>

8. Copy files

2) create snapshot Volume 29

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/02203354L-29.png "/>

9 create a snapshot volume of 50 MB with read-only permission

3) view lv information 30

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/022033M25-30.png "/>

0. View lv Information

4) The last step is to demonstrate the archive backup file 31.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0220331M0-31.png "/>

1. archive files

After the snapshot is created, Incremental Backup must be performed on the modified data in a timely manner to avoid data loss.

This article from "Deng junyang's Blog" Blog, please be sure to keep this source http://djy0000.blog.51cto.com/5816828/1154011

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.