
To create a new CentOS Linux instance we had selected 100 GB of root volume. But when the system cam online it showed only 8GB of usable disk space. While trying to resize the root disk using resize2fs, we got the following message:
root@knowarth [~] # resize2fs /dev/xvda1
Therefore we followed the below steps and were able to resize the volume to its full size, that is, same as we have selected during instance creation:
1. Backup of Instance
We strongly recommended to take full backup (AMI) of your instance before doing any changes. Also create a snapshot of root disk.
2. Check Current Partitioning
[root@knowarth ~ ] # df -hFilesystem Size Used Avail Use% Mounted on /dev/xvda1 8G 3.7G 4.2G 45% /[root@knowarth ~ ] # fdisk -l Disk /dev/xvda: 108.4 GB, 108447924224 bytes 255 heads, 63 sectors/track, 13184 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xeb6cffbe
3. Enlarge Size of Volume
Now start with the disk re-partitioning using set of following commands. Execute all the commands carefully.
[root@knowarth ~ ] # fdisk /dev/xvda 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').
Now change the display units to sectors using u switch.
Command (m for help): u Changing display/entry units to sectors
Now print the partition table to check for disk details.
Command (m for help): pDisk /dev/xvda: 108.4 GB, 108447924224 bytes 255 heads, 63 sectors/track, 13184 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xeb6cffbe
Now delete the first partition using following command.
Command (m for help): d Selected partition 1
Now create a new partition using following commands. For the first sector enter 63 (as shows in above command output) and for last second just press enter to select all partition.
Command (m for help): n Command action e extended p primary partition (1 -4) p Partition number (1-4) : 1 First sector (63-104857599, default 63) : 63 Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): [PRESS ENTER] Using default value 104857599
Print the partition table again. You will see that new partition has occupied all disk space
Command (m for help): pDisk /dev/xvda: 108.4 GB, 108447924224 bytes 255 heads, 63 sectors/track, 13184 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xeb6cffbe
Now set the bootable flag on partition 1.
Command (m for help): a Partition number (1-4): 1
Write disk partition permanently and exit.
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. [root@knowarth ~ ] # reboot
It take some time to reboot the system.
Lets resize file system using resize2fs command. Remember that you are resizing filesystem not formatting.
[root@knowarth ~ ] # resize2fs /dev/xvda1 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 4 Performing an on-line resize of /dev/xvda1 to 13106944 (4k) blocks. The filesystem on /dev/xvda1 is now 13106944 blocks long.
4. Verify Extended Disk
At this point your root volume has been resized successfully. Now verify your disk if its has been resized properly.
[root@knowarth ~ ] # df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 100G 1.6G 93G 2% / tmpfs 1.8G 0 1.8G 0% /dev/shm