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:
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 /
- Stop the instance
- Create a snapshot from the volume
- Create a new volume based on the snapshot increasing the size
- Check and remember the current’s volume mount point (i.e.
- Detach current volume
- Attach the recently created volume to the instance, setting the exact mount point
- Restart the instance
- Check you disks using either lsblk or df -ah
- In my case is /dev/xvde. Access the instance and run
- Change display units to sectors by pressing u
- Press p to show current partitions. Take a note of the Start value.
- 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
- Press n to create a new partition
- Press p to set it as primary
- 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.
- Set the desired new space (if empty the whole space will be used). To use the whole space just press enter.
- Press a to make the new partition bootable
- Press 1 and w to write changes
- Reboot instance
- 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