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:
- Stop the instance
- Detach the root volume (say,
/dev/xvda
) - Create a snapshot of the root volume
- Create a new volume from the snapshot, with the desired storage size (say,
/dev/xvdf
) - Attach both volumes back up
- Start the instance
/dev/xvdf
.
Now we need to extend the partition on - Check that none of the partition on
/dev/xvdf
is mounted by runningdf -h
. Otherwise, unmount it withumount /dev/xvdf1
- Run
lsblk -l
and remember the start of the partitions - Run
fdisk /dev/xvdf
- Delete current partition by entering
d
- Create new partition by entering
n
- Use the start number recorded in previous steps.
- And use the default value for end.
- Verify that things are set up correctly by entering
p
- Write changed by entering
n
- 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
/dev/xvdf1
Change boot device to In /etc/fstab
change the device mounted at /
to /dev/xvdf1
(See configure)
/etc/fstab
Configure 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.