The creation and management of Linux self-study note--lvm2

Source: Internet
Author: User


LVM2, Logical volumemanager, logical volume management, which is a mechanism for managing disk partitions in a Linux environment, is implemented by Heinz Mauelshagen on the Linux 2.4 kernel Is. A common and difficult problem for Linux users when installing Linux operating systems is how to properly evaluate the size of each partition and allocate the appropriate hard disk space. Normal disk partition management mode after the logical partition can not change its size, when a logical partition does not hold a file, the file because of the upper file system restrictions, and can not be stored across multiple partitions, so it can not be placed on another disk. When you encounter a partition that is running out of space, the solution is usually to use symbolic links, or use a tool that resizes the partition, but this is only a temporary workaround and does not fundamentally solve the problem. With the advent of Linux logical management volume functions, these problems are also solved, users can easily adjust the size of each partition without the need for downtime.

Basic terminology:

PV : Physical Volume, physical volume, a disk partition or device that logically has the same function as a disk partition (such as RAID), is the basic storage logic block of LVM, but compared to the basic physical storage media, it contains the physical parameters associated with LVM.

PE : Physical Extent, physical blocks, each physical volume PV is divided into the basic unit called Pe,pe size is configurable, the default is 4MB, so the physical volume PV by the size of the equivalent of the basic unit PE composition.

VG : Volume Group, a volume group, similar to a physical disk of a non-LVM system, consisting of one or more physical volumes of PV. You can create one or more LV (logical volumes) on a volume group.

LV : Similar to a disk partition in a non-LVM system, the logical volume is built on the VG. A file system can be established on top of a logical volume.

The relationship between the three pv,vg,lv:

650) this.width=650; "title=" 1.png "src=" https://s3.51cto.com/wyfs02/M02/9F/8D/ Wkiol1mefpor7l-iaabszkp7-v4982.png-wh_500x0-wm_3-wmp_4-s_2595433057.png "alt=" Wkiol1mefpor7l-iaabszkp7-v4982.png-wh_50 "/>

LVM creation and management of:

Prepare before creating:

In this paper, the creation of test LVM in virtual machine, first add a disk, partition, partition number is SDB1,SDB2,SDB3,SDB5.

The process is as follows:

1. View disk Partitions

650) this.width=650; "title=" 2.png "src=" https://s1.51cto.com/wyfs02/M01/00/DD/ Wkiom1mefr6yuau2aaby03sfehe207.png-wh_500x0-wm_3-wmp_4-s_2490800784.png "alt=" Wkiom1mefr6yuau2aaby03sfehe207.png-wh_50 "/>

2. use the FDISK command to partition the/DEV/SDB, and divide each of the 2G spaces into one:

650) this.width=650; "title=" 3.png "src=" https://s2.51cto.com/wyfs02/M02/00/DD/wKiom1mefsjBb_ Feaadjm09otlk177.png-wh_500x0-wm_3-wmp_4-s_4258200855.png "alt=" Wkiom1mefsjbb_feaadjm09otlk177.png-wh_50 "/>

After dividing, view the list of partitions and save the exit:

650) this.width=650; "title=" 4.png "src=" Https://s3.51cto.com/wyfs02/M02/9F/8D/wKioL1mefsuQDtWdAABs_ Cp0azm027.png-wh_500x0-wm_3-wmp_4-s_1739344758.png "alt=" Wkiol1mefsuqdtwdaabs_cp0azm027.png-wh_50 "/>

3. change the partition type to 8e:

650) this.width=650; "title=" 5.png "src=" https://s4.51cto.com/wyfs02/M00/9F/8D/ Wkiol1meftsc6lssaadyp9kahco852.png-wh_500x0-wm_3-wmp_4-s_3409654064.png "alt=" Wkiol1meftsc6lssaadyp9kahco852.png-wh_50 "/>

4. Use the PARTX command to let the kernel re-identify the new partition:

650) this.width=650; "title=" 6.png "src=" https://s5.51cto.com/wyfs02/M02/00/DD/ Wkiom1mefurjmp-aaaa-jg2c83y173.png-wh_500x0-wm_3-wmp_4-s_2454907179.png "alt=" Wkiom1mefurjmp-aaaa-jg2c83y173.png-wh_50 "/>

PV Management tools:

Pvcreate/dev/device : Create PV

PVs : Brief PV information Display

Pvdisplay : Displays details of PV

Pvchange : Changing the properties of a physical volume

Pvmove : Moving some space to another physical volume

Pvremove : Removing physical volumes

pvresize : Adjust the size of the physical volume

VG Management tools:

VGs : Display volume Group information

Vgdisplay : Show volume group details

Vgcreate [-S #[kkmmggttppee]]volumegroupname physicaldevicepath[physicaldevicepath ...] : Create a volume group

- S : Indicates the size of the physical volume PE on the volume group

- P : The maximum number of physical volumes allowed to be added in a volume group

- L : The maximum number of logical volumes allowed to be added on a volume group

Vgchange : Changing the volume Group Properties

Vgrename : Renaming a group volume

vgextend volumegroupname Physicaldevicepath [Physicaldevicepath ...] : Expanding group volumes

Vgremove : Remove a group volume

Vgscan : Scan all volume groups

vgreduce volumegroupname Physicaldevicepath [Physicaldevicepath ...] : To reduce the amount of space in a volume, do pvmove first

LV Management tools:

lvcreate-l #[mmggtt]-n NAME volumegroup : Creating a logical Volume

- N : Specifies the logical volume name

- L : Specify logical Volume size

Lvremove/dev/vg_name/lv_name : Remove a logical volume

DF–LH : Displays spatial information for logical volumes

LVs : Display Logical Volume Information

Lvdisplay : Display Logical Volume details

to extend a logical Volume:

# lvextend-l [+]#[mmggtt]/dev/vg_name/lv_name

# Resize2fs/dev/vg_name/lv_name

to shrink a logical Volume:

# Umount/dev/vg_name/lv_name

# e2fsck-f/dev/vg_name/lv_name

# RESIZE2FS/DEV/VG_NAME/LV_NAME#[MMGGTT]

# lvreduce-l [-]#[mmggtt]/dev/vg_name/lv_name

# mount

Snapshot: Snapshot

Lvcreate-l #[mmggtt]-p r-s-nsnapshot_lv_name original_lv_name

Exercise 1: Create a VG of at least two PV with a size of 6G named MYVG, require a PE size of 16MB, and then create a logical volume of 4G in the volume group Mylv; mount to the/users directory;

1. Create PV and view PV details;

650) this.width=650; "title=" 7.png "src=" Https://s1.51cto.com/wyfs02/M02/00/DD/wKiom1mefvuQ17btAACi_ Hsm6yk477.png-wh_500x0-wm_3-wmp_4-s_978771117.png "alt=" Wkiom1mefvuq17btaaci_hsm6yk477.png-wh_50 "/>

2. Create the VG and view the VG details;

650) this.width=650; "title=" 8.png "src=" https://s3.51cto.com/wyfs02/M02/00/DD/wKiom1mefwbSN_ 3baabflra0bqu611.png-wh_500x0-wm_3-wmp_4-s_700604496.png "alt=" Wkiom1mefwbsn_3baabflra0bqu611.png-wh_50 "/>

3. Create the LV and view the LV details;

650) this.width=650; "title=" 9.png "src=" https://s5.51cto.com/wyfs02/M01/9F/8D/ Wkiol1mefwagyqqlaabdcdoiv6o506.png-wh_500x0-wm_3-wmp_4-s_461377143.png "alt=" Wkiol1mefwagyqqlaabdcdoiv6o506.png-wh_50 "/>

4. format and mount the logical volume;

650) this.width=650; "title=" 10.png "src=" https://s4.51cto.com/wyfs02/M02/00/DD/ Wkiom1mefxucfunvaacvdv8u56k939.png-wh_500x0-wm_3-wmp_4-s_2400180782.png "alt=" Wkiom1mefxucfunvaacvdv8u56k939.png-wh_50 "/>

Exercise 2: Extend the volume group MYVG;

650) this.width=650; "title=" 11.png "src=" https://s5.51cto.com/wyfs02/M00/00/DD/ Wkiom1mefyacv9moaabfnr-jmxk838.png-wh_500x0-wm_3-wmp_4-s_1156929321.png "alt=" Wkiom1mefyacv9moaabfnr-jmxk838.png-wh_50 "/>

Exercise 3: Extend Mylv to 5G;

650) this.width=650; "title=" 12.png "src=" https://s3.51cto.com/wyfs02/M00/00/DD/wKiom1mefzHyp_h-AACdk4K_ Ehq282.png-wh_500x0-wm_3-wmp_4-s_3493073842.png "alt=" Wkiom1mefzhyp_h-aacdk4k_ehq282.png-wh_50 "/>

Exercise 4: Shrink mylv to 3G;

650) this.width=650; "title=" 13.png "src=" https://s5.51cto.com/wyfs02/M00/9F/8D/ Wkiol1mefzdcmzedaadw26vzxpy639.png-wh_500x0-wm_3-wmp_4-s_2777600258.png "alt=" Wkiol1mefzdcmzedaadw26vzxpy639.png-wh_50 "/>

Exercise 5: Create a snapshot of mylv and try to back up the data based on the snapshot, and verify the function of the snapshot;

1. in the/dev/myvg/mylv logical volume, first create the file, then take the snapshot;

650) this.width=650; "title=" 14.png "src=" https://s1.51cto.com/wyfs02/M00/9F/8D/ Wkiol1mef0gywvsnaabwzuczyc0597.png-wh_500x0-wm_3-wmp_4-s_760119770.png "alt=" Wkiol1mef0gywvsnaabwzuczyc0597.png-wh_50 "/>

2. view snapshots;

650) this.width=650; "title=" 15.png "src=" https://s4.51cto.com/wyfs02/M02/00/DD/ Wkiom1mef1qwlr94aacy-iqacee208.png-wh_500x0-wm_3-wmp_4-s_3152447487.png "alt=" Wkiom1mef1qwlr94aacy-iqacee208.png-wh_50 "/>

3. removing snapshots;

650) this.width=650; "title=" 16.png "src=" https://s1.51cto.com/wyfs02/M02/00/DD/ Wkiom1mef2acvit1aabjaazj5e0303.png-wh_500x0-wm_3-wmp_4-s_148914820.png "alt=" Wkiom1mef2acvit1aabjaazj5e0303.png-wh_50 "/>

Exercise 6: How to transfer data if one of the disks in the LVM system is damaged in the latter partition;

650) this.width=650; "title=" 17.png "src=" https://s1.51cto.com/wyfs02/M01/9F/8D/ Wkiol1mef2twd-jjaabjw-1befu107.png-wh_500x0-wm_3-wmp_4-s_299412763.png "alt=" Wkiol1mef2twd-jjaabjw-1befu107.png-wh_50 "/>

Exercise 7: Delete the entire logical volume;

650) this.width=650; "title=" 18.png "src=" https://s5.51cto.com/wyfs02/M02/9F/8D/ Wkiol1mef3giowuuaaccybcynsk482.png-wh_500x0-wm_3-wmp_4-s_1295640986.png "alt=" Wkiol1mef3giowuuaaccybcynsk482.png-wh_50 "/>


The creation and management of Linux self-study note--lvm2

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.