HOW TO ATTACH AND MOUNT AN EXTRA AMAZON EBS VOLUME TO AN EXISTING INSTANCE?
Published: 2022-08-07 14:20:00

**Creating new EBS volumes can be done in AWS, you can attach them to instances to add additional storage. Mounting an EBS volume to a folder inside the instance is required to use it as 
storage inside the instance**

##MOUNT VOLUME TO THE INSTANCE

**Step 1:**Create an EC2 instance if you don't have any.
**Step 2:**Go to the volume section and click on create volume.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/up11ana2xyo2yy3ks8dd.jpg)
**Step 3:**Select the volume and click on action button, then select attach button.
**Note:Make sure the EBS volume and instance are in the same availability zone**
**Step 4:**Select the instance where you want it to attach and click on attach.Your volume has now been attached to the instance.
**Now connect to the root by throwing below commands**

```
_sudo su_
_cd_
```
**Step 6:**You can now list the disk available on your EC2 instance by firing the below command.

```
_lsblk_
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdeokqj0f0hovrrig1px.jpg)

**Step 7:**For a detailed description of the volumes throw below commands

```
_fdisk -l_
```
**Step 8:**Now check if the disk is mounted 

```
_df -h_
```
**Step 9:**Using the following command, format the volume as ext4 filesystem.

```
_mkfs.ext4 /dev/xvdf_
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ty2lcurb9iwbrgil9mqb.jpg)

**Note you can also format it into the xfs filesystem.(Usually used for larger volumes)**
**Step 10:**Create extra directory of your choice to mount out new ext4 volume. I am using the name _/extra_. You can name it something of your choice.

```
_mkdir /extra_
```
**Step 11:**Mount to the volume to the _/extra_ directory using following command.

```
_mount /dev/xvdf /extra_
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gl5sgtkf3bj540dltkek.jpg)
**Note: With `_df -h_`, you can check 
whether it is mounted or not.**

```
_cd /extra_
```
**By using the above command you can go into the extra directory and can create fil e**
**To unmount the volume use the unmount command as shown below**

```
_unmount /dev/xvdf_
```

_Now here is the problem is if you stop and start your instance the data will be gone... So we have to permanently mount the volume.._

##PERMANENTLY MOUNT THE VOLUME TO THE INSTANCE 

**Step 1:**After mounting your volume click the following command

```
_blkid_
```
**Step 2:**After clicking this you will get a UUID. Copy that UUID of your extra 
volume.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u5p55tmvcd6vjkd7h256.jpg)

**Step 3:**Then login to vi editor firing below command 

```
_vi /etc/fstab_
```
_** paste the UUID and the path where 
you want to mount and the filesystem you
 format**_

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nwnfa98ktxe6vxcxfrhj.jpg)

That's it your file is permanently mounted. Now if you stop your instance and start again your data won't be lost.

That's it you can mount and unmount as much as file of your choice by following these steps.


If you have any doubt feel free to comment.