I set up my Rasberry Pi as a network attached storage. It's currently running a Samba server so that it behaves like a Windows file share.
I've been doing a lot of networking & security lately for my day job. This includes stuff like creating static routes, and a simple PKI for an OpenVPN Site-To-Site implementation.
This has been a great learning experience for me, as I finally put a lot of theory into practice with regards to networking.
I'll write a post about OpenVPN Soon™.
Before I concern myself with creating a personal VPN for my own home, I figure I should first host a service that I want to make accessible from the WAN.
The first thing I'm going to do is create a Samba share, AKA a Windows Network File Share.
Nothing fancy. I have a rasberry pi that is currently hosting a few IRC & Discord bots. I also have a 1TB USB HardDrive lying around, not being used for anything.
The story with this hard drive is that I originally bought it as a teenager so that I can develop games "on the go". The plan was to host all the assets & code on this single hard drive... with no backups.
As you can guess, the hard drive pooped the bed during my 3rd learning project. I learned the value of backups after that, hahaha.
Mind you, this was before I learned about Git & source control.
We can create a file share using practically any computer. I've plugged my USB hard drive into my Raspberry Pi.
My Pi is running ubuntu 20.04 LTS at the moment.
First thing I had to do was figure out how to mount this thing as a storage device on my Pi. 🤔
I immediately ran into an issue with my Pi not detecting the USB hard drive. I think this was caused because I had plugged in the HDD and left it alone for several minutes.
I noticed that the HDD was blinking in a very slow pattern. So, I unplugged it and plugged it back in and it worked :)
I was finally able to see it represented in the output when I type lsblk
The next step is mounting the disk to a folder in /media. I'm going to call mine external_drive. So, I made the folder in /media.
Mounting the disk is as simple as typing:
sudo mount /dev/sda1 /media/external\_drive/
but we want it to stick around even after we reboot the Pi. So, what we actually want is to mount it automatically on startup.
According to Linux Config , we should use the disk's UUID, which we can get by entering:
ls -l /dev/disk/by-uuid/*
In my case, I can see that the disk I'm trying to access is UUID FC8...
So, all I have to do now is edit the /etc/fstab file, which you can read up on here.
I ran into some speed bumps, but after formatting the HDD to ext4, auto-mounting was successful. 👍
This is the fun part. Now that the HDD is in place to be used by the Rasberry Pi, we can host an SMB server.
I created some users via sudo useradd
Finally, created some folders in the /media/external_drive directory and updated the /etc/samba/smb.conf file to include these lines:
[Public Files]
path = /media/external\_drive/public
writable = yes
browsable = yes
read only = no
guest ok = yes
[Our Share]
path = /media/external\_drive/our\_share
writable = yes
browsable = yes
read only = no
guest ok = no
valid users = user1 user2
[My Files]
path = /media/external\_drive/share1
writable = yes
browsable = yes
read only = no
guest ok = no
valid users = user1
[Your Files]
path = /media/external\_drive/share2
writable = yes
browsable = yes
read only = no
guest ok = no
valid users = user2
Finally, restart all of the services for SMB.
sudo systemctl restart smbd.service
sudo systemctl restart nmbd.service
sudo service smbd restart
If you need any help, check out the article that guided me the most: link here.
If you have any questions or want me to elaborate on any of this, please leave a comment!
Thanks for reading :)