Linux Disk Management--LVM principle and basic operation

Source: Internet
Author: User

LVM (Logical Volume Manager) Logical volume management is a common operation in Linux Disk Management, this article mainly describes the basic principles of LVM and the operation of the expansion and reduction of LVM.


LVM is essentially a software way to combine multiple physical partitions or disks into a variable-size volume group of VG, and then make a variable-size logical volume LV by using the basic unit PE in the VG.

The advantages of LVM: By adjusting the number of PV in the VG to dynamically adjust the capacity of the VG, the size of the LV can be dynamically adjusted by adjusting the number of PE in the LV.


Part of LVM:

1. Partition: Available partitions on disk, partition type ID should be specified as 8e during disk partition creation

2. PV (physical Valume) Physical Volume: The lowest level of LVM used to form part of the VG

3. VG (Volume Group) Volume Group: VG is a logical large disk by combining PV

4. PE (physical Extend) physical expansion block: the smallest unit in LVM, divided when the VG is created, creating the LV essence of the specified size is to build the LV by a certain number of PE

5. LV (logic Volume) Logical Volume: divides a specified number of PE from the VG to construct a specified size LV


The process for creating LVM is as follows:


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/3D/wKioL1XfFaPjF3q0AAHGauqekoY475.jpg "title=" LVM creation process. jpg "alt=" wkiol1xffapjf3q0aahgauqekoy475.jpg "/>


Main steps:

1. Create PV: Create the available partitions of a specific type (8e) as PV

2. Create VG: make the specified PV a variable-sized volume group VG, and specify the unit PE size in VG

# 1 Actual device files will be generated when VG is created:/dev/dm-#; Also produces 2 symbolic link files pointing to the actual device file, named by:/dev/vg_name/lv_name and/dev/mapper/vg_name-lv_name

3. Create LV: A variable-sized logical volume LV with a specified number of PE in an existing VG


=============================================================

New LVM

1 Create 2 8e types of partitions/dev/sda7 and/dev/sda8 on existing disks, with 2G and 3G sizes, respectively:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/42/wKiom1XfMljAW6oQAAKF3jNHY4o576.jpg "title=" Create Lv-2.jpg "alt=" Wkiom1xfmljaw6oqaakf3jnhy4o576.jpg "/>


2 Create a new two partition as PV via pvcreat, the command is as follows, the result:

# pvcreate/dev/sda{7,8}

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/42/wKiom1XfMr_zZyUsAACJnNOCrpM642.jpg "title=" Create Lv-3.jpg "alt=" Wkiom1xfmr_zzyusaacjnnocrpm642.jpg "/>


3 using Vgcreat to create the specified PV device VG name is called MYVG, the command is as follows, the result:

# vgcreate-s 8M myvg/dev/sda7 #选项:-S #Unit: Used to specify the size and unit of the PE block in the VG

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/3F/wKioL1XfNoXAhifzAAF_SYOnutk549.jpg "title=" Create Lv-4.jpg "alt=" Wkiol1xfnoxahifzaaf_syonutk549.jpg "/>


4 in MYVG the name of the LV is MYLV, the size is 3G, the command is as follows, the result:

# lvcreate-l 3g-n mylv myvg #选项:-L #Unit: Specifies the size of the creation of the LV; -N lv_name: Specifies the name of the created LV

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/42/wKiom1XfNQ3DMZLdAALEHl1Sgu4703.jpg "title=" Create Lv-5.jpg "alt=" Wkiom1xfnq3dmzldaalehl1sgu4703.jpg "/>


5 MYLV to format the file in EXT4 format, and hang it in the/TMP/LV directory, the result:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/42/wKiom1XfNX3AyjKxAAK3clLuIcw473.jpg "style=" float: none; "title=" creates lv-6.jpg "alt=" Wkiom1xfnx3ayjkxaak3clluicw473.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/3F/wKioL1XfN5fA1Vd6AAHks10IRMk962.jpg "style=" float: none; "title=" creates lv-7.jpg "alt=" Wkiol1xfn5fa1vd6aahks10irmk962.jpg "/>


At this point, the file system created on the LVM can be accessed through the/tmp/lv/


=============================================================

Scaling LV

When users feel that the existing LV partition disk space is small, the MYLV can be expanded by LVM to 3G space

1 Create 1 new disk partitions on an existing disk/dev/sda9, type 8e, size 4G, results:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/3F/wKioL1XfOl2A_EiUAAJk7khE-6w278.jpg "title=" Extended LV Capacity -1.jpg "alt=" Wkiol1xfol2a_eiuaajk7khe-6w278.jpg "/>


2 Create the/DEV/SDA9 as PV and add/dev/sda9 to the existing MYVG, similar to the 2nd and 3 steps in creating the LV, which is not described here, and the result

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/72/3F/wKioL1XfPPvjq2s0AADhlRm6I70566.jpg "title=" Extended LV Capacity -3.jpg "alt=" Wkiol1xfppvjq2s0aadhlrm6i70566.jpg "/>


3 Use the Lvextend command to expand the current mylv to a size of 6G, the command is as follows, the result:

# lvextend-l +3g/dev/myvg/mylv #选项:-l [+] #Unit: Specify the expansion space, use + when the # is the variable value, do not use + when the # is the target value, unit for the specified units

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/42/wKiom1XfOdfABpbAAAMYFPGVhiw666.jpg "title=" Extended LV Capacity -4.jpg "alt=" Wkiom1xfodfabpbaaamyfpgvhiw666.jpg "/>


4 relative Mylv mount point/tmp/mylv to see that the directory size has not changed, because the file system does not change, you need to use RESIZE2FS to re-plan the file system boundaries, the command is as follows, the result:

# RESIZE2FS/DEV/MYVG/MYLV #使用resize2fs命令不指定分区调整后的大小时, all partition sizes will be used

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/42/wKiom1XfO7OgclaCAAIZdCscKyE367.jpg "title=" Extended LV Capacity -5.jpg "alt=" Wkiom1xfo7ogclacaaizdcsckye367.jpg "/>


At this point, the LV extension has been completed by displaying a file system size of 6G after expansion

Note: When you expand the LV, you do not need to unmount the file system, which can be expanded when the file system is mounted.

=============================================================

To crop a LV

If you find that the file system usage on an existing LV partition is low and you waste existing disk space, you can crop the LV to reduce the size of the LV partition.

Clipping the MYLV will guarantee the integrity of the files that are already in the file system, replicating two directories/bin and/sbin to the MYLV filesystem first.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/3F/wKioL1XfP8uC0ag_AALVMpcyuuA013.jpg "style=" float: none; "title=" crop LV capacity -1.jpg "alt=" Wkiol1xfp8uc0ag_aalvmpcyuua013.jpg "/>


1 First uninstall the MYLV, and then the Mylv file system to force the disk check, the command is as follows,

# umount/dev/myvg/mylv # e2fsck-f/dev/myvg/mylv

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/42/wKiom1XfPbKyzLnQAAL4pmeLlC8385.jpg "style=" float: none; "title=" crop LV capacity -2.jpg "alt=" Wkiom1xfpbkyzlnqaal4pmellc8385.jpg "/>


2 Use the RESIZE2FS command to reduce the size of the Mylv file system to 1G, as shown in the following command:

# RESIZE2FS/DEV/MYVG/MYLV 1G #指定文件系统更改后的大小为1G

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/3F/wKioL1XfP8uwZLItAADSnx5bl7E758.jpg "style=" float: none; "title=" crop LV capacity -3.jpg "alt=" Wkiol1xfp8uwzlitaadsnx5bl7e758.jpg "/>


3 Use the Lvreduce command to reduce the MYLV partition to 1G size, the reduced space is reassigned to MYVG, the command is as follows, the result:

# lvreduce-l 1g/dev/myvg/mylv

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/43/wKiom1XfQFGRBIShAAGKc_jdnW8958.jpg "title=" Crop LV capacity -4.jpg "alt=" Wkiom1xfqfgrbishaagkc_jdnw8958.jpg "/>


4 If you want to centralize the space used in MYLV to the specified physical disk partition, you need to look at the usage of the existing PV, as shown in:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/3F/wKioL1XfP8vBy_GaAAJ-GtBTg2c956.jpg "style=" float: none; "title=" crop LV capacity -5.jpg "alt=" Wkiol1xfp8vby_gaaaj-gtbtg2c956.jpg "/>

Discover that all that is now used is the space in the physical disk partition/dev/sda7,/dev/sda8 and/dev/sda9 Chinese blank


5 now need to use/DEV/SDA9 to use as PV, the other two disks removed from the PV, you need to use Pvmove to transfer the data in/dev/sda7 to/DEV/SDA9, the command is as follows, the result:

# PVMOVE/DEV/SDA7/DEV/SDA9

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/43/wKiom1XfPbKz3VYXAAB8hfnOX7E954.jpg "style=" float: none; "title=" crop LV capacity -6.jpg "alt=" Wkiom1xfpbkz3vyxaab8hfnox7e954.jpg "/>


6 View all data in the/DEV/SDA7 to be transferred to/DEV/SDA9

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/3F/wKioL1XfP8zg1m4YAAJl3F526jo707.jpg "style=" float: none; "title=" crop LV capacity -7.jpg "alt=" Wkiol1xfp8zg1m4yaajl3f526jo707.jpg "/>


7 Use Vgreduce to remove the specified device from the MYVG, as shown in the following command:

# Vgreduce myvg/dev/sda{7,8}

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/43/wKiom1XfPbLR3ALYAAECdRXaDVs831.jpg "style=" float: none; "title=" crop LV capacity -8.jpg "alt=" Wkiom1xfpblr3alyaaecdrxadvs831.jpg "/>


8 Use Pvremove to remove/dev/sda7 and/dev/sda8 from PV, command as follows, result:

pvremove/dev/sda{7,8}

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/3F/wKioL1XfP8zSOZ0eAADgh1QXdL8115.jpg "style=" float: none; "title=" crop LV capacity -9.jpg "alt=" Wkiol1xfp8zsoz0eaadgh1qxdl8115.jpg "/>


9 finally mount the MYPV to the original mount point:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/43/wKiom1XfQ3OQV4rRAAGgmi1-j2M975.jpg "title=" Crop LV capacity -10.jpg "alt=" Wkiom1xfq3oqv4rraaggmi1-j2m975.jpg "/>

You can see that the replicated/bin and/sbin two directories still exist, indicating that clipping of the LV does not affect its internal file system


At this point, the LV clipping has been completed

Note: When the LV is clipped, the file system needs to be unloaded, the file system must be forced to check and re-modify the file system boundaries, in the LVM partition operation of the disk, to ensure that the physical disk partition to be removed is blank, the corresponding PV will be moved out of the VG, and then moved itself out of the PV


This article is from the "Pavel" blog, make sure to keep this source http://pavel86.blog.51cto.com/8349178/1689134

Linux Disk Management--LVM principle and basic operation

Related Article

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.