The mount point we did in the previous section is not preserved after rebooting the EC2 instance. In order to do so, we need to add an entry for the device to the /etc/fstab file. This file contains all the disks and partitions, and describes how they should be initialized into the filesystem.
First, we’ll create a backup of the /etc/fstab file.
It is a good practice to create a backup of the known good configuration file before making edits. Some critical files (such as /etc/fstab) can prevent the system from booting properly if there are typos or incorrect configuration.
sudo cp /etc/fstab /etc/fstab.orig
Next, find the device’s 128-bit universally unique identifier (UUID). This UUID, unlike the devices’ names, is unique and does not change:
sudo blkid
This command will return the UUID of your devices. Save the UUID of /dev/xvdf. We will use it later:
/dev/xvda1: LABEL="/" UUID="ca774df7-756d-4261-a3f1-76038323e572" TYPE="xfs" PARTLABEL="Linux" PARTUUID="02dcd367-e87c-4f2e-9a72-a3cf8f299c10"
/dev/xvdf: UUID="aebf131c-6957-451e-8d34-ec978d9581ae" TYPE="xfs"
Now that we know the UUID, let’s add it to the /etc/fstab file. Open the file:
sudo nano /etc/fstab
Add the following line to the file, using the UUID you saved previously:
UUID=aebf131c-6957-451e-8d34-ec978d9581ae /data xfs defaults,nofail 0 2
Save the file.
Now, the /etc/fstab/ has two entries. Check that the entry has been added correctly. We’ll unmount the device and then mount all file systems in /etc/fstab.
sudo umount /data
sudo mount -a
If there are no errors, the configuration is properly done!