search by tags

for the user

adventures into the land of the command line

mounting additional storage

in this example, we’ll be mounting an AWS EBS volume onto an existing EC2 instance, but similar steps apply outside of AWS as well.

first create the ebs volume in the ec2 console. in the console, attach the volume to your instance & wait for it to come up, again in the console.

ssh to your instance and sudo to root

$ sudo su -

view available disk devices and their mount points

$ lsblk

determine if you need to create a file system on the volume

$ file -s /dev/xvda1
$ file -s /dev/xvdf

if the output of the previous command shows just data for the device, then there is no file system on the device and you need to create one.

if you are mounting an empty volume, use the following command to create an ext4 file system on the volume

$ mkfs -t ext4 /dev/xvdf

create a mount point directory for the volume

$ mkdir /mnt/data

then mount the volume at the directory you’ve created for it

$ mount /dev/xvdf /mnt/data

this mount will disappear if you reboot the computer so… lets make the mount persistent after reboots

to mount this EBS volume on every system reboot, add an entry for the device to the /etc/fstab file

create a backup of your /etc/fstab file before editting it

$ cp /etc/fstab /etc/fstab.orig
$ vim /etc/fstab

add a new line to the end of the file for your volume using the following format

# devicename mountpoint filesystemtype fsmntops fsfreq fspassno  
  /dev/xvdf  /mnt/data  ext4           defaults 0      2

check that your entry works (mounts all file systems in /etc/fstab)

$ mount -a

an important thing to note is that errors in the /etc/fstab file can render a system unbootable. so don’t shut down a system that has errors in the /etc/fstab file, unless you want excitement

to unmount a filesystem manually

$ umount /dev/xvdf

or to move a mount point to a different directory

$ mount --move /somewhere /somewhere/else

and remember to remove its entry from the /etc/fstab file unless you want it to keep reappearing whenever you reboot the computer