Automount Additional Drives Through fstab at Boot
This tutorial will describe the basics of utilizing the fstab file located in /etc/ in order to mount static drives during boot. It will briefly explain how to find a partition or drive’s UUID, what some options do, and further reading should the information provided be insufficient.
Prerequisites
- Root access
Adding Entries to /etc/fstab
1. List the UUIDs of your partitions
In the terminal emulator of your choice (Konsole, Alacritty, Kitty, etc.) run the following:
In our example, we know that we want to mount a Windows partition, which is ntfs, and we know that roughly half its space is available. Thus we can determine that the partition we want to mount is nvme0n1p3
and its UUID to be 08A24E90A24E81E4
, with a file system of ntfs
in this example.
2. Identifying your partition
Often lsblk -f
will provide all the information you need to mount your disk through /etc/fstab at this point. Should you find the information lacking however you can run the following:
We already know our UUID in this example, however, fdisk -l
can make it a bit more clear to us by showing the exact size of the partition (1.4T) as well as its type (Microsoft basic data)
That should make it abundantly clear to us that the partition we want is nvme0n1p3
with a UUID of 08A24E90A24E81E4
as described earlier. We knew earlier, but now we just know it for sure.
Once you are confident you’ve found the correct partition, copy the UUID. Copying from the terminal emulator is typically done with ctrl+shift+C
.
3. Adding an Entry to /etc/fstab
Now that we’ve obtained the UUID of our partition, it’s time to open up the fstab file.
Feel free to use your text editor of choice, in this example we will use nano. In order to edit the fstab file it must be opened as root:
Using the arrow keys, navigate to the bottom of the fstab file, and then on a new line we’ll create our new entry:
The break down of this entry is as follows:
-
UUID=08A24E90A24E81E4
This is the file system we want to mount, indentified by its UUID. There are other methods to identify your filesystem, though UUID tends to be safest. Additional methods listed here. -
/media/windows
The Linux Filesystem Hierarchy Standard says that/media/
is the proper location for removable drives to be mounted.windows
indicates the directory we wish to mount our drive to. Each drive we want to mount will need its own directory. -
ntfs3
This is the filesystem type for our file system. We are explicitly using the ntfs3 kernel driver in our example. Other examples would beext4
,xfs
or similar. This explicit filesystem type declaration can be replaced withauto
to allow the mount command to make its best guess. -
defaults,nofail
The options we want to pass to the mount command for this drive.nofail
meaning that should this drive fail to mount, it will not cause an error while booting. Booting will continue like normal.defaults
implies a standard set of logical options. Typicallyrw
,ro
, or similar. -
the first 0
dump, this is typically deprecated in modern systems. Leaving this at 0 won’t hurt anything. Feel free to read more about it here. -
the second 0
This sets the order for file system checks at boot time. For a root partition (unless your root file system is btrfs or xfs, which should be set to 0) this should be 1. All other file systems in your fstab should be either 0 (disabled) or 2. More information here.
Options are explained here and here in much more detail.
More info
As an aside, all options after the filesystem type declaration are optional if you do not change them from the default.
Thus
UUID=<partition UUID> /media/foo somefs
and
UUID=<partition UUID> /media/foo somefs defaults 0 0
are equivalent. somefs
followed by nothing is implicitly somefs defaults 0 0
Important for Windows Partitions
If you are following this guide with a Windows partition your options should be uid=1000,gid=1000,rw,user,exec,umask=000
replacing uid and gid with your user id and group id. If you do not give user, and exec permissions, Windows may lock your drive leaving you unable to modify anything. This may happen regardless of permissions if you do not disable fast boot.
If you do not set umask=000 some files may be unwritable depending
4. Finishing Up
If you wish to mount the drive you created an entry for now, you need to run the following:
and then:
Your drive should now appear under /media/windows
, and will appear there the next time you boot, as well as moving forward.
If you wish to create a link to your newly mounted drive in your home directory you can run the following
To show it worked
tl;dr
- Find the UUID of your partition
- Open /etc/fstab
- Create an entry in the bottom of the file
Replacing <partition UUID>
, foo
, and somefs
with your UUID, directory, and filesystem. eg., ext4, as well as setting any other options you may want after defaults, such as _netdev
for a NAS, or nofail
for any non-critical drive.
- Reload your daemon
- Mount your drive
This drive is now mounted, and will now be mounted on boot moving forward as well.
Additional reading
- https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html - Filesystem Hierarchy Standard
- https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s11.html - FHS on
/media/
- https://linux.die.net/man/8/dump - manual for
dump
- https://man.archlinux.org/man/fsck.8 - manual for
fsck
- https://man.archlinux.org/man/fstab.5.en - man page for fstab
- https://wiki.archlinux.org/title/Fstab - Arch Linux wiki for fstab