Mount Disk in Linux on Boot## BrefAutomatically mount the hard drive at boot¶
1. Check Partition.¶
Before mounting the disk, you need to know the path orUUIDof each disk. At this time, you mainly rely on the two instructionsfdiskandblkid. The former instruction obtains the partition information, and the latter instruction obtains the attributes of theBlock deviceblock device.```
$ sudo blkid
/dev/sda1: LABEL="Win10" UUID="C4A0E65EA0E65708" TYPE="ntfs" PARTUUID="6190c592-01"
/dev/sda2: UUID="AE3C137D3C133FAF" TYPE="ntfs" PARTUUID="6190c592-02"
/dev/sdb1: LABEL="Apps" UUID="0000678400004823" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="45ed07d2-c9e3-4167-8868-3e33f62784e1"
/dev/sdb2: LABEL="Data" UUID="0000678400004823" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="2a8b4bf1-8357-4d65-bed4-f73f01b96431"
/dev/sdb3: LABEL="Backup" UUID="0000678400004823" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="a7187083-2820-4eef-83ff-05d8899879a2"
From the above output results, the disk can be mapped to the specific block device path`/dev/sdax`. Because the computer contains two disks, it contains`sda`and`sdb`. The block device path and`UUID`here will be used in the following configuration parameters.
## 2. Temporary MountFor a temporary solution, you can use the following command to mount`/dev/sda1`to the`/mnt/c`directory```
sudo mkdir /mnt/c
sudo mount -t ntfs /dev/sda1 /mnt/c
3. Auto Mount on Boot### (1). Modify configuration fileThe solution to automatically mount after booting requires modifying the configuration file/etc/fstab. After opening it with an editor, add a new mount item in the following format```¶
$ cat /etc/fstab
/etc/fstab: static file system information.¶
¶
Use 'blkid' to print the universally unique identifier for a¶
device; this may be used with UUID= as a more robust way to name devices¶
that works even if disks are added and removed. See fstab(5).¶
¶
¶
/ was on /dev/sdb5 during installation¶
UUID=4d2e5a83-d9fe-47bb-aa02-fee9ac8535e3 / ext4 errors=remount-ro 0 1
/boot was on /dev/sdb6 during installation¶
UUID=9b521dc2-ad85-4ca6-bb8b-f285b312aa49 /boot ext4 defaults 0 2
/home was on /dev/sdb7 during installation¶
UUID=f6b796dd-9e59-4f79-b70a-c2c8e5977163 /home ext4 defaults 0 2
swap was on /dev/sdb4 during installation¶
UUID=9430ea0e-7ff9-4167-9bf7-1f3e08d26d34 none swap sw 0 0
/mnt/Data was on /dev/sdb2 during installation¶
/dev/sdb2 /mnt/Data ntfs defaults 0 2
/mnt/Backup was on /dev/sdb3 during installation¶
/dev/sdb3 /mnt/Backup ntfs defaults 0 2
The last two items are used to mount the disk. Of course, the`/dev/sdbx`in front of each line can also be replaced by`UUID=xxxxx`. However, since the`UUID`of the two disks are consistent, there may be problems. Maybe you can use the`PARTUUID`output by`blkid`.
### (2). Mount test```
sudo mkdir /mnt/{Data,Backup}
sudo mount -a
Mount SMB/CIFSUse systemd to automatically mount smb at boot```¶
This is a sample service script to mount CIFS/SAMBA shares.¶
Please read carefully the comments in this file. For production usage¶
you can remove all comments (lines beginning with "#") from this file.¶
[Unit]
The description should be used to explain what this servicefile is for¶
Description=nas cifs mount home
if we do network mounts like here we require 'network-online.service'¶
which checks if the network is online¶
Requires=network-online.target
our scripts must start after 'network-online.service', on timeout and if¶
'network-online.service' fails we can not mount and this scripts fails too¶
After=network-online.target
usually we mount networks shares because we want they avaible before XBMC starts.¶
so XBMC has access to this mounts from beginning. Note: this slows down the boot!¶
Before=kodi.service¶
[Mount]
The share we want mount¶
What=//IP_ADDRESS/Data
Where we want mount this share¶
Where=/PATH_TO_MOUNT
Any options you usually use with the "-o" parameter in the mount command¶
Options=username=haoran.qi,password=password,rw,vers=3.0,dir_mode=0775,file_mode=0664
filesystem type¶
Type=cifs
[Install] WantedBy=multi-user.target ```