Logo

dev-resources.site

for different kinds of informations.

How to Attach and Use a New EBS Volume on Your Existing EC2 Instance

Published at
9/25/2024
Categories
ebs
awsebs
aws
Author
shahidkhans
Categories
3 categories in total
ebs
open
awsebs
open
aws
open
Author
11 person written this
shahidkhans
open
How to Attach and Use a New EBS Volume on Your Existing EC2 Instance

Are you running out of disk space on your AWS EC2 instance? Don't worry; you're not alone! As applications grow and data accumulates, the need for additional storage becomes inevitable. The good news is that Amazon Web Services (AWS) makes it easy to attach new Elastic Block Store (EBS) volumes to your existing EC2 instances. In this blog post, we'll walk you through the step-by-step process to seamlessly add more storage to your server.

You can watch along the video
https://www.youtube.com/watch?v=X99yQtxFzzY

đź’˝ Why Add a New EBS Volume?

Before we dive in, let's understand why you might need an additional EBS volume:

  • Increased Storage Needs: Your application data is growing beyond the current disk capacity.
  • Separation of Data: You want to separate system files from application data for better management.
  • Performance Optimization: Distribute I/O operations across multiple volumes.

Now, let's get started!


đź“Ś Step 1: Check Current Disk Usage

First things first, let's see how much disk space you're currently using.

Run the df -h command:

ubuntu@ip-172-31-13-233:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        39G   31G  8.3G  79% /
...
Enter fullscreen mode Exit fullscreen mode

What's happening here?

  • /dev/root is 79% full. That's a warning sign that we need more space!

đź“Ś Step 2: List Attached Block Devices

Next, we need to identify the block devices attached to your instance.

Use the lsblk command:

ubuntu@ip-172-31-13-233:~$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
...
nvme1n1     259:0    0 93.1G  0 disk
nvme0n1     259:1    0   40G  0 disk
└─nvme0n1p1 259:2    0   40G  0 part /
Enter fullscreen mode Exit fullscreen mode

Understanding the output:

  • nvme0n1 is your root volume. which is 39 GB mounted on /dev/root . ⚠️ Don't touch that
  • nvme1n1 is the new 93.1G EBS volume you've attached but not yet configured.

đź“Ś Step 3: Inspect the New Volume

Let's check the current state of the new volume.

Run:

ubuntu@ip-172-31-13-233:~$ sudo file -s /dev/nvme1n1
/dev/nvme1n1: data
Enter fullscreen mode Exit fullscreen mode

Interpretation:

  • The output data means the volume is raw and doesn't have a filesystem.

đź“Ś Step 4: Create a Filesystem

Time to format the new volume so we can use it.

Format with ext4 filesystem:

ubuntu@ip-172-31-13-233:~$ sudo mkfs -t ext4 /dev/nvme1n1
Enter fullscreen mode Exit fullscreen mode

Sample output:

mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 24412160 4k blocks and 6108000 inodes
Filesystem UUID: your-uuid-here
Superblock backups stored on blocks: ...
Enter fullscreen mode Exit fullscreen mode

Note: Formatting will erase all data on the volume. Since it's new, we're safe!

đź“Ś Step 5: Mount the New Volume

Let's make this new space accessible.

Create a mount point:

ubuntu@ip-172-31-13-233:~$ sudo mkdir /mnt/data
Enter fullscreen mode Exit fullscreen mode

Mount the volume:

ubuntu@ip-172-31-13-233:~$ sudo mount /dev/nvme1n1 /mnt/data
Enter fullscreen mode Exit fullscreen mode

Verify the mount:

ubuntu@ip-172-31-13-233:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
...
/dev/nvme1n1     92G   61M   87G   1% /mnt/data
Enter fullscreen mode Exit fullscreen mode

Awesome! /dev/nvme1n1 is now mounted at /mnt/data.

đź“Ś Step 6: Ensure Persistence Across Reboots

We don't want to remount the volume every time the server restarts.

Get the UUID of the new volume:

ubuntu@ip-172-31-13-233:~$ sudo blkid /dev/nvme1n1
/dev/nvme1n1: UUID="your-uuid-here" TYPE="ext4"
Enter fullscreen mode Exit fullscreen mode

Edit the fstab file:

ubuntu@ip-172-31-13-233:~$ sudo nano /etc/fstab
Enter fullscreen mode Exit fullscreen mode

Add this line at the end:

UUID=1a36ae86-3d85-4b31-addb-asdsad /mnt/data  ext4  defaults,nofail  0  2
Enter fullscreen mode Exit fullscreen mode

Save and exit.

Test the fstab entry:

ubuntu@ip-172-31-13-233:~$ sudo umount /mnt/data
ubuntu@ip-172-31-13-233:~$ sudo mount -a
Enter fullscreen mode Exit fullscreen mode

Verify it's mounted:

ubuntu@ip-172-31-13-233:~$ df -h
...
/dev/nvme1n1     92G   61M   87G   1% /mnt/data
Enter fullscreen mode Exit fullscreen mode

Success! The volume will now auto-mount on reboot.


🎉 Conclusion

You've just expanded your EC2 instance's storage without any downtime! By attaching and configuring a new EBS volume, you can:

  • Avoid Disk Space Issues: Prevent application failures due to insufficient storage.
  • Improve Data Management: Organize data efficiently across multiple volumes.
  • Scale Seamlessly: Add storage as your needs grow, without overprovisioning upfront.

Pro Tip: 1 Always ensure you have backups before modifying disk configurations, especially in production environments.
Pro Tip: 2 To check the partition format type (filesystem type) of a disk partition on your Linux/Ubuntu system, you can use below commands. Here's how you can do it:


🛠️ Methods to Check Partition Format Type

1. Using the lsblk Command with the -f Option

The lsblk command lists information about all available or specified block devices. The -f option displays the filesystem information.

Command:

lsblk -f
Enter fullscreen mode Exit fullscreen mode

Example Output:

NAME        FSTYPE LABEL UUID                                 MOUNTPOINT
nvme0n1
└─nvme0n1p1 ext4         a1b2c3d4-e5f6-7890-abcd-sdsdsd/
nvme1n1     ext4         1a2b3c4d-5e6f-7890-abcd-sdsdsd /mnt/data
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • The FSTYPE column shows the filesystem type of each partition.
  • In this example, both partitions are formatted with the ext4 filesystem.

2. Using the blkid Command

The blkid command is used to locate or print block device attributes.

Command:

sudo blkid
Enter fullscreen mode Exit fullscreen mode

Example Output:

/dev/nvme0n1p1: UUID="a1b2c3d4-e5f6-7890-abcd-1234567890ab" TYPE="ext4" PARTUUID="12345678-01"
/dev/nvme1n1: UUID="1a2b3c4d-5e6f-7890-abcd-0987654321fe" TYPE="ext4"
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • The TYPE field indicates the filesystem type.
  • Replace /dev/nvme1n1 with your specific device if needed.

3. Using the file Command

The file command tests each argument to determine what it is. When used with the -s option, it reads the block or character special files.

Command:

sudo file -s /dev/nvme1n1
Enter fullscreen mode Exit fullscreen mode

Example Output:

/dev/nvme1n1: Linux rev 1.0 ext4 filesystem data, UUID=1a2b3c4d-5e6f-7890-abcd-0987654321fe
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • The output shows that /dev/nvme1n1 has an ext4 filesystem.
  • This method is useful for checking unmounted partitions.

4. Using the df Command with the -T Option

The df command reports file system disk space usage. The -T option displays the filesystem type.

Command:

df -T
Enter fullscreen mode Exit fullscreen mode

Example Output:

Filesystem     Type     1K-blocks     Used Available Use% Mounted on
/dev/nvme0n1p1 ext4      41152832 32505888   6584576  84% /
/dev/nvme1n1   ext4      94371840   65536  89595904   1% /data
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • The Type column indicates the filesystem type of each mounted filesystem.

đź“Ś Summary

  • lsblk -f: Lists block devices with filesystem information.
  • sudo blkid: Shows UUID and filesystem type of block devices.
  • sudo file -s /dev/your_device: Identifies the filesystem type of a specific device.
  • df -T: Displays mounted filesystems with their types.

đź”’ Permissions

  • Some commands may require superuser privileges. Use sudo when necessary.
  • Ensure you have the appropriate permissions to run these commands safely.
  • You need to change the permission to folder /mnt/data/ for non root user to able to write and read .
sudo chmod -R 777 /mnt/data/
Enter fullscreen mode Exit fullscreen mode

đź’ˇ Tips

  • Replace /dev/nvme1n1 with the actual device name you wish to check.
  • For a quick overview, lsblk -f is often the most convenient.

Example in Context:

If you want to check the filesystem type of the new EBS volume you attached (as per your previous steps), you might run:

ubuntu@ip-172-31-13-233:~$ lsblk -f
Enter fullscreen mode Exit fullscreen mode

This will display:

NAME        FSTYPE LABEL UUID                                 MOUNTPOINT
nvme0n1
└─nvme0n1p1 ext4         a1b2c3d4-e5f6-7890-abcd-1234567890ab /
nvme1n1     ext4         1a2b3c4d-5e6f-7890-abcd-0987654321fe /data
Enter fullscreen mode Exit fullscreen mode

🎉 Conclusion

By using these commands, you can easily determine the partition format type of your disk partitions. This is especially useful when managing storage devices, setting up new filesystems, or troubleshooting disk-related issues.


Feel free to reach out if you have more questions or need further assistance!


🔥 Join the Conversation!

Have questions or tips about managing EBS volumes? Drop a comment below! If you found this guide helpful:

  • đź‘Ť Like and Share: Help others discover this resource.
  • đź”” Subscribe: Stay updated with more AWS tutorials.

Thanks for reading, and happy computing!


ebs Article's
30 articles in total
Favicon
Identifying EBS Volumes and Mount Points with lsblk
Favicon
Exploring the AWS Journey Understanding Amazon EBS (Elastic Block Store)
Favicon
Putting Oracle EBS 12.2.13 to Work: Overview of Its Key Uses and Application
Favicon
Detached EBS volume from your local Linux system.
Favicon
How to Attach, Modify, and Increase an AWS EC2 EBS Volume from Your Local Linux Machine.
Favicon
Navigating the Key Challenge of Oracle EBS Testing
Favicon
Unlock Next-Level Efficiency with Oracles EBS Test Automation
Favicon
Rеvolutionizing Oraclе EBS Tеst Automation with Opkеy: A Comprehensive Guide
Favicon
Top 5 Benefits of Oracle EBS R12 Upgrade
Favicon
AWS Storage - Part 3: Instance Store and EBS
Favicon
k8s-pvc-tagger: The Swiss Army Knife of AWS EBS Tagging
Favicon
Mastering the Oracle EBS 12.2.13 Upgrade: Effective Testing Strategies
Favicon
Como Criptografar um Volume EBS Existente
Favicon
Storage options for EKS: Comparing Amazon EFS, EBS, S3 and FSx for ONTAP
Favicon
[SAA-C03: Part 4] - Unlocking EC2 Storage: Mastering EBS, AMIs, and Beyond for Optimal Performance
Favicon
How to Attach and Use a New EBS Volume on Your Existing EC2 Instance
Favicon
30 days of AWS - Part 4: AWS Storage
Favicon
Securing Your Data in AWS : A Practical Guide
Favicon
Oracle EBS 12.2.13: A Detailed Overview of the Latest Release
Favicon
Forensic Analysis of AWS EBS Volumes: Pentesting Storage
Favicon
AWS Under the Hood - Day 2 Why does an AWS EC2 instance lose its public IP address after a restart and how can this be managed?
Favicon
AWS Under the Hood - Day 1
Favicon
EVERYTHING YOU SHOULD KNOW ABOUT ORACLE EBS TESTING: STRATEGIES, TOOLS, AND AUTOMATION PRACTICES
Favicon
How Can Performing Oracle EBS Testing in Logistics and Distribution Aid in Optimizing Supply Chains?
Favicon
Secure Your Future: A Guide to Successful Oracle EBS Upgrades
Favicon
Diving Into Testing Strategies for Oracle EBS Upgrade
Favicon
Oracle EBS Upgrade: Accelerate It With Test Automation
Favicon
Ensure Seamless Oracle EBS Upgrade With Test Automation
Favicon
From Test Plans to Success: Mastering Oracle EBS Upgrade
Favicon
Get the Competitive Advantage by Considering Oracle EBS Upgrade

Featured ones: