How to achieve automatic mounting on startup in Linux?
To enable automatic mounting in Linux at startup, follow the steps below:
- Open the terminal and log in as the root user or a user with sudo permissions.
- Open the /etc/fstab file with a text editor, for example:
sudo nano /etc/fstab
- In the open file, add an entry for each mount point on a separate line. Each entry should include the device’s UUID or label, mount point, file system type, and mount options. For example:
UUID=设备的UUID /挂载点 文件系统类型 挂载选项 0 2
You can view the UUID of a device by using the following command.
sudo blkid
- Save and close the file.
- When you restart the computer, the mounting point should automatically mount.
Please note that in order to identify a device using UUID, the device must already be partitioned and formatted. If the device does not have a UUID or label, you can use the device’s path (e.g. /dev/sdb1) instead.
Additionally, if you want to use network shared mount points like NFS or Samba shares, you need to make sure that the network connection is already started at boot time. You can use systemd or other tools to configure the network connection to start automatically at boot.