In this post we will look at how to configure Raspberry Pi as NAS (Network Attached Storage).
Mounting the external hard drive with the appropriate permissions
- Log into raspberry pi (ssh username@ipaddress)
- Update Raspbian by executing following commands
- Install ntfs support
- Find the external hard drive (like sda1, sdb1, sdc1, etc.)
- Before mouning the drives we will need to create a directory to mount to.
- now we need to create a user to login as.
- We need to get the gid and the uid (write these down somewhere, as we will need them in the next step). Update username with the user you created above.
- For the gid enter the following:
- For the uid enter the following:
- Next step is to edit fstab to automatically mount the USB drive automatically with correct permissions when Pi boots up
- Add the following the line to the bottom of the file. Change the /dev/sda1 to whatever your hard drive is and update uid and gid as appropriate. (The code below is all one line)
- Now reboot the Pi and the drive will be mounted with the correct permissions.
sudo apt-get update sudo apt-get upgrade
sudo apt-get install ntfs-3g
sudo fdisk -l
sudo mkdir /media/NASHDD1
sudo useradd username -m -G users sudo passwd password
you will be prompted to enter the password twice
id -g username
id -u username
sudo nano /etc/fstab
/dev/sda1 /media/NASHDD1 auto uid=enter_uid_here,gid=enter_gid_here,noatime 0 0
- Install the samba package
- Before start editing the samba config file take a backup
- Start editing the file by executing the following command
- Firstly, find “#security = user” in the file and remove the # from that line.
sudo apt-get install samba samba-common-bin
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old
sudo nano /etc/samba/smb.conf
Next, add the external hard drive by adding the following commands
[NAS] comment = NAS Folder path = /media/NASHDD1 valid users = @users force group = users create mask = 0660 directory mask = 0771 read only = no
- [NAS]: This is the name of the share (What you will see in file explorer)
- Comment: This is a comment for the associated for share.
- Path: Path to the folder you wish to share.
- Valid User: A list of users that are allowed to login to this share.
- Force Group: This specifies a UNIX group name that will be assigned for all users connecting to this share.
- Directory Mask: This creates a permission mask for all directories created on the drive.
- Read Only: This allows you to set the share to be read only.
- Now restart the samba server by executing the following command
- Finally connect the user to the samba
sudo/etc/init.d/samba restart
sudo smbpasswd -a username
Now we will see how to format in Ext4 format (reference)
Creating data redundancy
This can be achieved in two ways depending on your needs, but both methods will use rsync to sync data between the drives.
Firstly install the rsync package
Firstly install the rsync package
apt-get install rsync
First method backs up the data at a certain specified time of the day, but the second method will update the backup drive as soon a change happens.
Backup at a defined time:
- Install crontab
- sudo apt-get crontab
Backup as soon a change happens
Comments
Post a Comment