Logo

dev-resources.site

for different kinds of informations.

How to Attach, Modify, and Increase an AWS EC2 EBS Volume from Your Local Linux Machine.

Published at
12/7/2024
Categories
aws
ec2
ebs
ubuntu
Author
abstractmusa
Categories
4 categories in total
aws
open
ec2
open
ebs
open
ubuntu
open
Author
12 person written this
abstractmusa
open
How to Attach, Modify, and Increase an AWS EC2 EBS Volume from Your Local Linux Machine.

Expanding the storage of an AWS EC2 instance involves attaching an Elastic Block Store (EBS) volume, modifying it, and resizing the filesystem to use the additional space. This blog walks you through these steps with a detailed explanation of the commands you will use.

Prerequisites

  • AWS EC2 instance: You need an Ubuntu-based EC2 instance running on AWS.
  • Local Linux system: A Linux system (Ubuntu in this case) to SSH into the EC2 instance.
  • AWS EBS Volume: An attached EBS volume to your instance.

Steps to Attach and Modify an EBS Volume

Step 1: Switch to the Root User

sudo su
Enter fullscreen mode Exit fullscreen mode

This command allows you to switch to the root user for administrative privileges required to perform disk operations.


Step 2: Change to the Home Directory

cd
Enter fullscreen mode Exit fullscreen mode

Navigate to the home directory to ensure you’re working in a familiar and safe location.


Step 3: Check Current Disk Usage

df -hT
Enter fullscreen mode Exit fullscreen mode
  • df: Displays the amount of disk space used and available on filesystems.
  • -hT: Displays sizes in a human-readable format (-h) and includes filesystem types (-T).

Use this to verify the current storage and note if the new EBS volume is recognized.


Step 4: List Block Devices

lsblk
Enter fullscreen mode Exit fullscreen mode
  • Displays information about available block devices such as disks and partitions.
  • Confirm that the new EBS volume (/dev/xvdb) is attached to your instance.

Step 5: View Disk Partitions

fdisk -l
Enter fullscreen mode Exit fullscreen mode
  • Lists all disk partitions.
  • Helps you identify the available disk space on the new EBS volume.

Step 6: Create a Partition on the New Volume

fdisk /dev/xvdb
Enter fullscreen mode Exit fullscreen mode
  • This command opens the partition editor for /dev/xvdb.

Follow these prompts:

  • n: Create a new partition.
  • w: Write changes to disk and exit.

You now have a partition (/dev/xvdb1) ready for formatting.


Step 7: Format the Partition with XFS

mkfs -t xfs /dev/xvdb1
Enter fullscreen mode Exit fullscreen mode
  • mkfs: Creates a filesystem on the partition.
  • -t xfs: Specifies the XFS filesystem type, known for scalability and performance.

Step 8: Create a Directory for Mounting

mkdir new_directory
Enter fullscreen mode Exit fullscreen mode

Create a new directory where the EBS volume will be mounted.


Step 9: Mount the Partition

mount /dev/xvdb1 /new_directory
Enter fullscreen mode Exit fullscreen mode

Mount the newly formatted partition to the new_directory.


Step 10: Expand the Partition

If the EBS volume has been resized in AWS, you need to expand the partition to use the additional space.

Resize the Partition Table

growpart /dev/xvdb 1
Enter fullscreen mode Exit fullscreen mode
  • growpart: Extends a partition on a block device.
  • /dev/xvdb 1: Indicates the first partition of the volume.

Resize the Filesystem

xfs_growfs -d new_directory
Enter fullscreen mode Exit fullscreen mode
  • xfs_growfs: Grows the XFS filesystem.
  • -d: Expands the filesystem to the maximum available size.
  • new_directory: Specifies the mount point.

Verification

  1. Check Filesystem Usage:
   df -hT
Enter fullscreen mode Exit fullscreen mode

Verify that the filesystem reflects the increased size.

  1. Inspect the Mounted Volume:
   lsblk
Enter fullscreen mode Exit fullscreen mode

Confirm the updated partition and filesystem.


Conclusion

By following these steps, you can successfully attach, partition, format, and expand an AWS EBS volume on your EC2 instance. This process ensures that your instance can handle increased storage requirements seamlessly.

Happy cloud computing! πŸš€

ec2 Article's
30 articles in total
Favicon
Power Up Your AWS Game: Create EC2 Instances, Install Apache, and Connect with PowerShell
Favicon
Introducing vulne-soldier: A Modern AWS EC2 Vulnerability Remediation Tool
Favicon
Tensorflow on AWS
Favicon
Forward logs to Cloudwatch for an EC2 instance running a custom Linux AMI
Favicon
How to Provision an Ubuntu Server & Using Apache for Hosting a Website
Favicon
EC2 instances with pre-configured EFS (elastic file system ) using Terraform modules
Favicon
Understanding EC2 in AWS - Day 1
Favicon
Identifying EBS Volumes and Mount Points with lsblk
Favicon
Creating an EC2 Instance on AWS and Installing IIS server on it
Favicon
Short: User Data file for Ubuntu based AWS ec2 instance with docker and docker compose.
Favicon
AWS VPC with Public and Private Subnets & NAT Gateway
Favicon
Terraform in AWS | Provision EC2 with AWS Systems Manager SSM access
Favicon
How to Build a Simple AWS Test Environment with Terraform
Favicon
How to Simulate High CPU Usage on AWS Ubuntu Instances for Testing and Performance Optimization
Favicon
πŸš€ EBS Volumes for EC2: Should You Use Multiple Small Volumes or One Large Volume? πŸ’‘
Favicon
Run vs code on a private AWS ec2 instance without ssh (with AWS CDK examples)
Favicon
Understand Amazon Elastic Compute Cloud (EC2) for launching virtual machines
Favicon
Deploy Vite-React Project in AWS EC2 using custom domain and free SSL Certificate.
Favicon
AWS Network Fundamentals for EC2 instance!
Favicon
Connecting to an EC2 Instance with Ubuntu and Installing NGINX on AWS
Favicon
What Are the Key Differences Between AWS EC2 and AWS Lambda?
Favicon
Deploy your Discord Bot using Amazon EC2
Favicon
AWS Elastic Compute Cloud (EC2)
Favicon
Securing Your AWS EC2 and S3 Communication: Best Practices for Enhanced Security
Favicon
How to install an iis web server on Amazon Ec2 instance
Favicon
Creating a Windows EC2 Instance on AWS and Installing IIS Server on it
Favicon
Detached EBS volume from your local Linux system.
Favicon
AI Model Optimization on AWS Inferentia and Trainium
Favicon
How to Attach, Modify, and Increase an AWS EC2 EBS Volume from Your Local Linux Machine.
Favicon
How to Deploy a Flask App on an AWS EC2 Instance: A Step-by-Step Guide

Featured ones: