Logical volume management for linux advanced File System Management

Source: Internet
Author: User

1. What is LVM?
LVM: (Logical Volume Manager) Logical Volume Manager. LVM combines several physical partitions or disks into a seemingly independent large disk (VG) through software, and then divides this large disk into usable partitions (LV: logical volume). These partitions (LV) can be expanded or reduced to elastically adjust the capacity of the file system.
Ii. PV, PE, VG, and LV
PV: (Physical Volume) Physical Volume. The bottom layer of LVM is the physical volume. The partition must be adjusted to an 8e (LVM identifier) and converted to PV by command pvcreate. Then, these PVS can be used.
VG :( Volume Group) Volume Group. A vg is formed by combining multiple PVS.
PE :( Physical Extents) Disk Area (Physical expansion block ). By default, LVM uses a 4 mb pe block. The number of PES directly determines the LV size. PE is the minimum storage unit of LV.
LV :( Logical Volume) Logical Volume. The VG is cut into LV, which is the partition that can be used after the last format.
Iii. logical volume creation process
Note: disk partitions are not described in detail here.
1. Create a PV: After the disk partition is created, adjust the system identifier to 8e (LVM identifier) and create a view PV.
Command: pvcreate
Syntax: pvcreate Device File
Pvdisplay: View pv Information
Pvs: view brief pv Information


2. Create VG: integrate multiple PVS into VG
Command: vgcreate
Syntax: vgcreate VG name [-s PE size (4 MB by default)] pv1 pv2...
Vgdisplay: View vg Information
Vgs: view brief vg Information
Instance: Create myvg and set the PE size to 8 MB.



3. Create LV: partition VG
Command: lvcreate
Syntax: lvcreate-L LV_SIZE-n LV_NAME VG_NAME
Options:-l indicates the number of PES.
Lvdisplay: displays LV Information
Lvs: displays brief lv information.


4. logical volume device file
/Dev/VG_NAME/LV_NAME
/Dev/mapper/VG_NAME-LV_NAME
5. format the logical volume
Mkfs-t FSTYPE/dev/VG_NAME/LV_NAME
Mke2fs-t {ext2 | ext3 | ext4}/dev/VG_NAME/LV_NAME


6. Mount the logical volume
Mount [-tFSTYPE]/dev/VG_NAME/LV_NAME mount point




Iv. VG expansion and reduction
1. VG Extension
First create a new PV
Command: vgextend
Syntax: vgextend VG_NAME Device File
2. VG reduction
Determine the PV to be removed
Transfers data on this PV to other PVS
Command: pvmove
Syntax: pvmove Device File
Remove this PV from the volume group
Syntax: vgreduce VG_NAME/PATH/TO/PV


V. logical volume Scaling
Note: Pay attention to the limitations of commands.
First, determine the extended size of the logical volume.
Make sure that the volume group of the Current Logical volume has sufficient free space;
Extension:
1. physical boundaries
Lvextend-L [+] SIZE/path/to/lv
2. logical boundaries
Resize2fs/path/to/device


Vi. logical volume reduction
Prerequisites for determining the scale-down: at least all the original data can be accommodated.
1. Uninstall and forcibly detect the file system;
E2fsck-f
2. logical boundaries
Resize2fs/path/to/deviceSIZE
3. physical boundaries
Lvreduce-L [-] SIZE/path/to/lv
VII. LVM System 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.
3. In the same volume group as the original volume
Command: lvcreate
Options:
-S: Snapshot volume;
-P r: Restrict read-only access to snapshot volumes
Syntax: lvcreate-l size-s-p r-n LV_SNAP_NAME/path/to/lv




8. Remove volume groups and logical volumes
1. Remove a volume group
Command: vgremove
Syntax: vgremove VG_NAME
2. Remove logical volumes
Command: lvremove
Syntax: lvremove/path/to/lv

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.