Samba

From Gentoo Wiki
Jump to: navigation, search

Samba is a re-implementation of the SMB/CIFS networking protocol, a Microsoft Windows alternative to Network File System (NFS).

Installation

Kernel

Activate the following kernel options:

KERNEL Enable CIFS
File Systems --->
    [*] Network File Systems --->
        [*] CIFS support (advanced network filesystem, SMBFS successor)--->
            [*] CIFS Statistics
                [*] Extended Statistics
            [*] CIFS Extended Attributes
                [*] CIFS POSIX Extentions

Optional: Make sure to enable the filesystems you want to mount later on

KERNEL SMB2 and SMB3 Support
File Systems --->
    [*] Network File Systems --->
        [*] CIFS support (advanced network filesystem, SMBFS successor)--->
            [*] SMB2 and SMB3 network file system support
Note
If you see errors like CIFS VFS: Unknown vers= option specified: 2.1 with dmesg, you might have not enabled the SMB2 option in the kernel.

Samba

USE flags

USE flags for net-fs/samba Samba Suite Version 4

acl Add support for Access Control Lists global
addc Enable Active Directory Domain Controller support local
addns Enable AD DNS integration local
ads Enable Active Directory support local
client Enables the client part local
cluster Enable support for clustering local
cups Add support for CUPS (Common Unix Printing System) global
dmapi Enable support for DMAPI. This currently works only in combination with XFS. local
fam Enable FAM (File Alteration Monitor) support global
gnutls Add support for net-libs/gnutls (TLS 1.0 and SSL 3.0 support) global
iprint Enabling iPrint technology by Novell local
ldap Add LDAP support (Lightweight Directory Access Protocol) global
pam Add support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip global
quota Enables support for user quotas local
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur global
syslog Enable support for syslog global
system-mitkrb5 Use app-crypt/mit-krb5 instead of app-crypt/heimdal. local
systemd Enable use of systemd-specific libraries and features like socket activation or session tracking global
test Workaround to pull in packages needed to run with FEATURES=test. Portage-2.1.2 handles this internally, so don't set it in make.conf/package.use anymore global
winbind Enables support for the winbind auth daemon local
zeroconf Support for DNS Service Discovery (DNS-SD) global

Emerge

Emerge Samba:

root #emerge --ask net-fs/samba

Samba can also be installed by setting the global USE flag samba and updating the system:

root #emerge -avtDNu world

CIFS

USE flags

If the full Samba package is not needed, the net-fs/cifs-utils package is available:

USE flags for net-fs/cifs-utils Tools for Managing Linux CIFS Client Filesystems

acl Add support for Access Control Lists global
ads Enable Active Directory support and create cifs.idmap binary - idmap support local
caps libcap support local
caps-ng libcap-ng support local
creds cifs credentials support local
pam Add support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip global

Emerge

Emerge the CIFS user-space tools:

root #emerge --ask net-fs/cifs-utils

Usage

Services

OpenRC

When using OpenRC, adding Samba to the default runlevel will enable the Samba service to start when the system boots:

root #rc-update add samba default

To start the Samba service now issue:

root #service samba start

Systemd

For systemd users, the Samba service can be configuired to start during boot using systemctl:

root #systemctl enable smbd.service

To start the service immediately issue:

root #systemctl start smbd.service

CIFS share

Mount the shared content

Once the client is fully configured, the shares can soon be accessed.

Create the mount point:

root #mkdir -p /mnt/My-Disk/{Media,Shared}

Mount the exported folders:

root #mount.cifs //O2-Foobar/Media /mnt/My-Disk/Media -o guest
root #mount.cifs //O2-Foobar/Shared /mnt/My-Disk/Shared -o guest

To automatically mount shares on every boot, edit /etc/fstab to look like this:

FILE /etc/fstab
//O2-Foobar/Media  /mnt/My-Disk/Media  cifs guest
//O2-Foobar/Shared /mnt/My-Disk/Shared cifs guest
Note
  • In the case of permission problems are encountered when trying to create files and folders on the disk, try to use gid=<user's_gid>, uid=<user's_uid>
  • Be sure to replace <user's_gid> with the user ID of choice.

Troubleshooting

Some problems may occur when trying to mount new CIFS shares. The following sections attempt to provide resolutions to common problems.

Cannot resolve <server-name>

More specifically, the actual error:

root #mount.cifs ...
"mount error: could not find target server. TCP name foo/bar not found. No ip
address specified and hostname not found"

This can easily be fixed by editing /etc/nsswitch and appending wins next to the hosts entry:

FILE /etc/nsswitch
hosts: files dns wins

If this does not work, use the NFS server's IP address instead of the O2-Foobar hostname. The nmblookup utility (provided by net-fs/samba) comes in handy when trying to find the IP address of an NFS host:

root #nmblookup O2-Foobar

Shutdown process hangs when trying to unmount CIFS shares

If the system shutdown hangs at

* Unmounting network filesystems ...

then users must make sure the CIFS shares are unmounted properly before udev tries to stop. One way to work around this is to create local.d scripts to unmount the CIFS filesystems:

root #echo "umount -a -t cifs -f" > /etc/local.d/cifs.stop
root #chmod a+x /etc/local.d/cifs.stop

Windows asking for passwords

security = share


When you can't start samba and get this errors ( in my case after upgrade from samba-4.2.9 to samba-4.2.11) :

../lib/param/loadparm.c:1082(lp_set_enum_parm)
WARNING: Ignoring invalid value 'share' for parameter 'security'
../source3/smbd/server.c:1256(main)
error opening config file '/etc/samba/smb.conf'

Change global security to:

security = user 

To keep windows users access without username/password:

map to guest = bad user

Emerge wants to downgrade to Samba 3 because of FFmpeg dependency

This is probably caused by enabling abi_x86_32 on media-video/ffmpeg, which isn't supported on Samba 4. Since Samba support is rarely needed by media-video/ffmpeg (in the typical use case, the media player itself handles media files served over smb), the samba USE flag can be disabled for media-video/ffmpeg without losing essential functionality.

See also

External resources