DEV Community

Cover image for πŸ’½ AWS 112: Plug and Play - How to Attach an EBS Volume to an EC2 Instance
Hritik Raj
Hritik Raj

Posted on

πŸ’½ AWS 112: Plug and Play - How to Attach an EBS Volume to an EC2 Instance

AWS

🧱 Expanding Your Horizons: Attaching Extra Storage to Your Cloud Server

Hey Cloud Builders! πŸ‘‹

Welcome to Day 12 of the #100DaysOfCloud Challenge: Attach EBS Volume! We are continuing our systematic infrastructure migration with KodeKloud Engineer. Today, we are bridging the gap between compute and storage.

Our mission: Attach the existing EBS volume named nautilus-volume to the EC2 instance named nautilus-ec2 in the us-east-1 region using the device name /dev/sdb.


1. Introduction: Why Attach a Secondary Volume? πŸ’‘

Most EC2 instances come with a "Root Volume" where the Operating System lives. However, in professional DevOps, we often attach secondary volumes for specific data.

  • Data Separation: Keeping your application data or databases on a separate volume makes it easier to manage backups (snapshots) and move data between instances.
  • Performance: You can choose different volume types (like io2 for high-speed databases) for your data volume while keeping a standard gp3 for your OS.
  • Persistence: If the OS crashes and you need to delete the instance, the secondary data volume can be easily detached and saved!

Let's get this "virtual hard drive" plugged in! πŸ”Œ


2. Step-by-Step Guide: Attaching nautilus-volume to nautilus-ec2

We will use the EC2 Dashboard to perform this operation.

Step 2.1: Locate your EBS Volume

  1. Log in to the AWS Console and navigate to the EC2 Dashboard.

  1. In the left sidebar, scroll down to "Elastic Block Store" and click on "Volumes".

  1. Find the volume named nautilus-volume.

Pro-Tip: Ensure the volume state is "available" (meaning it's not currently attached to anything else).

Step 2.2: Attach to the Instance

  1. Select the checkbox for nautilus-volume.

  1. Click the "Actions" button and select "Attach volume".

  1. In the Instance search box, click and select your instance: nautilus-ec2.
  2. Device name: This is a crucial step for this task! Delete the default suggestion and type: /dev/sdb.
  3. Click "Attach volume".

Step 2.3: Verify the Attachment

  1. Refresh your Volumes list. The state of nautilus-volume should now be "in-use".
  2. Go to the EC2 Dashboard, select nautilus-ec2, and click the Storage tab. You should now see two volumes listed under Block devices: the root volume and your new /dev/sdb volume!

Success! Your server has now been upgraded with extra storage space. πŸŽ‰


3. Key Takeaways πŸ“

  • The AZ Rule: An EBS Volume must be in the exact same Availability Zone (e.g., us-east-1a) as the EC2 instance to be attached.
  • Device Names: In modern Linux instances, even if you specify /dev/sdb in AWS, the OS might see it as /dev/xvdb or /dev/nvme1n1.
  • Hot-Plugging: You can attach EBS volumes while the instance is running!

4. Common Mistakes to Avoid 🚫

  1. Availability Zone Mismatch: If you can't find your instance in the dropdown, 99% of the time it's because the volume and instance are in different AZs.
  2. Forgetting to Mount: Attaching the volume in AWS is like plugging in a USB drive. You still need to log into the Linux server to format the disk and mount it to a directory before you can use it!
  3. Device Name Confusion: Always double-check the requirements. Some legacy systems specifically look for certain device paths.

5. Conclusion + Call to Action! 🌟

You've successfully managed the storage lifecycle of your cloud resources! Learning to handle EBS volumes is a core skill for anyone managing databases or stateful applications in AWS.

How are you finding the 100 Days of Cloud Challenge so far? πŸ›‘οΈ

  • πŸ’¬ Let’s connect on LinkedIn: Are you a "GP3 by default" person or do you prefer other volume types? πŸ‘‰ Hritik Raj
  • ⭐ Support my journey on GitHub: Check out my repository for all 100 days of cloud tasks. πŸ‘‰ GitHub – 100 Days of Cloud

Top comments (0)