0
votes

the steps showed in http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/console-modify.html are very complex.

Basically to resize EBS, I need to:

  1. modify volumn size
  2. expand partition

    2-1. detach root device from original EC2 and attach it to another EC2

    2-2. login another EC2: sudo umount / sudo parted /dev/xvda

    (parted) unit s

    (parted) print

    'Ignore' to all questions

    (parted) rm 1 ...... sudo e2fsck -f /dev/xvda1

    2-3.To return an expanded root partition to its original instance: Detach the expanded partition from its secondary instance Reattach the volume to the primary instance using the device name that you identified: /dev/xvda

    Start the primary instance.

    Terminate the second EC2

  3. Extend linux FS:

    sudo resize2fs /dev/xvda1

    df -h to see the result

is there easy and safe way to expand EBS size?

-------- update with more information

My EC2 is ubuntu 16.04

~$ lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  200G  0 disk 
└─xvda1 202:1    0  100G  0 part /

based on http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html and my lsblk output, I need to expand partition. then based on #5 and #6 of http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/expand-linux-partition.html, I need to detach then attache the partition from the original EC2. and then based on http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html, I need to first umount -d /dev/xvda, detach partition from original EC2, then attach it to a new EC2, expand partition using parted....

2

2 Answers

2
votes

If the EBS volume is your boot volume and you are using Amazon Linux, then you simply need to:

  • Modify the volume size (eg in the console)
  • Reboot the instance

Code that runs at startup will automatically expand the partition to use the new space available.

If you do not wish to reboot the instance, follow the directions on Extending a Linux File System after Resizing the Volume. These instructions do not list the need to unmount/reattach the volume.

1
votes

enter image description here

enter image description here

Now login through putty and follow the below mention steps - - -

   1. lsblk
   2. sudo file -s /dev/xvd*
   3. sudo growpart /dev/xvda 1
   4. sudo resize2fs /dev/xvda1
   5. df -h