9

Extend EBS boot disk on AWS without an instance reboot

 2 years ago
source link: https://computingforgeeks.com/how-to-extend-aws-ec2-instance-boot-file-system-without-rebooting/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

On AWS, you can increase EBS volume size, adjust performance, or change the volume type while the volume is in use. The change should guarantee zero downtime, and without any effect on the application operations.

In this example, I’ll extend the boot disk of a CentOS 7 server from 8 GB to 20 GB

Step 1: Resize boot Volume on EBS

Login to AWS console and navigate to:

EBS > Volumes > Right Click on volume name > Modify Volume

extend ebs volume min

Change the size from 8 to 20 or whichever value you want to grow to, then click “Modify

extend ebs volume 02 min

Confirm that you want to grow disk.

extend ebs modify volume 01 min

A successful message should look like below

extend ebs modify volume 02 min

Step 2: Login to the server via ssh and extend / partition

SSH into your EC2 instance and check block device current size.

# lsblk 
NAME          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
xvda          202:0    0    20G  0 disk 
└─xvda1       202:1    0    8G   0 part /

You can see /dev/xvda1 is still 8 GB in size. We need to resize it to 20 GB using the growpartcommand.

Install cloud utils

On Ubuntu / Debian system, run

sudo apt install -y cloud-guest-utils

For CentOS server, run

sudo yum -y install cloud-utils-growpart

For those new to growpart, it is Linux command line tool used to extend a partition in a partition table to fill available space.

Help page can be viewed by passing -h argument.

# growpart -h
growpart disk partition
   rewrite partition table so that partition takes up all the space it can
   options:
    -h | --help       print Usage and exit
         --fudge F    if part could be resized, but change would be
                      less than 'F' bytes, do not resize (default: 1048576)
    -N | --dry-run    only report what would be done, show new 'sfdisk -d'
    -v | --verbose    increase verbosity / debug
    -u | --update  R  update the the kernel partition table info after growing
                      this requires kernel support and 'partx --update'
                      R is one of:
                       - 'auto'  : [default] update partition if possible
                       - 'force' : try despite sanity checks (fail on failure)
                       - 'off'   : do not attempt
                       - 'on'    : fail if sanity checks indicate no support

   Example:
    - growpart /dev/sda 1
      Resize partition 1 on /dev/sda

In our case, we will run

sudo growpart /dev/xvda 1

New disk size should be 20 GB

# lsblk
NAME          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
xvda          202:0    0    20G  0 disk
└─xvda1       202:1    0    20G  0 part /

Step 3: Resize `/` partition to fill all space

The last step is to resize the file system to grow all the way to fill added space

For ext4 file system, use resize2fs

sudo resize2fs /dev/xvda1

If your filesystem is xfs, an XFS file system may be grown while mounted using the xfs_growfscommand:

sudo xfs_growfs /

Both of these commands will grow the file system to the maximum size supported by the device.

Confirm new size using df -h

# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/xvda1              20G  8.2G   12G  41% /

Congratulations!, you managed to extend a mounted / partition without any downtime.

Recommended Video courses to Learn AWS Cloud

Other disk management articles available are:

How to resize an ext2/3/4 and XFS root partition without LVM

How to extend root filesystem using LVM on Linux.

How to extend/increase KVM Virtual Machine (VM) disk size

Other AWS articles available in our blog are:

Create AWS S3 Upload and List Objects Policy without Delete Action

How to Configure Cpanel Backups to S3 Object Store

How to Install and Use AWS CLI on Linux – Ubuntu / Debian / CentOS

How to Reset RDS Master User Password on AWS


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK