Expand EBS partition for EC2 instance

How to expand the root partition on a Redhat EC2 instance.

NOTE: If your partition has been created on the disk without any partition then just run:

resize2fs /dev/xvde

Check this by running lsblk. If the result is like on the below example follow the tutorial to expand the partition.

NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINTNAME
MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvde    202:64   0  40G  0 disk
└─xvde1 202:65   0  40G  0 part /
  1. Stop the instance
  2. Create a snapshot from the volume
  3. Create a new volume based on the snapshot increasing the size
  4. Check and remember the current’s volume mount point (i.e. /dev/sda1)
  5. Detach current volume
  6. Attach the recently created volume to the instance, setting the exact mount point
  7. Restart the instance
  8. Check you disks using either lsblk or df -ah
  9. In my case is /dev/xvde. Access the instance and run fdisk /dev/xvde
  10. Change display units to sectors by pressing u
  11. Press p to show current partitions. Take a note of the Start value.
  12. Press d to delete current partitions (if there are more than one, you have to delete one at a time) NOTE: Don’t worry data is not lost
  13. Press n to create a new partition
  14. Press p to set it as primary
  15. Check the first cylinder on location before deleting the partition (step 9) usually is 16, at this step I recommend to type the Start value from the previous command.
  16. Set the desired new space (if empty the whole space will be used). To use the whole space just press enter.
  17. Press a to make the new partition bootable
  18. Press 1 and w to write changes
  19. Reboot instance
  20. After the reboot increase the space disk using resize2fs /dev/xvde1.

The machines should pass all the amazon checks and boot with the partition already increased to the configured size.

solution found on stockoverflow and modified to pass all the health checks in EC2

Leave a Reply

Time limit is exhausted. Please reload the CAPTCHA.