Adding a New EBS Volume to an EC2 Amazon Linux Server
By Łukasz Kallas
- Published on
Sharing
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
- Log in to the AWS Management Console.
- Navigate to the EC2 Dashboard.
- In the left sidebar, click on Volumes under the Elastic Block Store section.
- Click on the Create Volume button.
- 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).
- Click Create Volume.
Step 2: Attaching the EBS Volume to Your EC2 Instance
- Once the volume is created, select it from the list in the Volumes section.
- Click on the Actions dropdown and choose Attach Volume.
- In the Instance field, start typing the ID or name of your EC2 instance and select it from the list.
- Click Attach to link the volume to your EC2 instance.
Step 3: Preparing and Mounting the New EBS Volume
- 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
- 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
- Create a mount point: Decide where you want to mount the new volume. For example, create a directory named data:
sudo mkdir /mnt/app
- Mount the volume: Mount the new EBS volume to the app directory:
sudo mount /dev/xvdb /mnt/app
- 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.
- Check the UUID of EBS volume:
sudo blkid /dev/xvdb
- Open the /etc/fstab file in a text editor:
sudo nano /etc/fstab
- Add the following line at the end of the file:
UUID=THE_UUID_OF_DRIVE /mnt/app xfs defaults,nofail 0 2
- Save and exit the editor.