How to Automatically Mount File Systems and Storage Devices on Server Boot

I am a Cloud Engineer with 3+ years of experience
Certifications : AWS Certified Solutions Architect Associate, AZ-900
For technical collaborations, you can drop a mail to sreedevi.devopscloud@gmail.com
Hey Tech Geeks, welcome to the AWS series in this series we are going to discuss AWS Cloud Services along with hands-on demos.
In this article, we are going to discuss about “Step-by-Step Guide to Auto-Mount File Systems at Server Startup”. Let’s discuss this way, why we should Ensure File Systems Auto-Mount During Server Startup? What if you have filesystems that are mounted to specific mount paths in the server but they are not stored in the /etc/fstab file.
If we can take one scenario that you have scheduled OS patching activity and you have performed patching activity like installing all available updates and checked if there are any reboot required patches and noticed few kernel patches requires reboot, obviously what you do reboot or restart the server right? yes you have done that and after that you reported to your team as patching activity done to proceed for further activities. The other team member reached out you saying that the files stored in the non-root block device are missing which we have earlier(before patching activity) in the specified mount path.
Note: By default root device filesystem mount details will store in the /etc/fstab by AWS
To avoid the scenario we should make sure the all filesystems and block storage devices mount details are updated in the /etc/fstab file, this file will execute at system boot time so that all the filesystems and block storage devices mounts stored in this file will automatically remount.
Let’s start demo
Go to the EC2 service in the console
Choose "Volumes" in the menu
Click on create volume
You will get this page

Configure Size, IOPS etc.., and make sure the availability zone of the server and volume are same
Scroll down add tags and click on create volume
Go back volumes and select the volume which we created earlier
Click on actions, select attach volume


Choose Instance Id which we want to attach and Device name
The device name recommended for non-root devices is /dev/sd[f-p], in the server it would be xvdf
click on attach volume
Connect to the server which we attached the earlier created volume
run lsblk command to list all attached volumes to this server

We can see that the volume is not at mounted to any mount path
Let’s format this volume to xfs filesystem type
Run mkfs -t <file-system-type> <device name>

Create a directory for the mount path

Let’s mount the EBS block device to /mnt/scripts
Run mount /dev/xvdf /mnt/scripts
Run df -h to verify

Let create a test file to store data

If we restart or reboot the server now and do the df -h our mount will not show as we are not yet added this device mount details in /etc/fstab file.
Let me reboot and verify

As you can see here our test file is not showing to recover from this, we need to remount our device to the mount path manually which we have earlier
Run mount /dev/xvdf /mnt/scripts

Let’s add this device mount details in the /etc/fstab file
Run blkid to get UUID of the EBS volume
Run vi /etc/fstab and add block device mount details in the file


Here UUID : is the unique identifier of the device
/mnt/scripts : mounting point
xfs : file system type
defaults : refers to standard mount options
nofail : Usually if we get errors while mounting system will go emergency mode. nofail option ensures that boot process continue, even issue occurs while mounting
0 : refers to disable dump utility
2 : refers to fsck (file system check) utility
Now let’s reboot this time our mount will be there as we updated it on the /etc/fstab file


In this way, we can store our mount details in the /etc/fstab file to ensure that all mounts are in place as they were before the reboot.
Thanks for reading….Feedback is appreciated!!

