Daily Archives: January 18, 2011

Resizing a RHEL in Amazon EC2

Working on getting RHEL virtual appliances setup in the Amazon cloud this is how you resize the root filesystem after taking a snapshot of the original, creating a larger EBS from the snap, removing the old /dev/sda and attaching the EBS volume you just created.

  1. Verify that the device /dev/sda is where the / filesystem resides
    1. # df -h
  2. Verify that the device /dev/sda is larger than the usable space
    1. # fdisk -l
  3. Open fdisk with /dev/sda specified
    1. # fdisk /dev/sda
  4. Delete the current partition
    1. Command (m for help): delete
  5. Create a new primary partition
    1. Command (m for help): n
    2. p
    3. Partition number (1-4): 1
  6. Use the entire disk for the new partition
    1. “enter”
    2. “enter”
  7. Verify that the only thing that has changed on /dev/sda is the size
    1. Command (m for help): p
  8. Write out the new configuration
    1. Command (m for help): w
  9. Reboot
    1. reboot -n
  10. Extend the file system
    1. # resize2fs -p /dev/sda1
  11. Verify that the disk size and usable size are the same
    1. fdisk -l
  12. Enjoy!

I have had success using a similar method in Ubuntu, but then you have to be careful to leave the boot area and removing the swap partition first. Take a screenshot of fdisk -l /dev/sda before you start mucking around – you’ll be glad you did 🙂

–Nat