Example:
- Starting: 8GB
- Goal: 12GB
- Partition name: xdva
- Go to EC2 Dashboard
- Select EBS Volumes
- Modify the Volume
- Insert new Volume size
Volums should be updated to 12GB, but partition is still 8GB.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 12G 0 disk
└─xvda1 202:1 0 8G 0 part /
Notice the space before 1. 1 is choosing the first partition of volume xvda.
$ sudo growpart /dev/xvda 1
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 8.0G 4G 4G 50% /
Now resize
$ sudo resize2fs /dev/xvda1
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 12.0G 4G 8G 33% /
- Go to EC2 Dashboard
- Select EBS Volumes
- Create Volume
- Recommended size of swap volume is 2 times of RAM
- Select availability zone same as your EC2 instance
- Attach volume to EC2
Should appear as /dev/xvdf
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 256G 0 disk
└─xvda1 202:1 0 256G 0 part /
xvdf 202:80 0 32G 0 disk
Setup swap
$ sudo mkswap /dev/xvdf
Enable swap
sudo swapon /dev/xvdf
Make the swap persistent
$ sudo nano /etc/fstab
/dev/xvdf none swap sw 0 0
Check swap
$ sudo swapon --show
NAME TYPE SIZE USED PRIO
/dev/xvdf partition 32G 279.9M -1
Create swap file (2GB)
$ sudo dd if=/dev/zero of=/swapfile bs=1G count=2
Update permissions
$ chmod 600 /swapfile
Set up a linux swap area
$ mkswap /swapfile
Make swap available
$ swapon /swapfile
Verify swap
$ swapon -s
Enable at boot
$ nano /etc/fstab
$ /swapfile swap swap defaults 0 0