Extending amazon EBS with LVM partitions in practice

Launched an EC2 instance using IAM of CentOS-6.5-base-20150305 (ami-0e80db66) on AMAZON and configured EBS storage 200G. After entering the system, use df to view the storage space as follows:

[ec2-user@s1 ~]$ df -h

Filesystem                                    Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root   14G  2.4G   11G  19%    /

tmpfs 7.3G 0 7.3G 0% / dev / shm

 

/dev/xvda1                                   477M   73M  379M  17%  /boot

Obviously, only about 20G of space loaded by default in IAM is shown here, my EBS has 200G, and 180G is not mounted. What's going on? Use lsblk to see:

[ec2-user@s1 ~]$ lsblk

NAME                                                MAJ:MIN RM     SIZE     RO TYPE MOUNTPOINT

xvda                                                   202:0       0      200G       0    disk 

├─xvda1                                           202:1       0      500M       0    part    /boot

├─xvda2                                           202:2       0     15.5G       0    part 

     ├─VolGroup-lv_root (dm-0)       253:0       0     13.9G       0    lvm     /

    └─VolGroup-lv_swap (dm-1)     253:1       0     1.6G         0    lvm     [SWAP]

 

It can be seen that xvda is divided into 2 partitions. The first partition is 500M mounted with the /boot directory, and the second partition is an lvm partition with the / and swap directories mounted. Next, I will mount the 180G space to the / directory, that is, expand  VolGroup-lv_root to about 195G.

The first step, this is a root EBS, so the hard disk partition operation cannot be performed in the current instance. Disconnect this EBS from the current instance and mount it to another tool instance (I used a free Amazon Linux AMI 2015.09.1 ​​(HVM), SSD Volume Type - ami-60b6c60a instance). Note: Since the new instance has two root EBSs, you cannot restart the tool instance at this time, otherwise the root EBS cannot be loaded correctly. Then use the parted partition tool to partition the EBS to generate a new physical partition xvda3 with a size of the remaining 180G. The operation is as follows:

[ec2-user@s1~]$ sudo parted /dev/xvda

GNU Parted 2.1

use /dev/xvda

Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) unit s                                                           

(parted) print                                                            

Model: Xen Virtual Block Device (xvd)

Disk /dev/xvda: 419430400s

Sector size (logical/physical): 512B/512B

Partition Table: msdos

 

Number  Start      End         Size        Type     File system  标志

 1 2048s 1026047s 1024000s primary ext4 boot

 

 2      1026048s   33554431s   32528384s   primary               lvm

(parted) mkpart primary 33554432s 100%

(parted) print

Model: Xen Virtual Block Device (xvd)

Disk /dev/xvda: 419430400s

Sector size (logical/physical): 512B/512B

Partition Table: msdos

 

Number  Start      End         Size        Type     File system  标志

 1 2048s 1026047s 1024000s primary ext4 boot

 2      1026048s   33554431s   32528384s   primary               lvm

 

 3      33554432s  419430399s  385875968s  primary  ext4

(parted) quit

This creates a new physical partition, use lsblk again to view:

[ec2-user@s1 ~]$ lsblk

NAME                        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

xvda                        202:0    0  200G  0 disk 

├─xvda1                     202:1    0  500M  0 part /boot

├─xvda2                     202:2    0 15.5G  0 part 

│ ├─VolGroup-lv_root (dm-0) 253:0    0 13.9G  0 lvm  /

│ └─VolGroup-lv_swap (dm-1) 253:1    0  1.6G  0 lvm  [SWAP]

 

└─xvda3                     202:3    0  184G  0 part 

 

After the partition operation is completed, the EBS is disconnected and re-attached to the original instance.

 

The second step is to adjust the LVM partition. Enter the EC2 instance and check the LVM partition status:

[ec2-user@s1 ~]$ sudo vgdisplay

  --- Volume group ---

  VG Name               VolGroup

  System ID             

  Format lvm2

  Metadata Areas        1

  Metadata Sequence No  3

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  With LV 2

  Open LV               2

  Max PV                0

  Cur PV                1

  Act PV                1

  VG Size               15.51 GiB

  PE Size               4.00 MiB

  Total PE 3970

  Alloc PE / Size       3970 / 15.51 GiB

  Free  PE / Size       0 / 0   

 

  VG UUID               4431gC-stvB-LEil-fhM7-WT2F-y4DG-36Uf6w

 

[ec2-user@s1 ~]$ sudo lvdisplay

  --- Logical volume ---

  LV Path                /dev/VolGroup/lv_root

  LV Name                lv_root

  VG Name                VolGroup

  LV UUID                UTPDa9-4C6b-S0Yk-npmP-HMOM-ZGs0-TctA1e

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2015-03-05 19:27:09 +0900

  LV Status              available

  # open                 1

  LV Size                13.91 GiB

  Current LE             3561

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:0

   

  --- Logical volume ---

  LV Path                /dev/VolGroup/lv_swap

  LV Name                lv_swap

  VG Name                VolGroup

  LV UUID                vlCsmT-W0HL-q3wo-3tWf-jL2A-e2mB-C6zAGl

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2015-03-05 19:27:36 +0900

  LV Status              available

  # open                 1

  LV Size                1.60 GiB

  Current LE             409

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

 

  Block device           253:1

 

The current volume group VolGroup has 2 LVs, and the new partition xvda3 is converted into a physical volume:

pvcreate /dev/xvda3    /dev/xvda3

Expand the volume group and add the physical volume xvda3 to the existing volume group VolGroup

vgextend VolGroup /dev/xvda3

 

Increase logical volume lv_root size

 lvextend -L +180G /dev/VolGroup/lv_root

Look at the storage structure again:

[ec2-user@s1 ~]$ lsblk

NAME                        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT

xvda                        202:0    0   200G  0 disk 

├─xvda1                     202:1    0   500M  0 part /boot

├─xvda2                     202:2    0  15.5G  0 part 

│ ├─VolGroup-lv_root (dm-0) 253:0    0 197.9G  0 lvm  /

│ └─VolGroup-lv_swap (dm-1) 253:1    0   1.6G  0 lvm  [SWAP]

└─xvda3                     202:3    0   184G  0 part 

 

  └─VolGroup-lv_root (dm-0) 253:0    0 197.9G  0 lvm  /

 

The root directory has been increased to nearly 198G, successfully expanded.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326781073&siteId=291194637
LVM