Attach an AWS EBS volume to a Linux server

Format and mount the volume

List the available disk devices and their mount points

lsblk

xvdf is not yet mounted

Determine the file system of the volume

file -s

Data means no file system

If there is no file system on the volume, create one

mkfs -t xfs /dev/xvdf

If the mkfs tool is not found, install it with yum install xfsprogs

Create a mount point

Create a directory where the volume will be mounted

mkdir /data

Mount the volume to the directory

mount /dev/xvdf /data

Automatically mount the volume after reboot

The mounting above will not be retained after a reboot. To keep the volume mounted after a reboot add am entry to the /etc/fstab file

Make a safety copy of the original fstab file

cp /etc/fstab /etc/fstab.orig

Use blkid to find the UUID of the device

blkid

# On Ubuntu 18.04
lsblk -o +UUID

Open the /etc/fstab file in an editor

vim /etc/fstab

Add an entry to the /etc/fstab file for the volume

UUID=7c6cb20b-ada0-4cd7-9c3a-342d6faf87a2  /data  xfs  defaults,nofail  0  2
  • UUID
  • Mount point
  • file system
  • recommended file system mount options. The nofail option will allow this servetr to boot even if the volume is not availble. On Debian derivatives, including earlier than Ubuntu 16.04 nobootwait is also necessary

To test if the file entry is correct unmount the volume and use the /etc/fstab to mount it again

umount /data
mount -a

If there are no errors, the file should be correct.

Leave a comment

Leave a Reply