Jump to content

Getting a SATA hard drive to mount at boot and sharing whole drive by SMB


Recommended Posts

Posted (edited)

Sorry for what should be help on a basic operation but I'm having real problems trying to share a SATA attached hard drive via SMB. My aim is to try and share the root of the whole 1Tb drive but I have two problems.

1) Getting the drive to mount at startup. (I thought internal and SATA drives did by default but this seems not to be the case

2) Creating a share with guest permissions.

I understand that I should edit the fstb file using the UUID of the disk. I obtained the UUID but there are two listed. One for the whole disk and one for the partition. (Note The hard drive was formatted exFat in windows before being attached as whatever i did i couldn't write to it, something to do with having root permissions. I even tried taking ownership but without success)

here is the blkid command output

/dev/sda1: LABEL="data" UUID="74E3-01BF" BLOCK_SIZE="512" TYPE="exfat" PARTUUID="6c2b2d10-01"
/dev/mmcblk0p1: LABEL="armbi_root" UUID="69fa8a60-c365-456c-8d0a-7889eb4a3713" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="c0cf2841-01"
/dev/zram1: LABEL="log2ram" UUID="7269c460-6283-4374-bcba-be885c806c25" BLOCK_SIZE="4096" TYPE="ext4"
/dev/zram0: UUID="7a1deaea-e26c-45f2-9a73-ac43c6bf301e" TYPE="swap"

 here is my fstb file

UUID=69fa8a60-c365-456c-8d0a-7889eb4a3713 / ext4 defaults,,commit=120,errors=remount-ro 0 1
tmpfs /tmp tmpfs defaults,nosuid 0 0
UUID=74E3-01BF /mnt/data exfat defaults 0 2

I used the disk UUID rather than the partition however the disk is no longer visible when armbian starts. previously it was visible but unmounted. there is an entry in the /mnt/ folder called data. I was also unsure if I should enter the filetype  exfat in the fstb entry as all other example show ext4 before defaults.

 

Please can someone put me right and suggest the correct entry in the smb.conf file. I believe it should be something like this :-

path = /media/kealy/data

available = yes

valid users = kealy

read only = no

browsable = yes

public = yes

writable = yes

 However as there is an entry in the /mnt/ folder should path be /mnt/kealy/data instead?

Finally where should the user password go in the smb.conf or is public= yes is this necessary. The device will only be used in a family household to upload their photos from their phones.

Edited by John Felstead
Posted

OK I think I have learned something. My fstab entry doesn't contain an entry like x-gvfs-show  which i believe makes the disk appear in the UI (desktop icon and in Thunar??

I found this by comparing Gnome Disks settings for the SATA drive, which according to disks is mounted at mnt/data. Good.

So next task is to install and configure SMB to share the root drive on the network ideally without the necessity of entering a password.

 

So path should be /mnt/data?? and do I require Valid Users entry? Finally do I need smbpasswd.. Note users accessing will be from Windows 11 pcs and mobile phones (iOS)

 

path = /mnt/data

available = yes

valid users = kealy

read only = no

browsable = yes

public = yes

writable = yes

Posted

OK thanks @bedna With your help I've made some progress. I followed one of your links to the wiki regarding a standalone server and modified the smb.conf file as below

 

#
# Sample configuration file for the Samba suite for Debian GNU/Linux.
#
#
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options most of which 
# are not shown in this example
#
# Some options that are often worth tuning have been included as
# commented-out examples in this file.
#  - When such options are commented with ";", the proposed setting
#    differs from the default Samba behaviour
#  - When commented with "#", the proposed setting is the default
#    behaviour of Samba but the option is considered important
#    enough to be mentioned here
#
# NOTE: Whenever you modify this file you should run the command
# "testparm" to check that you have not made any basic syntactic 
# errors. 

#======================= Global Settings =======================

[global]
    map to guest = Bad User
    log file = /var/log/samba/%m
    log level = 1
    server role = standalone server
[guest]
# This share allows anonymous (guest) access
# without authentication
path = /srv/samba/guest/
read only = no
guest ok = yes
guest only = yes

## Browsing/Identification ###

# Change this to the workgroup/NT-domain name your Samba server will part of
   workgroup = WORKGROUP

# server string is the equivalent of the NT Description field
   server string = %h server (Samba, Ubuntu)

#### Networking ####

# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
;   interfaces = 127.0.0.0/8 eth0

# Only bind to the named interfaces and/or networks; you must use the
# 'interfaces' option above to use this.
# It is recommended that you enable this feature if your Samba machine is
# not protected by a firewall or is a firewall itself.  However, this
# option cannot handle dynamic or non-broadcast interfaces correctly.
;   bind interfaces only = yes

#### Debugging/Accounting ####

# This tells Samba to use a separate log file for each machine
# that connects
   log file = /var/log/samba/log.%m

# Cap the size of the individual log files (in KiB).
   max log size = 1000

# We want Samba to only log to /var/log/samba/log.{smbd,nmbd}.
# Append syslog@1 if you want important messages to be sent to syslog too.
   logging = file

# Do something sensible when Samba crashes: mail the admin a backtrace
   panic action = /usr/share/samba/panic-action %d


####### Authentication #######

# Server role. Defines in which mode Samba will operate. Possible
# values are "standalone server", "member server", "classic primary
# domain controller", "classic backup domain controller", "active
# directory domain controller". 
#
# Most people will want "standalone server" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
   server role = standalone server

   obey pam restrictions = yes

# This boolean parameter controls whether Samba attempts to sync the Unix
# password with the SMB password when the encrypted SMB password in the
# passdb is changed.
   unix password sync = yes

# For Unix password sync to work on a Debian GNU/Linux system, the following
# parameters must be set (thanks to Ian Kahan <<kahan@informatik.tu-muenchen.de> for
# sending the correct chat script for the passwd program in Debian Sarge).
   passwd program = /usr/bin/passwd %u
   passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .

# This boolean controls whether PAM will be used for password changes
# when requested by an SMB client instead of the program listed in
# 'passwd program'. The default is 'no'.
   pam password change = yes

# This option controls how unsuccessful authentication attempts are mapped
# to anonymous connections
   map to guest = bad user

########## Domains ###########

#
# The following settings only takes effect if 'server role = classic
# primary domain controller', 'server role = classic backup domain controller'
# or 'domain logons' is set 
#

# It specifies the location of the user's
# profile directory from the client point of view) The following
# required a [profiles] share to be setup on the samba server (see
# below)
;   logon path = \\%N\profiles\%U
# Another common choice is storing the profile in the user's home directory
# (this is Samba's default)
#   logon path = \\%N\%U\profile

# The following setting only takes effect if 'domain logons' is set
# It specifies the location of a user's home directory (from the client
# point of view)
;   logon drive = H:
#   logon home = \\%N\%U

# The following setting only takes effect if 'domain logons' is set
# It specifies the script to run during logon. The script must be stored
# in the [netlogon] share
# NOTE: Must be store in 'DOS' file format convention
;   logon script = logon.cmd

# This allows Unix users to be created on the domain controller via the SAMR
# RPC pipe.  The example command creates a user account with a disabled Unix
# password; please adapt to your needs
; add user script = /usr/sbin/useradd --create-home %u

# This allows machine accounts to be created on the domain controller via the 
# SAMR RPC pipe.  
# The following assumes a "machines" group exists on the system
; add machine script  = /usr/sbin/useradd -g machines -c "%u machine account" -d /var/lib/samba -s /bin/false %u

# This allows Unix groups to be created on the domain controller via the SAMR
# RPC pipe.  
; add group script = /usr/sbin/addgroup --force-badname %g

############ Misc ############

# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting
;   include = /home/samba/etc/smb.conf.%m

# Some defaults for winbind (make sure you're not using the ranges
# for something else.)
;   idmap config * :              backend = tdb
;   idmap config * :              range   = 3000-7999
;   idmap config YOURDOMAINHERE : backend = tdb
;   idmap config YOURDOMAINHERE : range   = 100000-999999
;   template shell = /bin/bash

# Setup usershare options to enable non-root users to share folders
# with the net usershare command.

# Maximum number of usershare. 0 means that usershare is disabled.
#   usershare max shares = 100

# Allow users who've been granted usershare privileges to create
# public shares, not just authenticated ones
   usershare allow guests = yes

#======================= Share Definitions =======================

# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each
# user's home directory as \\server\username
;[homes]
;   comment = Home Directories
;   browseable = no

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
;   read only = yes

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
;   create mask = 0700

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
;   directory mask = 0700

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# Un-comment the following parameter to make sure that only "username"
# can connect to \\server\username
# This might need tweaking when using external authentication schemes
;   valid users = %S

# Un-comment the following and create the netlogon directory for Domain Logons
# (you need to configure Samba to act as a domain controller too.)
;[netlogon]
;   comment = Network Logon Service
;   path = /home/samba/netlogon
;   guest ok = yes
;   read only = yes

# Un-comment the following and create the profiles directory to store
# users profiles (see the "logon path" option above)
# (you need to configure Samba to act as a domain controller too.)
# The path below should be writable by all users so that their
# profile directory may be created the first time they log on
;[profiles]
;   comment = Users profiles
;   path = /home/samba/profiles
;   guest ok = no
;   browseable = no
;   create mask = 0600
;   directory mask = 0700

[printers]
   comment = All Printers
   browseable = no
   path = /var/tmp
   printable = yes
   guest ok = no
   read only = yes
   create mask = 0700

# Windows clients look for this share name as a source of downloadable
# printer drivers
[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = no
# Uncomment to allow remote administration of Windows print drivers.
# You may need to replace 'lpadmin' with the name of the group your
# admin users are members of.
# Please note that you also need to set appropriate Unix permissions
# to the drivers directory for these users to have write rights in it
;   write list = root, @lpadmin
[data]
    path = /mnt/data
    read only = no
    browseable = yes
    writeable = yes
    create mask = 0777
    directory mask = 0777

I've inserted the global settings as found in the wiki and an entry [data] for the share as above.  I can now see the share from windows but could not connect due to a windows security policy for guest users. I therefore ran 

sudo smbpasswd -a your_username

to add the local user to samba. This allowed me to connect to the share using the local user account. However i have two issues:-

1) Whilst i can browse the share I cannot write to it from windows.

2) There is a second share named guest which has appeared. See (attachment)

I can only think this is something to do with the global entry at the beginning of the smb.conf? Which entry should i remove from smb.conf to remove this share (everything in [guest] ?? ) as clearly guest only access is not working from windows.

 

As regards writing to the share I have tried running

chmod -R 777 /mnt/data/

this appears to finish without errors but I still cannot write to the share from windows. Could this be because the file system is exFat?

If I try and convert the partition to Ext4 then I need to run gnome-disks as Sudo and afterwards I still cannot access the share on the pi with the local user permissions. I am therefore stuck.

 

Any suggestions as to change the permissions to allow write access to the share please?

Screenshot 2026-03-26 140507.png

Posted (edited)

I haven't used samba for a long time so I'm probably not the best to ask, but I checked my old notes about samba, and this was my goto config:

[samba] # edit, or whatever name you want to give it
path = /path/to/mountlocation/
browsable = yes
writable = yes
read only = no
force user = <your_username>
force group = <your_usergroup>
create mask = 0644 # edit, you should probably set this to 0640. This is for files, no need for 7 here, unless you want every file to be executable on the samba share?
direcotry mask = 0755 # make sure this works on debian, errors on arch (edit, this was in my notes, so I guess 755 instead of 0755.. maybe.. Or rather 0750 or 750 to only give access to your user and group)
public = no

 

This was the only thing I changed from default IIRC, so no guest access or anything, just a uname and passwd to connect.

 

Changing the directory permissions on the server filesystem (chmod) does not matter at all when it comes to samba. As you can see in the conf I provided, the mask is defined there, and all files will get that user/mask (if ext4, exfat does not support user/group/all masks, what you see in your filesystem is what you set in fstab for exfat) and is the mask you will se when looking through a samba mount on another computer.

 

And as a rule of thumb, don't use 777 or 666, the solution is very rarely to completely open up everything, that's a "windows thing" (run as administrator or give everybody access to the directory/application), try to get rid of that habit.

Edited by bedna

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines