Skip to content

Instantly share code, notes, and snippets.

@ThomasTJdev
Last active March 2, 2019 06:41
Show Gist options
  • Save ThomasTJdev/f3f92e5c634d1e427b1920f8f9d43beb to your computer and use it in GitHub Desktop.
Save ThomasTJdev/f3f92e5c634d1e427b1920f8f9d43beb to your computer and use it in GitHub Desktop.

Resize filesystem (extend partition)

Example:

  • Starting: 8GB
  • Goal: 12GB
  • Partition name: xdva

Update volume size

  1. Go to EC2 Dashboard
  2. Select EBS Volumes
  3. Modify the Volume
  4. Insert new Volume size

Check partition 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 /

Grow partition

Notice the space before 1. 1 is choosing the first partition of volume xvda.

$ sudo growpart /dev/xvda 1

Resize filesystem

$ 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% /

SWAP

EBS

Add a volume

  1. Go to EC2 Dashboard
  2. Select EBS Volumes
  3. Create Volume
  4. Recommended size of swap volume is 2 times of RAM
  5. Select availability zone same as your EC2 instance
  6. Attach volume to EC2

Setup volumn as swap space

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

SWAP file

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment