Introduction and management of Linux LVM

Source: Internet
Author: User
Tags uuid

What is LVM?

LVM is the abbreviation for Logical Disk volume management (logicalvolumemanager), which is a mechanism for managing disk partitions in a Linux environment, and LVM is a logical layer built on hard disks and partitions to improve the flexibility of disk partition management. System administrators can easily manage disk partitioning through LVM, such as connecting several disk partitions or physical disks to a single block of volume group (volumegroup) to form a storage pool. Administrators can create logical volume groups (logicalvolumes) at will on a volume group and further create file systems on logical volume groups. The administrator can easily adjust the size of the storage volume group through LVM, and the disk storage can be named, managed and assigned as a group, for example, "development" and "sales", instead of using the physical disk name "SDA" and "SDB". There is a lot of flexibility relative to normal disk partitioning, and using normal disk partitioning can cause a lot of trouble when the partition space of a disk is not enough, and using LVM makes it very flexible to resize the partition and the data is unaffected.

Basic terminology

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

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

LV (logical volume, Logical Volume): Similar to a disk partition in a non-LVM system, the logical volume is built on the volume group VG. File system can be established above the logical volume LV

PE (physical block, physical Extent): each physical volume PV is divided into a basic unit of PE (physical extents), with a unique number of PE is the smallest unit that can be addressed by LVM. The size of the PE is configurable and defaults to 4MB. So the physical volume (PV) is made up of basic unit PE of equal size

Le (logical block, Logical Extent): The logical volume LV is also divided into an addressable basic unit called Le. In the same volume group, the size of Le is the same as PE, and one by one corresponds


PV, VG, LV, there is a logical relationship between, LVM is a number of fragmented disk partition (PV) into a larger disk (VG), and then on the need for the larger disk (VG) divided into different small partitions (LV), And these small partitions (LV) can be expanded or scaled up dynamically. While PE is the basic component of PV, Le is the basic unit of LV.


Create LVM

1th Step: First create PV,PV can use the new disk directly, you can use the partition, if you use the partition, you need to change the partition's identity to 8e (Linux LVM) When you create the partition.

The command to create the PV is: pvcreate [-F] DEVICE

The commands for viewing PV are: Pvdisplay, PVS

#直接将一块新的磁盘创建为PV [[email protected] ~]# pvcreate /dev/sdb# Use Partition to create pv[[email protected]  ~]# fdisk -l /dev/sdc...    Equipment  Boot       start         end      blocks    Id  System/dev/sdc1             2048    41943039    20970496   8e   linux lvm[[email protected] ~]# pvcreate /dev/sdc1# View the created pv[[email  protected] ~]# pvs  pv         vg    Fmt  Attr PSize  PFree   /dev/sdb         lvm2 ---  20.00g 20.00g  /dev/sdc1        lvm2 ---  20.00g 20.00g[[email protected] ~]# pvdisplay    "/DEV/SDD"  is  a new physical volume of  "20.00 gib"   --- new physical  volume ---  PV Name                /dev/sdb  VG Name                  PV Size                20.00 GiB  Allocatable            NO  PE Size                0     Total PE               0  Free PE                0  allocated pe           0  PV UUID                ZI9SJA-ZARN-1FRG-QW5F-IPHH-7OEY-BIIZCP &NBSP, .....

2nd step: Create the VG, you must specify the name of the volume group and the PV used to create the VG, you can use the-s option to specify the size of the PE, the default size of PE is 4M,

The specific command is: vgcreate [-S #[kkmmggttppee]] volumegroupname Physicaldevicepath [Physicaldevicepath ...]

The commands to view the VG are: Vgdisplay, VGS

#创建一个名为vg0, the VG volume group with a PE size of 8M, and/dev/sdb and/DEV/SDC1 are added to the volume group [[email protected] ~]# vgcreate -s  8m vg0 /dev/sd{b,c1}  volume group  "Vg0"  successfully created# view Create a good VG [[email protected] ~]# vgs   vg    #PV   #LV   #SN  attr    vsize  vfree   vg0    2   0    0 wz--n- 39.98g 39.98g[[email protected] ~]# vgdisplay    --- Volume group ---  VG Name                vg0  System ID                Format                 lvm2  Metadata Areas         2  metadata sequence no  1  vg access              read/write  VG Status              resizable  MAX LV                 0  cur lv                 0   open lv               0   Max PV                 0  Cur PV                 2  Act PV                 2  vg size                39.98 GiB  PE Size                8.00 MiB  Total PE               5118  Alloc PE / Size        0 / 0     Free  PE / Size        5118 / 39.98 GiB  VG UUID                ajzwei-ukux-mtez-wkkz-k5ea-f9tl-qklhnu

3rd step: Create the LV, you must indicate from which volume group to create the LV, you can use the-l option to specify the size of the LV, and you can use the-N option to specify the name of the LV

The specific command is: Lvcreate-l #[mmggtt]-n NAME volumegroup

The commands to view the LV are: Lvdisplay, LVS

#创建一个名为lv0, lv[[email protected] ~]# lvcreate -l 15g -n lv0 vg0 of size 15G   Logical volume  "Lv0"  created.   #查看创建好的LV [[email protected] ~]#  lvs  LV   VG   Attr        lsize  pool origin data%  meta%  move log cpy%sync  CONVERT  LV0  VG0  -WI-A----- 15.00g                                                       [[email protected] ~]# lvdisplay    --- Logical volume ---  LV Path                 /dev/vg0/lv0  LV Name                 lv0  VG Name                 vg0  lv uuid                  rqmmht-gv5d-jquu-sgfd-4m0v-jrpf-uu9bg8  lv write access         read/write  lv creation host, time fengl, 2016-08-30  18:59:38 +0800  LV Status               available  # open                  0  LV Size                 15.00 gib  current le              1920  Segments                1  Allocation              inherit  read ahead sectors     auto   - currently set to     8192  block device            253:0

4th step: Format, Mount

#格式化分区 [[email protected] ~]# mkfs.ext4/dev/vg0/lv0 #查看分区 [[email protected] ~]# blkid .../dev/mapper/vg0-lv0:uuid= " 78248233-6e64-47ae-9392-2abf6a25fbf0 "type=" Ext4 "#挂载到/MNT/LVM, if you want to power on auto mount you need to add mount information in the/etc/fstab configuration file [email Protected] ~]# mount Uuid= "78248233-6e64-47ae-9392-2abf6a25fbf0"/MNT/LVM

LVM Management

(1) Expansion of the expansion of LV:LV need two steps, the first step to expand the LV size, this step can use the-l option to specify the specific expansion to how much, or add more space on the original basis, you can use the-l option to use a percentage of capacity expansion, after the first step to see the LV does expand, However, the size of the mounted partition is still the same size, if the file system of the EXT series can use the Resizefs command to reset the size, the command uses the following format:

lvextend-l [+]#[bbsskkmmggttppee]/dev/vg_name/lv_name or

Lvextend-l [+]#[%{vg|lv| pvs| free| ORIGIN}]/dev/vg_name/lv_name

Resize2fs/dev/vg_name/lv_name

#将LV从15G扩容到20G [[email protected] ~]# lvextend-l +5g/dev/vg0/lv0 #方法1 [[email protected] ~]# lvextend-l 20g/dev/vg0/l V0 #方法2 # Capacity expansion using percentages, such as VG0 all remaining space to Lv0[[email protected] ~]# lvextend-l +100%free/dev/vg0/lv0# reset size [[email protected] ~ ]# Resize2fs/dev/vg0/lv0

(2) Reduction of LV:LV is a little more troublesome than the expansion, you need to cancel the mount, and then use the E2FSCK command to force file system detection, and then use the RESIZE2FS command to reduce the size of the file system, note that the size of the reduction can not be less than the total size of all the files under the partition, Finally, use the Lvreduce command to reduce the size of the logical volume to how large

lvreduce-l [-]#[bbsskkmmggttppee]/dev/vg_name/lv_name or

Lvreduce-l [-]#[%{vg|lv| free| ORIGIN}]/dev/vg_name/lv_name

#卸载已经挂载的逻辑卷 [[email protected] ~]# umount/dev/vg0/lv0# Force Detection Logical Volume [[email protected] ~]# e2fsck-f/dev/vg0/lv0# reduced file system size 30G [[email protected] ~]# resize2fs/dev/vg0/lv0 30g# reduced logical volume size to 30g[[email protected] ~]# lvreduce-l 30g/dev/vg0/lv0# re-mount [[EM AIL protected] ~]# mount/dev/vg0/lv0/mnt/lvm/

(3) Expansion of VG: Volume group expansion needs to increase the PV, and then add the new PV into the VG can be

Vgextend volumegroupname Physicaldevicepath [Physicaldevicepath ...]

#新建一个新的PV [[email protected] ~]# pvcreate/dev/sdd# expansion VG, add new/dev/add to Vg0[[email protected] ~]# vgextend VG0/DEV/SDD

(4) Reduced VG: Remove a PV from the VG, it should be noted that if the PV to be removed is already in use, you need to use Pvmove to remove the PE

Vgreduce volumegroupname Physicaldevicepath [Physicaldevicepath ...]

#先将/DEV/SDD in the PE move out [[email protected] ~]# pvmove/dev/sdd# again reduced VG size, will/DEV/SDD removed from vg0 [[email protected] ~]# vgreduce vg0 /dev/sdd

(5) Delete LVM

#先卸载已经挂载的逻辑卷 [[email protected] ~]# umount/dev/vg0/lv0# delete lv[[email protected] ~]# lvremove/dev/vg0/lv0# Delete vg[[email Protected] ~]# vgremove/dev/vg0# delete pv[[email protected] ~]# Pvremove/dev/sd{b,ca,d}





This article is from the "Linux Operational Learning path" blog, please be sure to keep this source http://fengliang.blog.51cto.com/3453935/1844280

Introduction and management of Linux LVM

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.