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

Last updated:

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.

Check the volume is attached to your instance

Use lsblk command

$ sudo lsblk
xvda    202:0    0   8G  0 disk 
`-xvda1 202:1    0   8G  0 part /
xvdb    202:16   0  80G  0 disk /data

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

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

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

The volume is only mounted until the end of your session. You can redo the last step after reboot (your data will be there).


Dialogue & Discussion