Adding a New EBS Volume to an EC2 Amazon Linux Server

By Łukasz Kallas
Picture of the author
Published on
aws image

If you're running an application on an EC2 instance and need more storage space, adding a new Elastic Block Store (EBS) volume is a straightforward solution. In this post, we'll walk you through the steps to add, attach, and configure a new EBS volume to your Amazon Linux EC2 instance.

Step 1: Creating a New EBS Volume

  1. Log in to the AWS Management Console.
  2. Navigate to the EC2 Dashboard.
  3. In the left sidebar, click on Volumes under the Elastic Block Store section.
  4. Click on the Create Volume button.
  5. Configure the volume settings:
  • Size (GiB): Specify the size of the volume you need.
  • Availability Zone: Make sure this matches the Availability Zone of your EC2 instance (e.g., us-east-1a). Volumes can only be attached to instances in the same Availability Zone.
  • Volume Type: Choose the type of volume, such as General Purpose (SSD), Provisioned IOPS (SSD), or Magnetic (HDD).
  1. Click Create Volume.

Step 2: Attaching the EBS Volume to Your EC2 Instance

  1. Once the volume is created, select it from the list in the Volumes section.
  2. Click on the Actions dropdown and choose Attach Volume.
  3. In the Instance field, start typing the ID or name of your EC2 instance and select it from the list.
  4. Click Attach to link the volume to your EC2 instance.

Step 3: Preparing and Mounting the New EBS Volume

  1. Identify the new volume: Use the lsblk command to list all block devices. The new volume will typically show up as /dev/xvdf or similar.
lsblk
  1. Format the volume: If the new volume appears as /dev/xvdb, format it with the following command. Use the correct device name if it differs.
sudo mkfs -t xfs /dev/xvdb
  1. Create a mount point: Decide where you want to mount the new volume. For example, create a directory named data:
sudo mkdir /mnt/app
  1. Mount the volume: Mount the new EBS volume to the app directory:
sudo mount /dev/xvdb /mnt/app
  1. Verify the mount: Use the df -h command to check if the volume is mounted correctly.
df -h

Step 4: Configuring Automatic Mounting

To ensure that the volume is mounted automatically on reboot, add it to the /etc/fstab file.

  1. Check the UUID of EBS volume:
sudo blkid /dev/xvdb
  1. Open the /etc/fstab file in a text editor:
sudo nano /etc/fstab
  1. Add the following line at the end of the file:
UUID=THE_UUID_OF_DRIVE   /mnt/app   xfs   defaults,nofail   0   2
  1. Save and exit the editor.

Stay Tuned

Want to learn?
The best articles, links and news related to software development delivered once a week to your inbox.