owenclements
Posts: 1
Joined: Tue Aug 06, 2019 7:50 am

Samba share whole external drive

Tue Aug 06, 2019 7:52 am

What do I have to do to share an whole external USB hard drive with all folders and files via Samba for the network under Raspbian? All the way from installing Samba to setting it up.

LTolledo
Posts: 6657
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Samba share whole external drive

Tue Aug 06, 2019 2:32 pm

for starters...search the internet regarding installing and configuring samba (believe me, there are numerous sites on the wild wild web)
then read and fully understand the instructions on those web pages

once its up and running and you encounter some road blocks, come back here and some of us will guide you what to do next...

the next move is yours to make...
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

hippy
Posts: 12693
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Samba share whole external drive

Tue Aug 06, 2019 3:21 pm

As said, follow one of the numerous guides already written. Get it working how you want with 'something' shared from the SD Card, adjust that to share the whole card, then adjust again for sharing the whole external disk.

It is basically -

Code: Select all

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install samba
sudo smbpasswd -a pi

Code: Select all

sudo nano /etc/samba/smb.conf
sudo systemctl restart smbd
Repeat the last two until you have it working how you want.

jeremykhardin
Posts: 1
Joined: Tue Aug 06, 2019 5:04 pm

Re: Samba share whole external drive

Tue Aug 06, 2019 5:37 pm

Hi there.

For my uses, I set this up to auto mount the USB drive on boot, always to the same location, and share that location in samba (for my windows machines) and in nfs for the linux machines here. I haven't focused on security on the local network, so that's a whole different topic.

This guide is useful for getting samba set up:
https://www.raspberrypi.org/magpi/samba-file-server/

The key for me was making sure that the permissions on the share directory were set correctly. At first I made the share directory with this command, which didn't work even after changing the permissions after the fact:

Code: Select all

mkdir /share
But if I followed the instructions in the above link when creating the directory, problems went away:

Code: Select all

sudo mkdir -m 1777 /share
If it's a clean/empty USB drive and you want to format it, you can use gparted. I used the ext4 file format for the USB drive to avoid permissions issues. Since the raspberry pi has the same permissions, it was able to share those permissions over samba and nfs. (Originally I tried using exfat and was able to get either windows samba sharing or nfs sharing working, but struggled to get both working and reliable without gotchas. So ext4 it was.)
This youtube tutorial covered the gparted side of things:
https://www.youtube.com/watch?v=JYvUQXfiTz8

So with the drive mounting, and with smb.conf sharing the mount point, I edited /etc/fstab. I did brick my pi for a brief while with this, so obviously do at your own risk. (FWIW, the nofail part was my lucky fix. with nofail added in my new fstab entry, the pi was unbricked.)

This was the guide I followed for fstab:
https://www.raspberrypi.org/documentati ... storage.md

It's worth noting, though, that umask doesn't work with ext4, so I deviated from the instructions there. This was the link that told me why:
https://ubuntuforums.org/showthread.php?t=1376379

Testing the fstab is worth doing rather than rebooting every time, and you can test the fstab mounting by running:

Code: Select all

sudo mount -a
If that fails, you can test why it failed by using this command:

Code: Select all

dmesg |tail -20
Which I found in this thread:
https://ubuntuforums.org/showthread.php?t=1294786

After fstab is set up to use the UUID of the external drive, it should auto mount on boot and share over samba.

As I said, do at your own risk, etc. And I make no claims as to the security or safety of these steps!

Hopefully this helps.


User avatar
DougieLawson
Posts: 42288
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: Samba share whole external drive

Thu Aug 08, 2019 7:07 am

You'll want the drive mounted at boot time. So you either need to add a line to /etc/fstab (complete with the nofail option) or create a Systemd mount file.

You need to find the UUID for the device. Use the blkid command. Note I'm using a root shell started with sudo -s so I don't have to prefix every command with sudo.

Code: Select all

root@eagle:~# blkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="xxxx-yyyy" TYPE="vfat" PARTUUID="zzzzzzzz-01"
/dev/mmcblk0p2: UUID="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" TYPE="ext2" PARTUUID="zzzzzzzz-02"
/dev/sda1: UUID="qqqqqqqq-rrrr-ssss-tttt-uuuuuuuuuuuu" TYPE="ext2" PARTUUID="aabbccdd-01"
/dev/mmcblk0: PTUUID="zzzzzzzz" PTTYPE="dos"
root@eagle:~#
Your PARTUUIDs and UUIDs will be hex strings.

So /dev/sda1 is /dev/disk/by-uuid/qqqqqqqq-rrrr-ssss-tttt-uuuuuuuuuuuu

So the /etc/fstab line would look like

Code: Select all

UUID=qqqqqqqq-rrrr-ssss-tttt-uuuuuuuuuuuu /share ext4 defaults,nofail 0 0
Or we can mount with System (the rule is the *.mount file needs to match the mount point name with '/' changed to '-' if needed.
/etc/systemd/system/share.mount

Code: Select all

[Unit]
Description=Mount share directory
#
# Replaces this line in fstab
#UUID=qqqqqqqq-rrrr-ssss-tttt-uuuuuuuuuuuu /share ext4 defaults,notfail 0 0
#
[Mount]
What=/dev/disk/by-uuid/qqqqqqqq-rrrr-ssss-tttt-uuuuuuuuuu
Where=/share
Type=ext4
Options=defaults

[Install]
WantedBy=multi-user.target
Which you enable (for the next boot) with systemctl enable share.mount and activate with systemctl start share.mount
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

Kingjacob280
Posts: 2
Joined: Sat Jan 18, 2020 5:52 am

Re: Samba share whole external drive

Sat Jan 18, 2020 5:54 am

Intro:
This document will explain:
How to install a SAMBA server on Raspbian OS
Mount an external hard drive to Raspbian OS
Maintain mounted hard drive after Pi reboot
Shear external hard drive on SAMBA server

Commands:
SAMBA Install:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install samba
sudo smbpasswd -a pi
sudo service smbd restart

After Hard Drive Mount:
sudo nano /etc/samba/smb.conf
ADD: (at the bottom of the file):
------------------------------------------
[RaspberryPi NAS]
comment = Pi Server
public = no
writeable = yes
browsable = yes
path = /mnt/external-disk
create mask = 0777
directory mask = 0777
-------------------------------------------
(CTRL+X) then (Y) then (ENTER)
sudo service smbd restart

FTFS Support:
sudo apt-get install ntfs-3g

External Hard drive mount:
sudo blkid
sudo mkdir /mnt/external-disk
sudo mount /dev/sda1 /mnt/external-disk
ls /mnt/external-disk/
sudo blkid
sudo nano /etc/fstab
ADD: “UUID=DE94190D9418EA33 /mnt/external-disk NTFS defaults,auto,users,rw,nofail,x-systemd.device-timeout=30,umask=000 0 0” (UUID from the blkid list)
sudo reboot now
ls /mnt/external-disk/



Other Commands - In case of errors:
sudo umount /dev/sda1
fstab 2nd option: /dev/sda1 /mnt/location ntfs defaults 0 0
Target is busy:
sudo apt update
sudo apt install lsof
lsof /mnt/location

Commands with explanation:
SAMBA Install:
sudo smbpasswd -a pi (Set SAMBA password)
sudo service smbd restart (Restart service so changes take effect)


External Hard drive mount:
sudo blkid (List hard drive partitions and their respective names, this is used for locating and mounting them)
sudo mkdir /mnt/external-disk (Make a folder so the external hard drive can be mounted, this is the location the hard drive files folders/files will show up, a bit like “This PC” in windows.)
sudo mount /dev/sda1 /mnt/external-disk (Mount the hard drive to the new folder, marked in red is the name location of the hard drive you will want to mount, this might change)
Ls /mnt/external-disk/ (Check that the files/folders in the external drive are showing up, you will want to have placed some files in the drive so you can confirm this.)
sudo nano /etc/fstab (This is the file that tells the OS what hard drives to mount on startup)
sudo reboot now (Reboot the Pi to check if this is working)
Ls /mnt/external-disk/ (Again this is used for checking the files/folders)

chipace
Posts: 198
Joined: Sat Jun 29, 2019 2:56 am
Location: brown paper bag in a septic tank

Re: Samba share whole external drive

Sat Jan 18, 2020 5:09 pm

If you run into issues with how clients mount the samba share (under linux), be aware that proper uid and gid are required in order to keep permissions, timestamps and file attributes when copying them to the samba server. In one case I needed to use "gcp" instead of cp to retain my timestamps. I have a rpi_zero client that automatically backs up iphone photos to the samba server, and I needed "gcp" to keep the original timestamps.

In my opinion, you are making the best low-cost, low-power file server there is today. My 1GB RPi4 serves files for me and my family... the same box plays 4k videos on the TV it is attached to, downloads legal-ish torrents and is a sftp and ssh server to the external world (with fail2ban).

I have 2 external drives connect to my RPi4, each configured as samba shares without any issue.
I have 30 minute timers configured locally on the external drives for them to spin down (save power).
I also have one off-site backup (remember to always have 3 copies of all your important data, including one off-site).

john_k
Posts: 4
Joined: Sun Dec 16, 2012 10:11 pm

Re: Samba share whole external drive

Thu Apr 02, 2020 10:37 pm

Hi

I wondered what script you ran for the 30 min timer to close down the drives?

Return to “General discussion”