AWS Examples: Mounting an EBS Volume on a Linux EC2 Instance

AWS Examples: Mounting an EBS Volume on a Linux EC2 Instance

Last updated:
Table of Contents

Some kinds of EC2 Instances only support EBS datastores. If you plan on using one of these, you will need to format the volume (so it can be used as a filesystem) and them mount it to a path in your system.

Before mounting, you need to create an EBS volume and attach it to your instance. Then it will be available for mounting.

Check the volume is attached to your instance

in my case, the volume name is xvfb. It might be different in your case

Use lsblk command

$ sudo lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   8G  0 disk 
`-xvda1 202:1    0   8G  0 part /
xvdb    202:16   0  80G  0 disk /data

Format it as a filesystem

For example, ext4 format

$ sudo mkfs -t ext4 /dev/xvfb

Again, replace xvfb with you own volume name in case it's different

Only if it's an empty EBS Volume! Skip this step if your volume already has data in it.

Mount it to a path

For example, /data

$ sudo mkdir /data
$ sudo mount /dev/xvfb /data

Check the mounting was successful

The volume is only mounted until the end of your session1

$ sudo df -h /data
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvdb        79G   21G   54G  29% /data

1: You can re-mount it after rebooting (your data will still be there).