Linux LVM creation and expansion and reduction

Source: Internet
Author: User

Tag:manager    management tool    linux   

LVM Logical Volume 1, LVM logical volume mechanism LVM logical Volume (Logical volumes manager) is a logical integration of multiple partitions or physical hard disks, dividing different logical partitions from this whole The logical partition can be enlarged and reduced as needed the entire creation of the logical partitioning process, in turn, the creation of PV, VG, LV;PV partition or physical hard disk, and PE as the basic unit; The VG is a whole LV composed of one or more PV partitions from the VG volume group, which can be formatted to create a file system; 2 , LVM creation and management since Linux supports LVM, LVM creation and management are essential, and LVM management tools include PV, VG, LV, scan, create, delete, expand, display, reduce, and PE size settings ; function PVVGLV Scan pvscanvgscanlvscan Create pvcreatevgcreatelvcreate display pvdisplayvgdisplaylvdisplay Delete pvremovevgremovelvremove extension--vgexten Dlvextend reduced--vgreducelvreduce Common syntax: pvcreate physical volume or partition name Vgcreate  –s  pe size   Volume group name   Physical volume Lvcreate  -l LV size –n LV name  VG name lvcreate  -l PE number –n LV name  VG name Lvextend–l + size  LV logical partition Lvreduce RESIZE2FS  LV partition size Note Matter: If not a single hard disk but multiple partitions to build PV, must be partitioned into 8e format; 3, the instance now has 4 50G hard disk, the SAB, SDC, SDD as a VG, and then divided into three 40G ext4 partition, in the creation of a 250M swap partition; 3.1. Create physical volume [[email protected] ~]# pvcreate/dev/sdb  /dev/sdc/dev/sdd  physical volume "/dev/sdb" Successfully created  physical volume "/DEV/SDC" successfully created  physical volume "/DEV/SDD" successfully created[[email Protected] ~] #查看pv [[email protected] ~]# pvdisplay  ---physical volume---  "/dev/sdb" is a new physical V Olume of "50.00 GiB"  ---NEW physical volume--- pv Name              /dev /sdb  VG Name                PV Size           &NBSP ;   50.00 GiB  allocatable           NO  pe Size               0    total PE              0  free PE               0  allocated PE          0  PV UUID       & nbsp       t6xa0f-naxl-0i8f-xgj0-eojd-pbr0-nnauuu     "/DEV/SDC" is a new physical volume of "50.00 GiB  ---NEW physical volume--- PV name              /DEV/SDC  VG name     &NBsp          PV Size               50.00 GiB  allocatable &NB Sp         NO  pe Size               0    total PE &nbs P            0  free PE               0  allocate D PE          0  PV UUID               AKREKZ-L5RT-UDZR-4 Iy6-z2bh-vwi0-qexqza     "/DEV/SDD" is a new physical volume of "50.00 GiB"  ---new physical volume---&NB Sp PV name              /DEV/SDD  VG Name                PV Size               50.00 GiB  allocatable       &NB Sp   NO  pe Size               0    total PE       &NBS P &nBsp    0  free pe               0  allocated PE       &N Bsp  0  PV UUID               vyhzts-vm5b-j40c-mhe9-9a3r-wu7b-tbggy33.2, creating volume groups and viewing [[email protected] ~]# vgcreate woonvg/dev/sdb/dev/sdc/dev/sdd  volume Group "WOONVG" successfully created &N Bsp VG Name               WOONVG  system ID              format                LVM2  metadata areas        3  metadata Sequence No  1  vg Access             Read/write  VG Status & nbsp           resizable  max LV                0  c ur lv                0  open LV             &NB Sp 0 max PV                0  cur PV           &NBS P    3  act PV                3  VG Size       &N Bsp       149.99 GiB  pe Size               4.00 MiB  total PE &NB Sp            38397  alloc pe/size       0/0    free  pe /Size       38397/149.99 GiB  vg UUID               TGMW2T-5IL0 -fuev-umqp-rtst-ootc-o4alna; default PE size 4m3.3, create LV and view green partition [[email protected] ~]# lvcreate-l 40g-n  woon_lv1 WOONVG  logical Volume "Woon_lv1" created[[email protected] ~]# lvcreate-l 10240  -n  woon_lv2 woonv G  logical Volume "Woon_lv2" created[[email protected] ~]# lvcreate-l 10240  -n  woon_lv3 woonvg &nbs P Logical Volume "Woon_Lv3 "created[[email protected] ~]# lvdisplay  ---Logical volume--- lv Path         & nbsp      /DEV/WOONVG/WOON_LV1  lv Name                WOON_LV1 &NB Sp VG Name                WOONVG  lv UUID           &NB Sp    ZEOMDA-TAP0-OENX-YMI6-KYUA-IJPR-IWDZGD  lv Write Access        read/write   LV Creation Host, Time Woon, 2015-02-09 23:03:20 +0800  lv Status              ava Ilable  # Open                 0  lv Size         &N Bsp      40.00 GiB  current LE             10240  segments   &NBSP ;           1  allocation             inherit  read ahead s Ectors &nbsp   Auto  -currently set to      block device           253:2    ---Logical volume--- lv Path                /DEV/WOONVG/WOON_LV2 &NB SP;LV name                WOON_LV2  VG name         &NBSP ;      WOONVG  lv UUID                10uxvd-2efm-gzuo-fq2z-0guq -1EW2-G3HLS7  lv Write Access        read/write  lv Creation host, Time Woon, 2015-02-09 23: 04:32 +0800  lv Status              available  # open       &N Bsp         0  lv Size                40.00 GiB  current LE             10240  segments               1 &nbs P AllocatioN             inherit  read ahead sectors     Auto  -currently set to & nbsp    block device           253:3    ---Logical volume--- lv Path & nbsp              /dev/woonvg/woon_lv3  lv Name           &NBS P    woon_lv3  VG Name                WOONVG  lv UUID   &NB Sp            DAHX1R-6HQE-W8KG-8PXR-ZZEQ-0LCP-ULONPC  lv Write Access     &NBSP ;  read/write  LV Creation Host, Time Woon, 2015-02-09 23:04:40 +0800  lv Status              available  # open                 0  LV Size                40.00 GiB  current LE             10240 &nbSp Segments               1  allocation             INH Erit  read ahead sectors     Auto  -currently set to         Block device &NB Sp         253:43.4, format lv logical volume [[email protected] ~]# mkfs.ext4/dev/woonvg/woon_lv1[[email  Protected] ~]# mkfs.ext4/dev/woonvg/woon_lv2[[email protected] ~]# mkfs.ext4/dev/woonvg/woon_lv33.4.1, formatted and mounted to /OPT/WOON_LV1, Woon_lv2, Woon_lv3 [[email protected] ~]# mount/dev/woonvg/woon_lv1/opt/woon_lv1[[email  Protected] ~]# mount/dev/woonvg/woon_lv2/opt/woon_lv2[[email protected] ~]# mount/dev/woonvg/woon_lv3/opt/ Woon_lv3  3.4.2, viewing mount      [[email protected] woon_lv1]# Mount | Tail-n 3/dev/mapper/woonvg-woon_lv1 on/opt/woon_lv1 type EXT4 (rw)/dev/mapper/woonvg-woon_lv2 ON/OPT/WOON_LV2 type ext 4 (rw)/dev/mapper/woonvg-woon_lv3 On/opt/woon_lv3 type EXT4 (rw) [[Email&nbsP;protected] woon_lv1]#       3.4.3, split 250M swap partition and Mount [[email protected] woon_lv1]# lvcreate-l 250M -N woon_swap woonvg  rounding up size to full physical extent 252.00 MiB  logical volume "Woon_swap" created found at this time Clearly points is 250M, but after the execution of the command is really 252M, after the investigation is due to the size of the PE, because the PE is the basic unit of PV, resulting in 250M can not be accurately divided; in the current environment if you want to implement it must delete all LV, VG, adjust the PE size of 1M can To solve this problem, you only need to use the following command when you create the VG: Vgcreate–s 1M woonvg/dev/sd[b-d]4, resizing partition size 4.1, extended partition expands woon_lv1 to 50g[[email protected] woon_lv1]# lvextend-l 50g/dev/woonvg/woon_lv1size of Logical Volume WOONVG/WOON_LV1 changed from 40.00 GiB (10240 extent s) to 50.00 GiB (12800 extents).  logical Volume WOON_LV1 successfully resized the partition is now extended to 50G, but the kernel is not aware, so be notified of the kernel Yongda resize2fs instructions [[email protected ] woon_lv1]# resize2fs/dev/woonvg/woon_lv1[[email protected] woon_lv1]# df-hfilesystem            size  used Avail use% mounted on/dev/mapper/vg_woon-lv_root           &N Bsp          8.3g  4.0g  4.0g  51%/tmpfs                 504M  224k & nbsp;503m   1%/dev/shm/dev/sda1             477M   27M  426m   6%/boot /DEV/SDF1             100G   13G   88G  13%/opt/ntfs1/dev/sde1             459G   70M  435g   1%/opt/gpt1/dev/sr0           &NB Sp  3.8g  3.8g     0 100%/media/centos_6.6_final/dev/mapper/woonvg-woon_lv1                       50G   52M   47G   1%/opt/woon_lv1/dev/mapper/woonv G-woon_lv2                       40G   48M   38G   1 %/opt/woon_lv2/dev/mapper/woonvg-woon_lv3                       40 G   48M   38G &NBSp 1%/opt/woon_lv34.2, reduce the reduction of a partition partition can not be directly reduced online, you should unmount the partition, then reduce the file system, then reduce the partition size, and finally re-mount, such as reducing the WOON_LV2 to 30G, do not damage the file system; [email  protected] woon_lv1]# umount/dev/woonvg/woon_lv2[[email protected] woon_lv1]# e2fsck-f/dev/woonvg/woon_ Lv2[[email protected] woon_lv1]# resize2fs/dev/woonvg/woon_lv2 30g[[email protected] woon_lv1]# lvreduce- L 30g/dev/woonvg/woon_lv2  warning:reducing Active Logical Volume to 30.00 GiB  this may DESTROY YOUR DATA (fi Lesystem etc.) Does really want to reduce woon_lv2? [y/n]: Y  size of Logical Volume WOONVG/WOON_LV2 changed from 40.00 Gib (10240 extents) to 30.00 GIB (7680 extents).  logical volume Woon_lv2 successfully resized[[email protected] woon_lv1]# mount/dev/woonvg/woon_lv2/opt/ Woon_lv2[[email protected] woon_lv1]# df-hfilesystem            size  used Avail Use% mounted on/dev/mapper/vg_woon-lv_root                     &NBSP8.3G  4.0g  4.0g  51%/tmpfs                 504M  224k &nbsp 503M   1%/dev/shm/dev/sda1             477M   27M  426m   6%/boot/dev /SDF1             100G   13G   88G  13%/opt/ntfs1/dev/sde1     &NB Sp       459G   70M  435g   1%/opt/gpt1/dev/sr0             &NBS p;3.8g  3.8g     0 100%/media/centos_6.6_final/dev/mapper/woonvg-woon_lv1         &NB Sp             50G   52M   47G   1%/opt/woon_lv1/dev/mapper/woonvg-woon_lv3 &NB Sp                     40G   48M   38G   1%/opt/woon_lv3/de V/mapper/woonvg-woon_lv2                       30G   44M &nbsp ; 28G  1%/opt/woon_lv2

This article is from the "Woonlinux" blog, make sure to keep this source http://woonlii.blog.51cto.com/9869103/1613182

Linux LVM creation and expansion and reduction

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.