When we connect an external drive, by default, Linux OS (or Ubuntu Server) doesn't automount the external drive at startup. We can mount it very easily using the mount
command but we want to enable automount feature on startup. So, we don't need to mount the drive again after restarting or logging into Linux OS. Here are steps to auto mount drive at startup -
1. Create the Mount Point
First, we need to create a directory which will be our mount point for a drive
2. Get Drive UUID and Type
Now, we need to get the drive UUID and File System Type. This information we need in the next step. So, to find the drive's UUID and File System Type, run the following command -
This will return something like what we have below. Here you can see, sd2 is type exfat and doesn't have any mount point. So, we need to mount this sda2 on /media/USB1
. There UUID for this is 632D-7154
and File System Type is exfat
. So, Copy the UUID and File System Type from the disk.
3. Edit fstab
To edit the fstab file run the following command (note I'm using nano here but use whatever editor you prefer)
You'll see something like this -
Here we need to add one more entry for our drive. The format for adding a new entry is something like this -
3.1. Mount drive as root user
To mount the drive as root user we need to add an entry like this -
3.2. Mount drive as specific user
If we want to mount the drive with specific user and group then we need to add an entry like this -
Here, uid=1000 is the user id, gid=1000 is the group id, and umask=022 is to set permissions so that the owner has read, write, execute. Group and Others will have read and execute permission.
You can run the id
command to get all users and group ids.
4. Test fstab
Now we'll test the fstab
before rebooting because an invalid fstab
can render a disk unbootable. So, for the test, run the following command and check if there is any error or warnings. Do not reboot your Ubuntu Server / Linux OS without resolving those errors or warnings (if any).
5. Restart Ubuntu Server / Linux OS
If the last step doesn't show any error or warnings then restart Ubuntu Server / Linux OS using the following command -
6. Test the Mount Point
Run the same command which we run in Step 2 to check if our drive is mounted to its mount point.
Here you can see, sda2
is now mounted to /media/USB1
.