This is a short reminder to myself about common mounting use-cases during boot time using fstab.
Overview
- General
- Mount ext partitions (unix standart)
- Mount ntfs partitions (windows standart)
- Mount samba folders
General
In order to mount folder during boot, edit fstab via: sudo nano /etc/fstab
Identify partitions via UUID no by name (e.g. not by /sda/sda1).
Check partition names and their UUIDs via
lsblk
and ls -l /dev/disk/by-uuid/
Test fstab settings with sudo mount -a
.
Mount ext partitions
fstab example entry:
UUID=8c21afbf-23a9-47e9-b241-417823663674 /media/vm ext4 defaults 0 1
Target folders in /media/ are automatically created (do not have to exist before).If the mounted folder is read-only, use chown/chmod in order to change permission of mounted folders.
sudo chown -R myname.myname /media/data/
Mount ntfs partitions
fstab example entry:
UUID=38E75A3E7CBCAC0E /media/data ntfs-3g default,uid=1000,windows_names,locale=en_US.utf8 0 0
Target folders in /media/ are not automatically created. Create them via:
sudo mkdir /media/data
followed by
sudo chown myname.myname /media/data/
Mount samba folders
In order to mount smb folders during boot, install the cifs-utils package:
sudo apt-get install cifs-utils
fstab example entry:
//192.168.1.2/SharedFolderName /media/NAS/LocalFolderName/ cifs credentials=/home/username/.smbcredentials,iocharset=utf8,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0
Target folders in /media/ are not automatically created. Create them via:
sudo mkdir /media/data
followed by
sudo chown myname.myname /media/data/
Create the .smbcredentials file in your home directory:
username=myname password=mypassword domain=domain_or_workgroupname
Secure the ~/.smbcredentials file via:
chmod 0600 ~/.smbcredentials
In case of:
mount error(95): Operation not supported Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
add the smb protocol version in the fstab line (smb1 is default). Example for smb protocol 2 would be vers=2.0 see:
//192.168.1.2/SharedFolderName /media/NAS/LocalFolderName/ cifs credentials=/home/username/.smbcredentials,iocharset=utf8,vers=2.0,gid=1000,uid=1000,file_mode=0777,dir_mode=0777 0 0