How to mount an EBS Volume in Linux

AWS LogoOnce you’ve created an EBS Volume in the AWS web interface and attached it to an EC2 instance, how do you actually use it on your virtual server?

Here’s how! The following commands assume you’re logged into your system as root. I’ve created a 13GB volume and attached it to my running instance.

Before we begin

Let’s get a quick overview of our file system before we get started:

Looks like right now I’ve only got one 8GB partition available. Let’s take a look at what else may be available to mount:

The second block tells us that an unused partition is at our disposal. That’s good news – let’s see how we can make that available for storage.

Find out what your EBS Volume is called

Depending on your Linux distribution, what you see in Amazon isn’t what your file system sees. Amazon may have told you that you’ve attached a volume as /dev/sdf, but your kernel may give it a different name – as seen with fdisk command above. Here’s another way to see your partitions using lsblk:

We can see that xvde is mounted on root (or /) and xvdj is not – that’s our new EBS volume. Let’s attach it so we can use it.

Format the EBS Volume

Before we do, we may have to format the partition. If you’ve used this EBS Volume before and it already contains data you don’t want to do this as it will – obviously – erase all your data. In our case however it’s a fresh volume so it needs formatting. This will take a moment, depending on the size of your volume:

Nice! The above command formats our volume as ext3 filesystem and it’s now ready for use.

Mounting your EBS Volume

Let’s create a directory so that Linux can speak to the new partition. I’ll call mine “/storage” and mount the partition to it:

No news means good news. Let’s check what our file system looks like now:

Smashing! 12GB of usable storage has been attached to our EC2 instance, ready to be populated with tons of files.

EBS Volumes are persistent, which means that whatever is saved on it will remain intact, even if you terminate your instance. In fact, you can detach your volume and attach it to another running instance and start using your data. Here’s how:

Unmounting and reusing your EBS Volume

Rather than “force detaching” the volume in the web interface, let’s ask our instance to unmount it first. This is the equivalent of saying to Windows “Safely Eject my USB stick”:

Make sure you’re not cd’d into your directory or you’ll get an error message that it’s “in use”. I’m also checking that I no longer have /storage in my file system.

You can now attach this volume to another instance, mount it again and see all your data on another server.

Is this cool or what?

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

2 thoughts on “How to mount an EBS Volume in Linux

Add your voice!