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 a…


This content originally appeared on DEV Community and was authored by shahid

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% /
...

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 /

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

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

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: ...

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

Mount the volume:

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

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

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"

Edit the fstab file:

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

Add this line at the end:

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

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

Verify it's mounted:

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

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

Example Output:

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

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

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"

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

Example Output:

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

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

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

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/

đź’ˇ 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

This will display:

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

🎉 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!


This content originally appeared on DEV Community and was authored by shahid


Print Share Comment Cite Upload Translate Updates
APA

shahid | Sciencx (2024-09-25T12:55:05+00:00) How to Attach and Use a New EBS Volume on Your Existing EC2 Instance. Retrieved from https://www.scien.cx/2024/09/25/how-to-attach-and-use-a-new-ebs-volume-on-your-existing-ec2-instance/

MLA
" » How to Attach and Use a New EBS Volume on Your Existing EC2 Instance." shahid | Sciencx - Wednesday September 25, 2024, https://www.scien.cx/2024/09/25/how-to-attach-and-use-a-new-ebs-volume-on-your-existing-ec2-instance/
HARVARD
shahid | Sciencx Wednesday September 25, 2024 » How to Attach and Use a New EBS Volume on Your Existing EC2 Instance., viewed ,<https://www.scien.cx/2024/09/25/how-to-attach-and-use-a-new-ebs-volume-on-your-existing-ec2-instance/>
VANCOUVER
shahid | Sciencx - » How to Attach and Use a New EBS Volume on Your Existing EC2 Instance. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/25/how-to-attach-and-use-a-new-ebs-volume-on-your-existing-ec2-instance/
CHICAGO
" » How to Attach and Use a New EBS Volume on Your Existing EC2 Instance." shahid | Sciencx - Accessed . https://www.scien.cx/2024/09/25/how-to-attach-and-use-a-new-ebs-volume-on-your-existing-ec2-instance/
IEEE
" » How to Attach and Use a New EBS Volume on Your Existing EC2 Instance." shahid | Sciencx [Online]. Available: https://www.scien.cx/2024/09/25/how-to-attach-and-use-a-new-ebs-volume-on-your-existing-ec2-instance/. [Accessed: ]
rf:citation
» How to Attach and Use a New EBS Volume on Your Existing EC2 Instance | shahid | Sciencx | https://www.scien.cx/2024/09/25/how-to-attach-and-use-a-new-ebs-volume-on-your-existing-ec2-instance/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.