Summary of LVM logical volume Management

Source: Internet
Author: User

Create and manage LVM:

Create a partition

Disk/dev/xvdc: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersunits = cylinders of 16065*512 = 8225280 bytessector size (logical/physical ): 512 bytes/512 bytesi/o size (minimum/optimal): 512 bytes/512 bytesdisk identifier: 0xd199e24a device boot start end blocks ID system/dev/xvdc1 1 65 522081 8e Linux LVM # adjust the partition type to Linux LVM/dev/xvdc2 66 104 313267 + 8e Linux LVM/dev/xvdc3 105 181 618502 + 8e Linux LVM

Create PV:

Pvcreate/path/to/device create physical volume

[[email protected]_168_102_centos ~]# pvcreate /dev/xvdc{1,2,3}  Writing physical volume data to disk "/dev/xvdc1"  Physical volume "/dev/xvdc1" successfully created  Writing physical volume data to disk "/dev/xvdc2"  Physical volume "/dev/xvdc2" successfully created  Writing physical volume data to disk "/dev/xvdc3"  Physical volume "/dev/xvdc3" successfully created

View the existing physical volume in PVS [/path/to/pv_device]

[[email protected]_168_102_centos ~]# pvs  PV         VG   Fmt  Attr PSize   PFree    /dev/xvdc1      lvm2 a--  509.84m 509.84m  /dev/xvdc2      lvm2 a--  305.93m 305.93m  /dev/xvdc3      lvm2 a--  604.01m 604.01m[[email protected]_168_102_centos ~]# pvs /dev/xvdc1  PV         VG   Fmt  Attr PSize   PFree    /dev/xvdc1      lvm2 a--  509.84m 509.84m

Pvdisplay [/path/to/pv_device] displays physical volume properties

[[Email protected] _ 168_102_centos ~] # Pvdisplay/dev/xvdc1 "/dev/xvdc1" is a new physical volume of "509.84 MIB" --- new physical volume --- PV name/dev/xvdc1 # PV name VG name # vg pv size 509.84 MIB # PV size allocatable no pe size 0 # PE size, default 4 Total pe 0 # Total number of PES free pe 0 # Number of idle PES allocated pe 0 # Number of PES allocated pv uuid sCID3E-GNNl-DoeW-BaLW-kuYj-fskV-RhLx8g

Create an VG volume group:

Vgcreate [-s size] vg_name/path/to/pv_device

-S: Specifies the PE size. The default value is 4 MB.

[[email protected]_168_102_centos ~]# vgcreate -s 8 myvg /dev/xvdc{1,2}  Volume group "myvg" successfully created

View existing volume groups in vgs [/path/to/vg_device]

[[email protected]_168_102_centos ~]# vgs  VG   #PV #LV #SN Attr   VSize   VFree    myvg   2   0   0 wz--n- 808.00m 808.00m

Vgdisplay [/path/to/vg_device]

[[email protected]_168_102_centos ~]# vgdisplay   --- Volume group ---  VG Name               myvg  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               808.00 MiB  PE Size               8.00 MiB  Total PE              101  Alloc PE / Size       0 / 0     Free  PE / Size       101 / 808.00 MiB  VG UUID               R35yt2-S4dp-M9oY-4O1d-1CqX-4CQd-t0TpB9

Vgrename vg_name new_name modify the volume group name

[[email protected]_168_102_centos ~]# vgrename myvg testvg  Volume group "myvg" successfully renamed to "testvg"[[email protected]_168_102_centos ~]# vgs  VG     #PV #LV #SN Attr   VSize   VFree    testvg   2   0   0 wz--n- 808.00m 808.00m

Create logical volume:

Lvcreate-l size-N name vg_name create logical volume

[[email protected]_168_102_centos ~]# lvcreate -L 500M -n mylv /dev/myvg  Rounding up size to full physical extent 504.00 MiB  Logical volume "mylv" created

LVS [/path/to/lv_device]

[[email protected]_168_102_centos ~]# lvs  LV   VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv myvg -wi-a--- 504.00m

Lvdisplay [/path/to/lv_device]

/path/to/lv_device[[email protected]_168_102_centos ~]# lvdisplay   --- Logical volume ---  LV Path                /dev/myvg/mylv  LV Name                mylv  VG Name                myvg  LV UUID                nnelF1-sSxC-0A1l-IzLf-YqwL-djsy-lMeiTH  LV Write Access        read/write  LV Creation host, time VM_168_102_centos, 2014-08-24 16:12:08 +0800  LV Status              available  # open                 0  LV Size                504.00 MiB  Current LE             63  Segments               1  Allocation             inherit  Read ahead sectors     auto  - currently set to     256  Block device           253:7

About formatting and attaching the Logical Data of mylv2:

[[Email protected] _ 168_102_centos ~] # Mke2fs-T ext4/dev/myvg/mylvmke2fs 1.41.12 (17-may-2010 )... omit this filesystem will be automatically checked every 26 mounts or180 days, whichever comes first. use tune2fs-C or-I to override. [[email protected] _ 168_102_centos ~] # Mount/dev/myvg/mylv/tmp/wanghan [[email protected] _ 168_102_centos ~] # Mount/dev/xvda1 on/type ext3 (RW, noatime, ACL, user_xattr) proc on/proc type proc (RW) sysfs on/sys type sysfs (RW) devpts on/dev/PTS type devpts (RW, mode = 0620, gid = 5) None on/proc/sys/fs/binfmt_misc type binfmt_misc (RW) /dev/mapper/myvg-mylv on/tmp/wanghan type ext4 (RW)

Allocate MB of myvg space to mylv2:

[[email protected]_168_102_centos ~]# lvcreate -L 200M -n mylv2 /dev/myvg  Logical volume "mylv2" created[[email protected]_168_102_centos ~]# lvs  LV    VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv  myvg -wi-a--- 504.00m                                             mylv2 myvg -wi-a--- 200.00m                                           [[email protected]_168_102_centos ~]# vgs  VG   #PV #LV #SN Attr   VSize   VFree    myvg   2   2   0 wz--n- 808.00m 104.00m

Remove mylv2 logical volume:

Lvremove [/path/to/lv_device] Remove a specified logical volume

[[email protected]_168_102_centos ~]# lvremove /dev/myvg/mylv2Do you really want to remove active logical volume mylv2? [y/n]: y  Logical volume "mylv2" successfully removed[[email protected]_168_102_centos ~]# lvs  LV   VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv myvg -wi-a--- 504.00m

Extended volume group:

Prepare the physical volume to be added

[[email protected]_168_102_centos ~]# pvs  PV         VG   Fmt  Attr PSize   PFree    /dev/xvdc1 myvg lvm2 a--  504.00m      0   /dev/xvdc2 myvg lvm2 a--  304.00m 304.00m  /dev/xvdc3      lvm2 a--  604.01m 604.01m

Add a physical volume to a volume group

Vgextend vg_name/path/to/pv_device

[[email protected]_168_102_centos ~]# vgextend /dev/myvg /dev/xvdc3  Volume group "myvg" successfully extended[[email protected]_168_102_centos ~]# vgs  VG   #PV #LV #SN Attr   VSize VFree    myvg   3   1   0 wz--n- 1.38g 904.00m[[email protected]_168_102_centos ~]# pvs  PV         VG   Fmt  Attr PSize   PFree    /dev/xvdc1 myvg lvm2 a--  504.00m      0   /dev/xvdc2 myvg lvm2 a--  304.00m 304.00m  /dev/xvdc3 myvg lvm2 a--  600.00m 600.00m

Shrink a volume group

1. The total space of the physical volume to be removed must be smaller than the available space of the current VG.

2. Move the data on the PV to be removed to another PV

Pvmove can migrate data from a PV to a new PV.

[[email protected]_168_102_centos ~]# pvmove /dev/xvdc2  No data to move for myvg

3. Remove the PV to be specified from VG

VgreduceDelete a physical volume from a volume group

[[email protected]_168_102_centos ~]# vgreduce /dev/myvg /dev/xvdc2  Removed "/dev/xvdc2" from volume group "myvg"[[email protected]_168_102_centos ~]# pvs  PV         VG   Fmt  Attr PSize   PFree    /dev/xvdc1 myvg lvm2 a--  504.00m      0   /dev/xvdc2      lvm2 a--  305.93m 305.93m  /dev/xvdc3 myvg lvm2 a--  600.00m 600.00m[[email protected]_168_102_centos ~]# vgs  VG   #PV #LV #SN Attr   VSize VFree    myvg   2   1   0 wz--n- 1.08g 600.00m

Extended logical volume:

1. Make sure that the volume group of the logical volume to be extended has sufficient space.

2. Expand the physical boundary (physical boundary: the boundary for partitioning a disk)

Lvextend extended logical volume space

[[email protected]_168_102_centos ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/xvda1            7.9G  2.2G  5.3G  30% //dev/mapper/myvg-mylv                      489M   31M  433M   7% /tmp/wanghan[[email protected]_168_102_centos ~]# lvextend -L 700M /dev/myvg/mylv  Rounding size to boundary between physical extents: 704.00 MiB  Extending logical volume mylv to 704.00 MiB  Logical volume mylv successfully resized[[email protected]_168_102_centos ~]# df -lhFilesystem            Size  Used Avail Use% Mounted on/dev/xvda1            7.9G  2.2G  5.3G  30% //dev/mapper/myvg-mylv                      489M   31M  433M   7% /tmp/wanghan

3. Extend the logical boundary (logical boundary: We format partitions and create partition boundary after the file system)

Resize2fs: file system size adjustment tool

[[email protected]_168_102_centos ~]# resize2fs /dev/myvg/mylvresize2fs 1.41.12 (17-May-2010)Filesystem at /dev/myvg/mylv is mounted on /tmp/wanghan; on-line resizing requiredold desc_blocks = 2, new_desc_blocks = 3Performing an on-line resize of /dev/myvg/mylv to 720896 (1k) blocks.The filesystem on /dev/myvg/mylv is now 720896 blocks long.[[email protected]_168_102_centos ~]# df -lhFilesystem            Size  Used Avail Use% Mounted on/dev/xvda1            7.9G  2.2G  5.3G  30% //dev/mapper/myvg-mylv                      682M   31M  616M   5% /tmp/wanghan[[email protected]_168_102_centos ~]# lvs  LV   VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv myvg -wi-ao-- 704.00m

Reduce logical volume (risky, not recommended ):

1. unmount the volume and perform a forced detection.

[[email protected]_168_102_centos ~]# umount /dev/myvg/mylv[[email protected]_168_102_centos ~]# e2fsck -f /dev/myvg/mylve2fsck 1.41.12 (17-May-2010)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/myvg/mylv: 1307/180224 files (0.2% non-contiguous), 54323/720896 blocks

2. Reduce logical boundaries first

[[email protected]_168_102_centos ~]# resize2fs /dev/myvg/mylv 400Mresize2fs 1.41.12 (17-May-2010)Resizing the filesystem on /dev/myvg/mylv to 409600 (1k) blocks.The filesystem on /dev/myvg/mylv is now 409600 blocks long.

3. reduce physical boundaries

[[email protected]_168_102_centos ~]# lvreduce -L 400M /dev/myvg/mylv  WARNING: Reducing active logical volume to 400.00 MiB  THIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce mylv? [y/n]: y  Reducing logical volume mylv to 400.00 MiB  Logical volume mylv successfully resized[[email protected]_168_102_centos ~]# lvs  LV   VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv myvg -wi-a--- 400.00m

Snapshot volume:

1The lifecycle is the entire data duration. During this period, the data growth cannot exceed the snapshot volume size 2The Snapshot volume should be read-only. 3. It is in the same volume group as the original volume.
[[email protected]_168_102_centos ~]# lvcreate -s -L 50M -n snap-mylv -p r /dev/myvg/mylv  Rounding up size to full physical extent 56.00 MiB  Logical volume "snap-mylv" created[[email protected]_168_102_centos ~]# lvs  LV        VG   Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert  mylv      myvg owi-a-s- 400.00m                                             snap-mylv myvg sri-a-s-  56.00m      mylv     0.00
 

Summary of LVM logical volume Management

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.