Mounting samba on Linux. Until it mounts at startup.

I want to mount samba. Anyway, I want to mount it at startup.

The environment is Raspberry Pi OS 10.7 of Raspberry Pi 4 Since I started studying the samba server, a summary of what I did before mounting it. I mounted it with the mount command → described it in fstab and mounted it automatically at startup.

Basics of mount command

The basis of the mount command is

$ mount -t <File system type> <device> <Mount point>

Type to be specified with option-t

The option -t specifies the type of file system. What is a file system? The type that should be specified in the samba mount this time is `` `-t cifs```.

In order to specify cifs in the file system, cifs-utils must be installed, so let's check it for the time being.

$ apt list cifs-utils
List display...Done
cifs-utils/stable,now 2:6.8-2 armhf [Installation complete]

Mostly it should be installed with smbclient.

What to specify with option -o

The mount command also has options such as -r`` -w, but it is not used. All other small options are listed after -o, separated by commas, such as -o

mount.cifs options

-If t cifs is specified, mount.Since cifs is called, you have to look at that option.


 I understand that the options available will change because the behavior is different depending on the file system.

 About mount.cifs
http://www.samba.gr.jp/project/translation/3.5/htmldocs/manpages-3/mount.cifs.8.html

 So what you should write after -o is
```-o user=<username>,password=<password>```
 Is the minimum required first.


 + Other candidates to write
 + `rw` (something that allows you to read and write. I didn't work and used ↓)
 + `file_mode = 664` (Specify permissions for mounted files)
 + `Dir_mode = 775` (Specify permissions for mounted directories)
 + `uid = <username>` (Make the mounter an arbitrary user)
 + `gid = <group name>` (make the group of things to be mounted an arbitrary group)


 Let's organize up to this point and connect the parts made up to this point.
```mount -t cifs -o user=<username>,password=<password>,file_mode=664,dir_mode=775```


### Run mount

 In order to mount it, you need a directory in the mounting location, so create it under/mnt.
```# mkdir -m 777 /mnt/<Mount point>```

 You can finally mount it.

mount -t cifs -o user=,password=,file_mode=664,dir_mode=775 /// /mnt/


 Verification
```$ df -th```


 Unmount
```$ unmount /mnt/<Mount point> ```



## Write in/etc/fstab and mount at startup

 / etc/fstab is a file that describes the device to mount and the file system and is read at boot time.


### fstab basics
 The description is


 `<dump>` is `0 ~ 1`
 `<fsck>` is `0 ~ 2`
 Enters.
 I'll leave that role here, and put both `0`s if you're thinking of mounting samba.

 The rest is the same as the description when mounting with the mount command.
 The file system is `cifs`
 Options are written after `-o`, separated by commas.

### Have systemd automount remote filesystems

 If you want the remote filesystem to be mounted at boot time, let systemd mount it automatically.

`_netdev,x-systemd.automount`
 Just write these two options and it will wait for the network to come online and then systemd will mount it nicely.

 I read the technique around here in the fstab page of ArchWiki in an easy-to-understand manner.
https://wiki.archlinux.jp/index.php/Fstab


### I don't want to write the password in/etc/fstab
 `/ etc/fstab` is probably a file that should be accessible to many people, and I don't want to write the password there.

 In such a case, use the `credentials = <path>` option and prepare a separate file that describes the user and password information so that it can be read.

 This time, I will create a directory called `smb-credentials` in`/etc` and create a file called `.password1` in it.
 Manage your permissions properly.

 The format to be described in `.password1` is as follows.

username= password=


### Description in fstab

 Describe it in `/ etc/fstab`.

/// /mnt/ cifs _netdev,x-systemd.automount,credentials=/etc/smb-credentials/.password1,file_mode=664,dir_mode=775 0 0


 Success if you can mount it with `reboot`.






Recommended Posts

Mounting samba on Linux. Until it mounts at startup.
Build a Samba server on Arch Linux
Until you install Arch Linux on VMware
Set the startup script on Linux (RasPi, Edison)