Resize Amazon EBS disks easily

Now, AWS has introduced Elastic Volumes for EBS, We still have to resize the volumes once they are modified. This tutorial will show 2 ways to increase/extend the volume after modification.

Part 1 - Using fdisk:

  1. Check disk size:

    1
    df -h

    Output:

    1
    2
    3
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/xvda1 6.0G 2.0G 3.7G 35% /
    tmpfs 15G 0 15G 0% /dev/shm
  2. Check disk cylinders/sectors:

    1
    fdisk -l

    Output:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Disk /dev/xvda: 21.5 GB, 21474836480 bytes
    97 heads, 17 sectors/track, 25435 cylinders
    Units = cylinders of 1649 * 512 = 844288 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0003b587

    Device Boot Start End Blocks Id System
    /dev/xvda1 * 2 7632 6291456 83 Linux
  3. Start fdisk command and follow the inside steps carefully:

    1
    fdisk /dev/xvda

    Output:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
    switch off the mode (command 'c') and change display units to
    sectors (command 'u').

    Command (m for help): u
    Changing display/entry units to sectors

    Command (m for help): p

    Disk /dev/xvda: 21.5 GB, 21474836480 bytes
    97 heads, 17 sectors/track, 25435 cylinders, total 41943040 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0003b587

    Device Boot Start End Blocks Id System
    /dev/xvda1 * 2048 12584959 6291456 83 Linux

    Command (m for help): d
    Selected partition 1

    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p
    Partition number (1-4): 1
    First sector (17-41943039, default 17): 2048
    Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): <<11>>
    Using default value 41943039

    Command (m for help): p

    Disk /dev/xvda: 21.5 GB, 21474836480 bytes
    97 heads, 17 sectors/track, 25435 cylinders, total 41943040 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0003b587

    Device Boot Start End Blocks Id System
    /dev/xvda1 2048 41943039 20970496 83 Linux

    Command (m for help): a
    Partition number (1-4): 1

    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.
  4. Reboot the machine for the changes to take place:

    1
    sleep 10; reboot
  5. Check for disk space after reboot:

    1
    df -h

    Output:

    1
    2
    3
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/xvda1 20G 2.0G 17G 11% /
    tmpfs 15G 0 15G 0% /dev/shm
  6. Cross check partition with resize2fs:

    1
    resize2fs /dev/xvda1

    Output:

    1
    2
    resize2fs 1.41.12 (17-May-2010)
    The filesystem is already 5242624 blocks long. Nothing to do!

Part 2 - Using growpart:

  1. Install EPEL:

    1
    yum install epel-release -y

    Check partitions:

    1
    lsblk

    Output:

    1
    2
    3
    NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    xvda 202:0 0 30G 0 disk
    └─xvda1 202:1 0 8G 0 part /
  2. Install growpart:

    1
    yum install cloud-utils-growpart -y
  3. Run the final command:

    1
    growpart /dev/xvda 1
  4. Reboot the instance for changes to take effect:

    1
    sleep 10; reboot
  5. After the reboot, Check for disk size:

    1
    lsblk

    Output:

    1
    2
    3
    NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    xvda 202:0 0 30G 0 disk
    └─xvda1 202:1 0 30G 0 part /

NOTES:

  • All the commands must be run as root.
  • Tested on CentOS box.
  • OP is not responsible for any damage, obviously !
  • In some cases, reboot is not required. Check before proceeding.
amazon web services aws instance ec2 centos ebs ebs volumes root