# The Ultimate AWS EBS Workflow: EC2 Integration

## 📝 Abstract

In this guide, I demonstrate the **complete lifecycle of working with AWS EC2 and EBS volumes** starting from launching an EC2 instance and attaching a new EBS volume, to **preserving data** by disabling *delete-on-termination*.

You’ll also learn how to:

* **Recover EBS data** after EC2 termination
    
* **Migrate EBS volumes across Availability Zones** using snapshots
    
* **Copy snapshots across AWS Regions** to restore data remotely
    

This end-to-end workflow ensures **data durability**, **flexibility**, and **disaster recovery readiness** for modern cloud infrastructure setups.

### ✅ Step 1: Launch an EC2 Instance

To begin, launch a new EC2 instance:

* Go to the **EC2 Dashboard** in AWS Management Console.
    
* Click on **“Launch Instance”**.
    
* Select an appropriate **AMI** (Amazon Machine Image), such as Ubuntu or Amazon Linux.
    
* Choose an **instance type** (e.g., t2.micro for testing or t3.medium for production).
    
* In the **network section**, you can **keep the default VPC and Subnet** settings — AWS will automatically manage networking unless you have a custom setup.
    
* Continue with key pair, storage, and security group settings.
    

Once launched, the EC2 instance will automatically have a **root EBS volume** attached.

### 🔒 Understanding the “Delete on Termination” Setting in EC2

When launching an EC2 instance, AWS automatically attaches a **root EBS volume** to store the operating system and configuration files. By default, this root volume is **deleted** when the instance is terminated — but you can control this behavior.

#### 📌 Why it's important to uncheck “Delete on Termination”:

* 🔐 **Preserve critical data:** Prevents the root EBS volume from being deleted, even if the EC2 instance is terminated.
    
* 🔄 **Easily recover configuration:** Retain OS setup, logs, and installed packages for later use or migration.
    
* 💼 **Safe for production use:** Especially helpful in staging or production environments where instance termination is temporary or planned.
    
* ☁️ **Avoid accidental data loss:** Ensures your volume (and its data) remains available in the **EBS → Volumes** section after termination.
    
* 🔧 **Attach to a new EC2:** The preserved volume can be re-attached to any EC2 instance in the **same Availability Zone** for instant recovery.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752029929308/7b19e150-5e37-42ad-a96c-d492c7b6f700.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752029942629/0f547661-6105-431d-8fcb-0bb979e12354.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752029686849/5419eb8d-7490-436d-a4b9-ce2acfc302ad.png align="center")

> As shown below, AWS automatically creates and attaches a root EBS volume when you launch an EC2 instance.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752029752332/06ac26d6-72ef-4b9e-b9d9-3eaa45b99828.png align="center")

### ✅ Step 2: Create and Attach a New EBS Volume to Your EC2 Instance

After launching your EC2 instance, you may need extra storage. For that, you can create a new EBS volume and attach it.

#### 🔧 Steps to Create:

* Go to **EC2 → Elastic Block Store → Volumes → Create Volume**
    
* Select **Volume Type**, **Size**, and most importantly, choose the **same Availability Zone** as your EC2 instance
    
    > 📌 EBS volumes can only be attached to EC2 instances in the **same Availability Zone**
    

#### 🔗 Steps to Attach:

* After creation, select the volume → Click **Actions → Attach Volume**
    
* Choose your EC2 instance and confirm the **device name** (e.g., `/dev/xvdf`)
    
* Click **Attach** — your volume is now connected to the instance
    

> ✅ You’ll now need to format and mount the volume inside the EC2, which we’ll do in the next step.
> 
> ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752030513241/516964dd-2863-403f-8784-6e023afa65c4.png align="center")

✅ Our new EBS volume has been successfully created and is now ready to be attached to the EC2 instance.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752030572775/81e0f79d-7aba-4b05-9748-1dcab0f448fb.png align="center")

📌 Go to **Actions → Attach Volume**, then select your EC2 instance to attach the volume.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752030621249/fe020805-2a1c-4809-9e86-38d63df4f513.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752030672570/375c1eeb-d807-43ba-a2a5-d3e091917b4c.png align="center")

### ✅ Step 3: Connect to EC2 and Mount the Attached EBS Volume

Once your EBS volume is attached, you need to **connect to your EC2 instance** and prepare the volume for use.

#### 💻 Steps to Check and Mount:

1. **SSH into your EC2 instance** using terminal or any SSH client  
    *(e.g., using* `.pem` key file)
    
2. Run the following to **verify attached volumes**:
    
    ```powershell
    lsblk
    ```
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752030849427/80bd43cf-84a9-472c-8a07-de418783455d.png align="center")

## 🧩 Step 4: Format the EBS Volume with ext4 File System

```powershell
sudo mkfs -t ext4 /dev/xvdd
```

* `mkfs`: Stands for “make file system” — used to format the disk.
    
* `-t ext4`: Specifies the ext4 file system type (widely used in Linux).
    
* `/dev/xvdd`: The name of the newly attached EBS volume.
    

> 📌 This command prepares the volume for storing files by formatting it.

---

## 📁 Step 5: Create a Mount Point

```powershell
sudo mkdir /mydata
```

* `mkdir`: Command to make a new directory.
    
* `/mydata`: This directory will act as the mount point for the EBS volume.
    

> 📌 This is where your EBS volume will be accessible from.

---

## 🔗 Step 6: Mount the Volume

```powershell
sudo mount /dev/xvdd /mydata
```

* `mount`: Command to attach the volume to a directory.
    
* `/dev/xvdd`: The formatted EBS volume.
    
* `/mydata`: The directory where the volume will be mounted.
    

> 📌 This makes the volume usable like a local disk through `/mydata`.

---

## 📊 Step 7: Verify the Mount Status

```powershell
df -h
```

* `df`: Disk free — shows storage usage.
    
* `-h`: Human-readable format (GB/MB).
    

> ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752033383255/929e96a4-ab49-43a3-9154-7c17415b2ec9.png align="center")
> 
> 📌 This helps confirm whether the EBS volume is mounted and shows its usage.

---

## 📝 Step 8: Write Data into the Mounted Volume

```powershell
echo "This is task for EBS performed by Apurv Gujjar" | sudo tee /mydata/ebs-test.txt
```

* `echo`: Prints the given message.
    
* `| sudo tee`: Pipes the message into a file with root permissions.
    
* `/mydata/ebs-test.txt`: The file to create inside the mounted volume.
    

> 📌 This command creates a test file in the EBS volume to validate it's writable.

---

## 🔍 Step 9: Check Stored Data

```powershell
ls /mydata
```

* `ls`: Lists all files and folders in the directory.
    
* `/mydata`: The mount point where the volume is attached.
    

```powershell
cat /mydata/ebs-test.txt
```

* > ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752033421246/cc4aa9c3-cb78-43c1-9669-da856a7101de.png align="center")
    > 
    > 📌 Helps you verify that the file (`ebs-test.txt`) exists.
    
    `cat`: Used to display file content in terminal.
    
* `/mydata/ebs-test.txt`: The test file we just created.
    

> 📌 Confirms the file contains the correct data you wrote earlier.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1752033572954/a23a57c6-5e8a-4fd8-afd4-cc3f932ec8d1.png align="center")

## 👨‍💻 About the Author

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1751797710818/123a7231-3dca-4273-ad68-7bd026f69b95.png align="center")

This project is a deep dive into the AWS ecosystem designed to strengthen my foundation in cloud-native architecture, automation, and service integration **using only AWS services**.

> From launching **EC2 instances**, managing storage with **S3 and EBS**, configuring **IAM for secure access**, setting up **VPCs and subnets**, to automating infrastructure with **CloudFormation** each service I used brought real-world relevance and clarity to cloud concepts.

This series isn't just about using AWS; it's about **mastering the core services that power modern cloud infrastructure**.

---

### 📬 Let's Stay Connected

* 📧 **Email**: gujjarapurv181@gmail.com
    
* 🐙 **GitHub**: [github.com/ApurvGujjar07](https://github.com/ApurvGujjar07)
    
* 💼 **LinkedIn**: [linkedin.com/in/apurv-gujjar](https://www.linkedin.com/in/apurv-gujjar)
    

---

> 💡 *If you found this project useful, or have any suggestions or feedback, feel free to reach out or drop a comment I’d love to connect and improve.*  
> This is just the beginning **many more builds, deployments, and learnings ahead.**
