Contents

Mounting drives at boot in Linux

How to set entries in /etc/fstab.

Source

@ArchWiki:fstab

Editing /etc/fstab

1
sudo nano /etc/fstab

Or if you have Plasma desktop and want a GUI editor

1
kate /etc/fstab

You’ll need to provide sudo password upon saving the file.

Apply fstab settings

1
sudo mount -a

Check mounted location

findmnt --target dir

e.g.

1
findmnt --target /tmp

Mount NAS drive at boot

@ArchWiki and @UbuntuManPage.

Add the entry in /etc/fstab like this.

1
//192.168.50.70/OneDrive\040Business\040(xxxxxxxxx@ntu.edu.tw) /home/username/onedrive cifs uid=sosiristseng,credentials=/root/.cred,iocharset=utf8 0 0

💡

  • The end of sharename (//192...) should not leave a trailing /
  • Spaces in sharename should be replaced by \040.
  • The local folder you want to mount on (.../onedrive) should be empty.
  • If uid is not set, it defaults to root. It could cause some issure for normal users.
  • /root/.cred for storing username and password instaed of setting username=<username>,password=<password> in the options.
1
2
username=sosiristseng
password=xxxxxx

Then set permission to root only

1
sudo chmod 600 /root/.cred

💡

  • sudo mount -a to apply changes to /etc/fstab.
  • You may need to enable systemd-networkd-wait-online.service or NetworkManager-wait-online.service for network drives.

tmpfs

tmpfs is a non-persistent (cleared after reboot) temporay filesystem resides in RAM, especially suitable for /tmp or I/O intensive tasks (e.g. compiling, web servers).

For Linux systems with systemd. /tmp is automatically mounted as tmpfs.

If it’s not the case, there is the script to fix it @AskUbuntu.

1
2
sudo cp -v /usr/share/systemd/tmp.mount /etc/systemd/system/
sudo systemctl enable tmp.mount

bind mounts

@StackExchange

An alternative to symlinks.

1
mount --bind /source/folder /view/folder

The corresponding fstab entry is:

1
/source/folder /view/folder  none  bind   0 0