Add an additional EBS volume to a running AWS EC2 machine
Step 1: Create and Attach an EBS Volume
-
Go to AWS Console > EC2 > Elastic Block Store (EBS).
-
Click "Create Volume".
- Choose the same availability zone as your EC2 instance.
- Select the desired size, type (
gp3orgp2for general-purpose SSD), and IOPS. - Click Create Volume.
-
Attach the EBS Volume to the EC2 Instance.
- Go to Volumes in the EBS dashboard.
- Select the newly created volume and click Actions > Attach Volume.
- Choose the target EC2 instance.
- Set a device name (e.g.,
/dev/xvdfor/dev/sdf). - Click Attach.
Step 2: Format and Mount the Volume
-
Connect to the EC2 instance via SSH:
ssh ubuntu@your-ec2-ip -
Check if the volume is detected:
lsblkYou should see a new device (e.g.,
/dev/xvdfor/dev/nvme1n1). -
Format the volume (if it's new and unformatted):
sudo mkfs -t ext4 /dev/xvdf(Replace
/dev/xvdfwith your actual device name fromlsblk.) -
Create the mount point:
sudo mkdir -p /home/ubuntu/kbparse -
Mount the volume:
sudo mount /dev/xvdf /home/ubuntu/kbparse -
Verify the mount:
df -h
Step 3: Make the Mount Persistent (Optional)
To ensure the volume mounts automatically after a reboot:
-
Get the volume’s UUID:
sudo blkid /dev/xvdfYou will see output like:
/dev/xvdf: UUID="1234-5678-ABCD" TYPE="ext4" -
Edit
/etc/fstab:sudo nano /etc/fstabAdd this line at the bottom:
UUID=1234-5678-ABCD /home/ubuntu/kbparse ext4 defaults,nofail 0 2 -
Test the fstab entry (to prevent boot issues):
sudo mount -a