Resizing the root device on Amazon EC2 - iteloo/formality-tools GitHub Wiki

Create new EBS volume

To resize the root device, create a copy your current volume. It is the easiest to do the following through Amazon's online dashboard:

  1. Stop the instance
  2. Detach the root volume (say, /dev/xvda)
  3. Create a snapshot of the root volume
  4. Create a new volume from the snapshot, with the desired storage size (say, /dev/xvdf)
  5. Attach both volumes back up
  6. Start the instance

Now we need to extend the partition on /dev/xvdf.

  1. Check that none of the partition on /dev/xvdf is mounted by running df -h. Otherwise, unmount it with umount /dev/xvdf1
  2. Run lsblk -l and remember the start of the partitions
  3. Run fdisk /dev/xvdf
  4. Delete current partition by entering d
  5. Create new partition by entering n
  6. Use the start number recorded in previous steps.
  7. And use the default value for end.
  8. Verify that things are set up correctly by entering p
  9. Write changed by entering n
  10. Re-mount the partition with mount /dev/xvdf (you might need to configure /etc/fstab)

Resize the filesystem

Finally, we need to resize the filesystem by running

resize2fs /dev/xvdf1

You can check that the system has been resized by running lsblk -l

Change boot device to /dev/xvdf1

In /etc/fstab change the device mounted at / to /dev/xvdf1 (See configure)

Configure /etc/fstab

In /etc/fstab, add a new line. You can either specify the device through labels, or hard-coded name or UUID. To use labels, put

LABEL=label_name

in /etc/fstab, and run

e2label /dev/xvdf1 label_name

to give /dev/xvdf1 the label.