How to extend Ubuntu file system after resizing AWS EBS Volume

Sometimes, imply increase the size of an EBS volume in EC2 Management console doesn’t expand the actual storage size in Ubuntu system. You need to further configure your OS to apply the size change.

Check if you need to resize the partition and the filesystem

lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  21G  0 disk 
└─xvda1 202:1    0  20G  0 part /

Run lsblk command to list the attached devices if the partition size are not equal, you need to resize the partition

df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            996M   12K  996M   1% /dev
tmpfs           201M  340K  200M   1% /run
/dev/xvda1       20G   11G  8.2G  57% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none           1001M     0 1001M   0% /run/shm
none            100M     0  100M   0% /run/user

Use df -h command to see if the filesystem need the resizing

Resizing the partition

sudo growpart /dev/xvda 1
CHANGED: partition=1 start=16065 old: size=41913585 end=41929650 new: size=44018100,end=44034165

lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  21G  0 disk 
└─xvda1 202:1    0  21G  0 part /

Use sudo growpart command to expand the partition. Verify the result by running lsblk command.

sudo resize2fs /dev/xvda1
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/xvda1 is now 5502262 blocks long.

df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            996M   12K  996M   1% /dev
tmpfs           201M  340K  200M   1% /run
/dev/xvda1       21G   11G  9.1G  54% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none           1001M     0 1001M   0% /run/shm
none            100M     0  100M   0% /run/user

Use sudo resize2fs command to expand the filesystem. Verify the result by running df -h command.

Resources: Extending a Linux File System after Resizing the Volume

When to upgrade T2 instances on AWS – CPU usage

AWS currently offers five levels of T2, Burstable Performance, instances on EC2. T2 instances “provide a base level of CPU performance with the ability to burst above the baseline.”

What’s not obvious from the general documentation page is that what’s the easy indicator to determine if you need to upgrade your T2 instance to the next level.

T2 Instance CPU Baseline Performance

What I found to be the best/quickest way to figure out when to upgrade T2 instance is to look at CPU Utilization (Percent) chart on the monitoring section for the instance. You need to compare the average usage of the CPU and the baseline of the T2 instance (above the baseline means the server is in the “burst” mode which uses the extra CPU credits).

Here are the baseline of each T2 instances:

Instance TypeCPU Baseline Performance
t2.nano5%
t2.micro10%
t2.small20%
t2.medium40%
t2.large60%

CPU Credit Usage and CPU Credit Balance

CPU credit usage chart and CPU credit balance chart are also good indicators. However, when the credit usage is too rapid, you might not be able to catch the issue in time to resolve the performance issue. The decrease in the credit balance is recorded only AFTER the server is performing beyond baseline performance. In other words, it’s not a good PREVENTATIVE indicator.

But Beware…

This is a simple way to measure the performance of the server reflected on CPU usage. There are other resources that causing the issue on your server(s). The most common issue I experience is the depletion of available memory. This happens if I am running a multiple servers (such as LAMP) under one instance. While CPU usage is within a normal range, not too uncommon to run out of available memory and your application stop running properly. I find that t2.nano instance and t2.micro instance aren’t sufficient to run a LAMP in most cases.

Resources: New Low Cost EC2 Instances with Burstable Performance
Resources: EC2 Update – T2.Nano Instances Now Available
Resources: Burstable Performance Instances

Make PHP Mail() work in AWS EC2 – Ubuntu 14.04

AWS IP addresses can be problematic for setting an email server in an EC2 instance…even with right setup email sent from the IP address can be marked as spam.

So what to do with setting up SMTP for your web applications? One alternative is to use AWS SES service. I decided not to use SES, however, because 1) each email address or domain needs to be approved and 2) there is cost associated with number of email sent out. These aren’t too bad of the restrictions but I wanted something that JUST work without configuring every time I build a website.

I went with MSMTP to use my gmail account to send email message by default. I can also overwrite the smtp setting per linux account. So if I were to host sites that are not mine, they can use their own smtp setup.
Continue reading “Make PHP Mail() work in AWS EC2 – Ubuntu 14.04”