AWS HDD Increase

How all this work :) You’ve resized HDD for your EC2 instance and nothing changed on it… You’ve tried doing resize2fs on your HDD and it hasn’t worked also. But you really want to have your HDD increased and all your data remained….

Here are the step to accomplish that:

1st step:

go to your’s server root console and do the following:

fdisk -l

this will output the info similar to the following

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

where /dev/xvda1 is the HDD we will be playing with in this example ;)

2nd step:

In the same console issue the following:

fdisk /dev/xvda

It will output the info similar to the following:
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’).

and will leave the prompt on following:

Command (m for help):

3rd step

In the Command (m for help): prompt

enter u and it will output the following:

Changing display/entry units to sectors

and will leave the prompt on following:

Command (m for help):

4th step:

In the Command (m for help): prompt

enter p and it will output the following:

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

and will leave the prompt on following:

Command (m for help):

!!!Write down the “Start” sector from the output!!!

5th step:

In the Command (m for help): prompt

enter d and it will output the following:

Selected partition 1

and will leave the prompt on following:

Command (m for help):

6th step:

In the Command (m for help): prompt

enter n and it will output the following:

Command action
 e extended
 p primary partition (1–4)

Follow it by pressing p and it will ask you the following:

Partition number (1–4):

enter 1 there and proceed to the next question

First sector (17–41943039, default 17):

Enter the number, you’ve wrote down in 4th step here and it will ask you the following question:

Last sector, +sectors or +size{K,M,G} (2048–41943039, default 41943039):

just press enter and it will show you the following:

Using default value 41943039

and will leave the prompt on following:

Command (m for help):

7th step:

In the Command (m for help): prompt

enter p and it will output the following:

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

Check that “end” partition has another number now ;) (as it was in 4th step)

and your prompt is again on following:

Command (m for help):

8th step:

In the Command (m for help): prompt

enter a and it will proceed to the following:

Partition number (1–4):

enter 1 there

and your prompt is again on following:

Command (m for help):

9th step:

In the Command (m for help): prompt

enter w and it will proceed to the following:

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.

Then you will leave the fdisk prompt and will be back to your root one.

Issue a reboot there by any means, that are comfortable for you and wait for the instance to be back up and login again :)

10th step:

After you’ve logged into issue the following command to check if everything is fine: df -h

It will output the following message

Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 2.0G 17G 11% /
tmpfs 15G 0 15G 0% /dev/shm

If you see a new HDD size — you are good to go now.

If not — simply issue resize2fs /dev/xvda1 and it will work now ;)

Always yours,

BlackCat

P.S. if you will ruin something — you are the only person to blame ;)