AWS CentOS Amazon Instance resize Root Partition Live Running

Below are my steps for re-sizing the / partition for an AWS CentOS 6.5 x64 Instance.

Most all of the AWS instances start off as 15GB or smaller / partitions.  Being able to resize to take advantage of a larger disk is great.

Please use these directions at your own risk!  Keep backups or create a snapshot before you start to ensure if you do something wrong you can recover, reset, or back out.

Here are the steps I followed, and below is how I ran them each:

  1. As root, go into `fdisk /dev/xvda` and create a new primary partition n for new then p for primary 3 for 3rd partition number and enter for size
  2. t for tag it (t) as type 0x8e and then w for write
  3. Write your changes and exit fdisk
  4. Reboot = you may not be able to use the new partition until you reboot
  5. When the reboot completes, as root again,
  6. Run pvcreate on your new partition to create the physical partition
  7. Use vgextend to add the new PV to your existing Volume Group
  8. Now you have free space available in the VG
  9. Run lvextend to add some space to /dev/mapper/VolGroup-lv_root = this adds your new space to the logical volume
  10. Run `resize2fs /dev/mapper/VolGroup-lv_root`

**************************

First Verify you have the extra space by looking at the physical drives:

lsblk = will show you the raw disk space.

Then create a new partition from the available free space on the drive
[root@ip-172-31-36-49 ~]# fdisk /dev/xvdf
n
p
3
enter for default size = remaining amount

t 0x8e
w = write it out and exit
reboot server

[root@ip-172-31-36-49 ~]# pvcreate /dev/xvdf3
Physical volume “/dev/xvdf3” successfully created

pvdisplay = show physical volumes verify you have the remaining disk space

[root@ip-172-31-36-49 ~]# vgdisplay
— Volume group —
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 14.51 GiB
PE Size 4.00 MiB
Total PE 3714
Alloc PE / Size 3714 / 14.51 GiB
Free PE / Size 0 / 0
VG UUID lvi8Kt-MMja-nTvI-terh-7ljb-ImyV-SScwRk

[root@ip-172-31-36-49 ~]# vgextend VolGroup /dev/xvdf3
Volume group “VolGroup” successfully extended

[root@ip-172-31-36-49 ~]# vgdisplay VolGroup
— Volume group —
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 89.02 GiB
PE Size 4.00 MiB
Total PE 22788
Alloc PE / Size 3714 / 14.51 GiB
Free PE / Size 19074 / 74.51 GiB
VG UUID lvi8Kt-MMja-nTvI-terh-7ljb-ImyV-SScwRk

[root@ip-172-31-36-49 ~]# lvextend -l +100%FREE /dev/mapper/VolGroup-lv_root
Extending logical volume lv_root to 88.22 GiB
Logical volume lv_root successfully resized

lvdisplay = verify the lv size is bigger now

[root@ip-172-31-36-49 ~]# resize2fs /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 6
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 23126016 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 23126016 blocks long.

vgdisplay = verify the VolGroup is now bigger

[root@ip-172-31-36-49 ~]# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
87G 1.4G 82G 2% /
[root@ip-172-31-36-49 ~]#

CentOS-6.5-Base-HVM-SR-IOV-1/30/2015 – ami-09f7d239
[Copied ami-e4b7f18c from us-east-1] CentOS-6.5-Base-HVM-SR-IOV-1/30/2015
Root device type: ebs Virtualization type: hvm

 

Thanks to the following resources:

post by Trevor H @ https://www.centos.org/forums/viewtopic.php?f=13&t=44616

PVCreate @ http://linux.die.net/man/8/pvcreate

Display Volume Groups  @ redhat.com

Grow Logical Volumes  @ centos.org

Managing Partitions at How To Geek @ howtogeek.com

Display Physical Volumes @ Redhat.com