The management of LVM in Linux

Source: Internet
Author: User

1.LVM Overview

LVM is shorthand for Logical Volume Manager (Logical Volume management), which is implemented by Heinz Mauelshagen on the Linux 2.4 kernel. LVM sets the partition of one or more hard disks logically, equivalent to a large hard disk to use, when the hard disk space is not enough to use, you can continue to add the partitions of other hard disks, so that the dynamic management of disk space, relative to the normal disk partition has a lot of flexibility.

LVM provides a higher level of disk storage for computers than traditional disks and partitions. It makes it easier for system administrators to allocate storage space for apps and users. Storage volumes under LVM management can be resized and removed as needed at any time (file system tools may need to be upgraded). LVM also allows storage volumes to be managed by user groups, allowing administrators to identify storage volumes with more intuitive names (such as "Sales", "development") instead of physical disk names (such as ' SDA ', ' SDB ').

LVM Model:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9D/C6/wKiom1mFtTeBEF3DAAIZzeKdcN8959.png "title=" Screenshot from 2017-08-05 20-07-55.png "alt=" Wkiom1mfttebef3daaizzekdcn8959.png "/>

A large amount of space can be composed of four partitions, and then some logical partitions are partitioned, and when there is not enough space for a logical partition, some space can be allocated from the remaining space to the partition where space is not available. LVM is a logical layer that is added between the disk partition and the file system to mask the underlying disk partition layout for the file system, providing an abstract disk volume, and creating a file system on the disk volume.

LVM noun explanation

Physical storage media (the physical media): This refers to the system's storage device: The hard disk, such as:/DEV/HDA1,/DEV/SDA, etc., is the lowest layer of storage system storage unit.

Physical volume (physical volume): a physical volume refers to a hard disk partition or a device (such as RAID) that logically has the same function as a disk partition, which is the basic storage logic block of LVM, but is compared to basic physical storage media (such as partitions, disks, etc.) and contains management parameters related to LVM.

Volume group (Volume Group): LVM volume groups are similar to physical hard disks in non-LVM systems, which consist of physical volumes. You can create one or more LVM partitions (logical volumes) on a volume group, and an LVM volume group consists of one or more physical volumes.

Logical volumes (logical volume): LVM logical volumes are similar to hard disk partitions in non-LVM systems, and file systems (such as/home or/usr) can be created on top of logical volumes.

PE (physical extent): each physical volume is divided into a basic unit called PE (physical extents), with a uniquely numbered PE being the smallest unit that can be addressed by LVM. The size of the PE is configurable and defaults to 4MB.

Le (logical extent): Logical volumes are also divided into addressable basic units called LE (logical extents). In the same volume group, the size of Le is the same as the PE, and one by one corresponds.

In simple terms:

PV: is a physical partition of the disk

The physical disk partition in VG:LVM, which is PV, must be added to the VG, which can be understood as a warehouse or a few large hard disks.

LV: The logical partition from the VG

As shown in PV, VG, LV three relations:

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/C5/wKioL1mFtcrQOyZHAAH8XP74f10317.png "title=" Screenshot from 2017-08-05 20-10-24.png "alt=" Wkiol1mftcrqoyzhaah8xp74f10317.png "/>


Production of 2.LVM
First, you need FDIs to create the partition

Note: The LVM format for Linux is 8e650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/9D/C2/ Wkiom1mfc2vt9-pdaabzww_vq8a776.png "title=" screenshot from 2017-08-03 15-07-59.png "alt=" wKiom1mFc2vT9-PDAABZwW_ Vq8a776.png "/>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9D/C2/wKioL1mFdV3ClBQAAADk4vx0rHc496.png "style=" float : none; "title=" screenshot from 2017-08-03 15-08-26.png "alt=" Wkiol1mfdv3clbqaaadk4vx0rhc496.png "/>

3.LVM Build

Do before monitoring PV VG LV

Watch-n 1 ' pvs;echo ==========;vgs;echo ===========;lvs;echo ===========;d f-h/mnt '


PVCREATE/DEV/VDB1 physical partitions into physical volumes

Vgcreate VG0/DEV/VDB1 to make a physical volume group of/DEV/VDB1 This physical volume vg0
Lvcreate-l 100m-n lv0 vg0 set up vg0 device in lv0 This group-l specify device size-n Specify device name

Mkfs.xfs/dev/vg0/lv0 Formatting Logical Volumes

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/C2/wKioL1mFdV7zu_76AAG2Eh-FlSo539.png "style=" float : none; "title=" screenshot from 2017-08-03 15-15-39.png "alt=" Wkiol1mfdv7zu_76aag2eh-flso539.png "/>

Mount

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9D/C3/wKiom1mFeWzzkBCaAAAbE3MsPbs888.png "title=" Screenshot from 2017-08-03 15-15-57.png "alt=" Wkiom1mfewzzkbcaaaabe3mspbs888.png "/>


Expansion of 4.LVM devices
For XFS file systems, the XFS file system can only be scaled
(1) LVM enlargement
Lvextend-l 150m/dev/vg0/lv0 Extended LVM device to 150M
Xfs_growfs/dev/vg0/lv0 enlarge XFS File system to device size

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9D/C3/wKioL1mFf2qzUF2rAAItYtrrYZM354.png "title=" Screenshot from 2017-08-05 16-17-26.png "alt=" Wkiol1mff2qzuf2raaitytrryzm354.png "/>


(2) VG Enlargement

Fdisk/dev/vdb Add a new piece of hard disk and change the partition function to LVM
Partprobe Synchronizing a partitioned list

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9D/C3/wKioL1mFgKKzeDf9AAF0nejomkE525.png "title=" Screenshot from 2017-08-03 15-27-36.png "alt=" Wkiol1mfgkkzedf9aaf0nejomke525.png "/>

PVCREATE/DEV/VDB2 add a piece of equipment to PV/DEV/VDB2
Vgextend VG0/DEV/VDB2 Add the newly created/DEV/VDB2 to the VG0

Lvextend-l 300m/dev/vg0/lv0 Extended LVM device to 300M

Xfs_growfs/dev/vg0/lv0 enlarge XFS File system to device size

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9D/C3/wKiom1mFgYTz7BTIAAI0pySN9-c729.png "title=" Screenshot from 2017-08-03 15-31-29.png "alt=" Wkiom1mfgytz7btiaai0pysn9-c729.png "/>


Reduction of 5.LVM

Note: XFS file systems cannot be scaled down and EXT4 can, ext file system can be expanded or reduced

Ext4 extended to 400M

umount/mnt/un-mount

Since the XFS partition format cannot be reduced, the XFS file format file is first converted to EXT4

Mkfs.ext4/dev/vg0/lv0 formatted/dev/vg0/lv0 to EXT4

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9D/C4/wKiom1mFg93whTErAAFNTBfYAxg121.png "title=" Screenshot from 2017-08-03 16-00-54.png "alt=" Wkiom1mfg93whteraafntbfyaxg121.png "/>

mount/dev/vg0/lv0/mnt/Mount

Lvextend-l 400m/dev/vg0/lv0 Extended LVM device to 400M

Resize2fs/dev/vg0/lv0 Extended File System

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9D/C3/wKioL1mFhILSWK3MAADE1-tBNWU693.png "title=" Screenshot from 2017-08-03 16-01-07.png "alt=" Wkiol1mfhilswk3maade1-tbnwu693.png "/>

Adjusted LVM size and file system can be queried via df-h



EXT4 reduced to 200M

umount/mnt/un-mount

E2fsck-f/dev/vg0/lv0 detects disk contents to prevent content loss

Resize2fs/dev/vg0/lv0 200M Disk partition reduction
mount/dev/vg0/lv0/mnt/Mount
Lvreduce-l 200m/dev/vg/lv0 Disk Device reduction


650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9D/C3/wKioL1mFh72BoNbJAACWGUqPhCk168.png "title=" Screenshot from 2017-08-03 16-06-44.png "alt=" Wkiol1mfh72bonbjaacwguqphck168.png "/>

Reduced to 100M

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9D/C4/wKiom1mFh4iRHaxRAAGntq0Gy2U403.png "title=" Screenshot from 2017-08-03 16-09-52.png "alt=" Wkiom1mfh4irhaxraagntq0gy2u403.png "/>

Adjusted LVM size and file system can be queried via df-h


7. Move and remove the contents of the disk

PVMOVE/DEV/VDB1/DEV/VDB2 move all data on the VDB1 to VDB2

Vgreduce vg0/dev/vdb1 Remove/DEV/VDB1 from vg0
PVREMOVE/DEV/VDB1 to remove LVM management information from the/DEV/VDB1


650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9D/C4/wKiom1mFiTWxmFpTAAB4zFn6E1Q719.png "title=" Screenshot from 2017-08-03 16-12-35.png "alt=" Wkiom1mfitwxmfptaab4zfn6e1q719.png "/>

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/C3/wKioL1mFiXnj5MmvAACs47Ie2Hc053.png "title=" Screenshot from 2017-08-03 16-12-25.png "alt=" Wkiol1mfixnj5mmvaacs47ie2hc053.png "/>


8.LVM Snapshots
Lvcreate-l 20m-n lv0-backup-s/dev/vg0/lv0 set up a snapshot for/dev/vg0/lv0

-L Specify Snapshot size

-n Specifies the snapshot name

-s Specifies the snapshot template device

umount/mnt/

TOUCH/MNT/FILE{1..100}
Lvcreate-l 20m-n lv0-backup-s/dev/vg0/lv0
mount/dev/vg0/lv0picture/mnt/
ls/mnt/

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9D/C4/wKiom1mFilDTPN9UAACbtuV8Qs0622.png "style=" float : none; "title=" screenshot from 2017-08-03 16-46-45.png "alt=" Wkiom1mfildtpn9uaacbtuv8qs0622.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9D/C3/wKioL1mFilGBc4YlAAGAvo9E_ZY990.png "style=" float : none; "title=" screenshot from 2017-08-03 16-47-13.png "alt=" Wkiol1mfilgbc4ylaagavo9e_zy990.png "/>

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9D/C4/wKiom1mFilLR-fs0AAAyzKoxeOM529.png "style=" float : none; "title=" screenshot from 2017-08-03 16-48-50.png "alt=" Wkiom1mfillr-fs0aaayzkoxeom529.png "/>

Mount after creation is complete

Mount/dev/vg0/lv0-backup/mnt


When the data in the snapshot device is changed, if you want to restore, delete the snapshot device, re-establish the snapshot
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9D/C6/wKioL1mFuRjQaR-OAABPYm-Yr58205.png "title=" Screenshot from 2017-08-05 20-24-27.png "alt=" Wkiol1mfurjqar-oaabpym-yr58205.png "/>
9.LVM Delete
Delete order: lvremove---->vgremove----->pvremove

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9D/C6/wKiom1mFuSnhRYIVAABCtmJYOyY169.png "title=" Screenshot from 2017-08-05 20-24-38.png "alt=" Wkiom1mfusnhryivaabctmjyoyy169.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9D/C4/wKioL1mFi3WBa8N9AAAnmmERfMw359.png "style=" float : none; "title=" screenshot from 2017-08-03 17-06-15.png "alt=" Wkiol1mfi3wba8n9aaanmmerfmw359.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9D/C4/wKiom1mFi3Wy5yOdAAAx7GlPnLs716.png "style=" float : none; "title=" screenshot from 2017-08-03 17-06-29.png "alt=" Wkiom1mfi3wy5yodaaax7glpnls716.png "/>

Results after a query is deleted

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9D/C4/wKiom1mFi3bx-botAABGb22VWVY387.png "style=" float : none; "title=" screenshot from 2017-08-03 17-07-38.png "alt=" Wkiom1mfi3bx-botaabgb22vwvy387.png "/>




The management of LVM in Linux

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.