Follow by Email

Blog Archive

Search This Blog

Samba shares and mount - fstab

Samba share always consists of two side. The server side and the client side. The Samba server was configured successfully in the best case. Now it's about setting up or automatically mount the shared directory to the local file system of a client or other server.
Share it:
Samba shares and mount / unmount automatically with "fstab"
Samba shares and mount

In principle, a Samba share always consists of two side. The server side and the client side. The Samba server was configured successfully in the best case. Now it's about setting up or automatically mount the shared directory to the local file system of a client or other server.
Task
  • Check if the kernel supports the Samba file system.
  • Check access to the remote Samba file system.
  • Create a mount point on the client.
  • Create an entry in the file "/ etc / fstab".
  • Check if the Samba shares are automatically included.
preparations
  • In order to mount Samba shares, they must be set up beforehand.
  • Make sure that the shared directories on the Samba server contain files or other directories so that you can really check later if the shares have been incorporated correctly.
  • Set up Samba sharing on Raspberry Pi
Solution: Check available support for file systems
For a file system to be recognized and mounted on a drive, the appropriate file system modules must be installed. For this purpose, one should check which file systems the running kernel supports.
ls -1 / lib / modules / $ (uname -r) / kernel / fs

In order to access Samba shares, one needs the file system "cifs", which is contained in the package "cifs-utils" and which should be present at Raspbian Jessie. If not, then you can install it later.
sudo apt-get install cifs-utils

Solution: Check remote Samba share
First, we should check if the samba share is even reachable. For this we install a Samba client for the command line, if it is not already installed.
sudo apt-get update
sudo apt-get install smbclient

Command to check if the Samba shares are reachable:
smbclient -N -L //192.168.1.2/
smbclient -N -L raspberrypi

Now we go one step further and check if a user login is possible.
smbclient -U pi -L //192.168.1.2/

The command line will probably ask for a password. This is the password that the user got "pi" in the Samba user administration. Not the local user, but really the samba user.

Solution: Create a mount point
To include a share, you must first create a mount point. This can in principle be selected at any point in the file directory. However, the usual procedure is as follows:
  • System-wide integration: The mount point must be owned by root.
  • Personal integration: The mount point must be the property of the respective user. It is recommended to create an empty folder in its home directory.
Create mount points in the user directory:
//mkdir -p / home / pi / shares / test
mkdir -p / home / pi / shares / users
mkdir -p / home / pi / shares / pi
Solution: Create an entry in the file "/ etc / fstab" (Raspbian Wheezy)
Now it's about assigning the partition or the file system to a mount point in the file "/ etc / fstab". To do this, we open the following file:
sudo nano / etc / fstab

Enter the following lines:
//192.168.1.2/SambaTest/home/pi/shares/test cifs defaults, noauto, nofail, username = pi, passwd = raspberry 0 0
//192.168.1.2/SambaUsers/home/pi/shares/users cifs defaults, noauto, nofail, username = pi, passwd = raspberry 0 0
//192.168.1.2/SambaPi / home / pi / shares / pi cifs defaults, noauto, nofail, username = pi, passwd = raspberry 0 0

Please note that the IP address, user name (option "username"), password (option "passwd"), the shares and mount points have to be adapted to your scenario.

If you have made or changed the entry, then save the file and close it with Ctrl + O, Return, Ctrl + X.

Then you can mount / mount the shares manually. The new entries in the file "/ etc / fstab" are automatically taken into account.
sudo mount -a

Check if the shares have been mounted.
lsblk

ls / home / pi / shares / test
ls / home / pi / shares / users
ls / home / pi / shares / pi

Note that these directories exist on your local system and are used as mount points. Only if the local directory content matches that on the Samba system, then the shares were successfully mounted.

Check whether the Samba shares are automatically included after a restart.
reboot

In the best case, the shares are automatically integrated already at system startup.

Solution: Create an entry in the file "/ etc / fstab" (Raspbian Jessie)
Now it's about assigning the partition or the file system to a mount point in the file "/ etc / fstab". To do this, we open the following file:
sudo nano / etc / fstab

Enter the following lines:
//192.168.1.2/SambaTest/home/pi/shares/test cifs defaults, noauto, nofail, username = pi, passwd = raspberry, x-systemd.automount, x-systemd.requires = network-online.target 0 0
//192.168.1.2/SambaUsers/home/pi/shares/users cifs defaults, noauto, nofail, username = pi, passwd = raspberry, x-systemd.automount, x-systemd.requires = network-online.target 0 0
//192.168.1.2/SambaPi / home / pi / shares / pi cifs defaults, noauto, nofail, username = pi, passwd = raspberry, x-systemd.automount, x-systemd.requires = network-online.target 0 0

Please note that the IP address, user name (option "username"), password (option "passwd"), the shares and mount points have to be adapted to your scenario.

Note: The mount options "x-systemd.automount, x-systemd.requires = network-online.target" will not attempt to mount unless the network connection is available and is being mounted before the network connection is terminated ,

If you have made or changed the entry, then save the file and close it with Ctrl + O, Return, Ctrl + X.

Then you can mount / mount the shares manually.
sudo mount -a

Check if the shares have been mounted.
lsblk

ls / home / pi / shares / test
ls / home / pi / shares / users
ls / home / pi / shares / pi

Note that these directories exist on your local system and are used as mount points. Only if the local directory content matches that on the Samba system, then the shares were successfully mounted.

Check whether the Samba shares are automatically included after a restart.
reboot

In the best case, the shares are automatically integrated already at system startup.

Problem: Entries in the file "/ etc / fstab" are not included at system startup
The entries in the file "/ etc / fstab" should be included automatically at system startup. However, the condition is that the drive is available when processing the file. That is, the physical drive must be recognized and initialized, or in the case of a Samba share, the network connection must be available. That's never the case. And that's why you stumble over it. That means you have to somehow make sure that the Samba releases are subsequently incorporated.

What works in any case is to subsequently integrate the shares manually with "sudo mount -a". However, this is exactly what you want to avoid because it is a manual intervention. Actually, you want it to work automatically.

It's easy with Raspbian Jessie. Here it is enough to add "x-systemd.automount, x-systemd.requires = network-online.target" to the fstab line in the mount options.

If you have Raspbian Wheezy, then you have to wait with the mount until the network is "booted up". To execute a command such as "mount -a" just before the boot process is complete, use the file "/etc/rc.local".
The file "/etc/rc.local" is executed relatively late in the boot process, almost just before the login prompt. With Raspbian, a line for the output of the IP address is entered by default in this file.
sudo nano /etc/rc.local

...
mount -a
exit 0

However, the problem here is that it can not be guaranteed that a network connection is already possible. So it can happen that the file "/etc/rc.local" is executed before, for example, the WLAN is started up.
You can use it to install a delay until the network connection is established.
...
sleep 20
mount -a
exit 0

The "sleep" command delays the further processing of "/etc/rc.local" in seconds. The value given here must be found out by trial and error. It can be different for every system.
Share it:

Raspberry Pi

Post A Comment:

0 comments: