terça-feira, 28 de julho de 2015

AWS: Resize Root EBS Volume - Linux Partition

The goal from this document is to be clear and help you as quick as possible to achieve your goal. Further recommended reading is provided in the end of this tutorial - I am considering you have basic knowledge in AWS Console.


  1. Expanding your EBS Volume: by default you can't extend an EBS volume attached to an instance. To do so you need to perform the following steps:
    1. Stop your instance (take care to verify if the Stop behavior is STOP and not TERMINATE - otherwise you will lose your instance).

    2. Create a snapshot from the volume you want to expand (this can take a while).

    3. Right click the snapshot and select "Create Volume" choose the size you want the disk to have (consider current space + increase needed => plan for future). Important here is to make sure that you are creating the new EBS volume in the same availability zone from your instance, otherwise you will not be able to attach the new volume to the instance.

    4. After Volume is ready:

      1. Detach the former volume from your instance (the one you are "increasing")

      2. Attach the new volume, make sure you type /dev/sda1 in the Device Name (if this is the root volume), otherwise your instance will not boot.

    5. Start the instance with the newly created expanded EBS volume. 


  2. Expanding your Linux Root partition [Tested on CentOS]: 

    1. When you type df -h you will see that the new space is not reclaimed. 
    2. Get the partition name from df -h and the volume name, for example, /dev/xvda1 mounted as / and /dev/xvda for your device.
    3. Run fdisk -l /dev/xvda to list the partitions, probably the data partition you want to expand is the last one (hope to be). This command will also show the size from /dev/xvda which must reflect your expanded disk size. 
    4. Take note from the Start and End sectors from your partitions, specially the one you want to extend. 
    5. Delete your partition (the one you want to extend - no data will be lost but remember, you have one snapshot and the original volume is untouched):
    6. fdisk /dev/xvda
      Command (m for help): d
      Selected partition 1



      Command (m for help): n


    7. Now you deleted your partition, time to recreate it. Usually keeping the defaults is OK, check the previously noted Start and End cylinders.   
    8. Command (m for help): n
      Command action
      e extended
      p primary partition (1-4)
      p
      Partition number (1-4): 1
      First cylinder (1-634, default 1):
      Using default value 1
      Last cylinder or +size or +sizeM or +sizeK (1-634, default 634):
      Using default value 634
      Command (m for help): d

    9. If your partition had a "*" present in the Boot column, we have to add it with the command, change the partition number to your situation:
    10. Command (m for help): a
      Partition number (1-4): 1

    11. Now is time to write down the changes:
    12. Command (m for help): w
      The partition table has been altered!

    13. Reboot your instance. After reboot the partition will have the new space but it will not be allocated yet, so a df -h will still show the old values.

    14. After reboot, type the following command to extend your online partition to its full size (the size we gave with fdisk), here you will use the partition name, not the disk, so, instead of using /dev/xvda (our example) as you did for fdisk, here we use the partition number /dev/xvda1:
    15. resize2fs /dev/xvda1

  3. Additional Resources:
    1. http://possiblelossofprecision.net/?p=228
    2. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-expand-volume.html
    3. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html
    4. https://www.howtoforge.com/linux_resizing_ext3_partitions


Nenhum comentário:

Postar um comentário