Mounting with fstab
Definition
The fstab file can be used to define how disk partitions or remote file systems should be mounted into the file system. The file you have to edit is /etc/fstab and would look like this:
1
2
3
4
5
6
7
8
9
# Static information about the filesystems.
# See fstab(5) for details.
# <file system> <dir> <type> <options> <dump> <pass>
# /dev/sda2
UUID=232c16da-6f07-4f54-9bc1-494f97c05c5e / ext4 rw,relatime 0 1
# /dev/sda1
UUID=219E-A7C7 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2
| option | description |
|---|---|
| < file system > | describes the block special device or remote file system to be mounted, you can use sudo blkid. You can use UUIDs, PARTUUIDs, direct access like /dev/sdX and so on |
| < dir > | describes the mount directory |
| < type > | the file system type, like auto, ext4, btrfs, ntfs-3g … |
| < options > | the associated mount options, like defaults, rw, relatime |
| < dump > | is checked by the dump utility. This field is usually set to 0, which disables the check. |
| < pass > | sets the order for file system checks at boot time. For the root device it should be 1. For other partitions it should be 2, or 0 to disable checking. |
Mounting additional partitions
I use this often for my Batocera partition to easily access it whenever I want or have to configure any change or to access my shares on my NAS.
You have to create the corresponding mountpoints before mounting the devices or remote locations in it.
1
2
3
4
5
6
7
8
# /dev/sdb1 - Batocera boot partition
/dev/disk/by-uuid/2067-EAA3 /run/media/user/batocera-boot-local vfat user,uid=1000,gid=1000,umask=0022,nosuid,nodev,nofail,x-gvfs-show 0 2
# /dev/sdb2 - Batocera share partition
/dev/disk/by-uuid/5c329796-f5ae-487d-b747-3255c7b1b0a5 /run/media/user/batocera-share-local ext4 defaults,nosuid,nodev,nofail,x-gvfs-show 0 2
#SMB-Share
//192.168.178.5/backups /home/user/NAS/backups cifs user,noauto,_netdev,uid=1000,gid=1000,dir_mode=0770,file_mode=0770,credentials=/home/tommy/.smb,iocharset=utf8,vers=3.0 0 0
In this example I used the files in /dev folder to locate the partitions, but you can also use UUID=.
Filesystem options:
| option | description |
|---|---|
| /run/media/user | this is the standard mount point used by Arch so I created folders inside to easy remember it, user would be your username of course |
| auto | this is the partition type, could also be vfat for the boot partition and ext4 or btrfs for the share partition or cifs for samba remote locations |
Mounting options:
| option | description |
|---|---|
| users | means that non-root users are allowed to mount/unount this partition |
| auto | or noauto means if this device or remote location should be mount at boot, for remote locations it is recommended to also set _netdev |
| rw | have read/write access |
| uid=1000 | user id of your user to manipulate the user file permissions regardingless of the actual user of the files, get it in terminal with id |
| gid=1000 | same with the group id |
| x-gvfs-show | mount point shows up in sidebar of dolphin or nautilus (file managers) |
_netdevmount option ensures the mount point would be loaded after the network is initialized. I would also recommend for mobile devices like laptops to set thenoautooption especially if the remote location is only available on local networks or through VPNs.
Mount and unmount
After you’re finished any change must be made known to the system.
1
2
3
sudo systemctl daemon-reload
sudo umount -a
sudo mount -a
The 2nd command unmounts all devices known in fstab and the 3rd command mounts them all again. You can also use the exact mountpoint as paremeter instead of -a.
Note: If you had Arch Linux kernel updates and didn’t reboot you’re not able to mount
cifspartitions.
