Introduction: PI Hard Drive NAS
Do you already have a PI 3 ? I use mine to host a local web server for grammar and style checking. However, I also use it for a local NAS, networked attached storage. You can find lots of documents for setting up a PI. In the following document, I assume you already have a running PI.
Writing to a hard drive is faster than writing to a USB flash drive. I bought a new 500 GB 2.5" hard drive. I also spent about $12 for a USB 3.0 SATA case for the drive. I use a standard USB A to A male cable to connect it to one of the PI's USB 2.0 ports. Make sure your power supply for the PI has a capacity of 2.5 amps, 5 volts. The hard drive will get its power through the USB cable. Plug in the drive and attach the USB cable to the PI. You should heard the hard drive spin up. A 2.5" hard drive only draws about half an amp during operation. It will stop spinning when not in use, so the drive should not overload a 2.5 amp or greater 5 volt power supply.
I use putty to login with ssh to the PI's terminal using the password for user pi. The default password is raspberry. You should always change default passwords. To give the user pi a unique password use the passwd command.
sudo passwd pi
Now let's prepare the hard drive.
sudo fdisk -l
I see five /dev/mmcblk0px partitions for the pi's micro SD card.
The hard drive showed up as /dev/sda
I wrote down the partition UUID for the hard drive. Now we will use fdisk to partition the drive as an external, primary (non bootable) drive.
sudo fdisk /dev/sda
This gives you a menu of fdisk commands
to print the current partition info
to create partition, type
select a primary partition
select the first partition
hit ENTER twice to answer questions for the beginning and ending blocks.
check the partition by printing the partition table
the default is 83 Linux.
You could use a FAT32 or NTFS partition type. However, you will run into permission problems. A Linux file system will allow you to control the read and write permissions.
to write the partition table and exit.
make sure the drive is not mounted
now format the drive as ext4
sudo mkfs.ext4 /dev/sda1
sudo ls -al /dev/sda1
sudo id -g pi
this gives the id for the pi group, which is 1000
sudo id – u pi
this gives the id for the pi user, which is 1000
Now edit fstab to auto mount the hard drive
sudo nano /etc/fstab
add this to the bottom of the file.
dev/sda1 /media/HD1 auto nofail uid=1000 gid=1000, noatime 0 0
o to write the file
x to quit nano.
Make sure samba is installed.
sudo apt-get install samba samba-common-bin
sudo smbpasswd -a pi
I use the user pi's password for remote file access. The default is raspberry but you should have changed it.
Now edit /etc/samba/smb.conf
sudo nano /etc/samba/smb.conf
add this to the bottom of the file. I call my share PI3.
pi drive path=/media/HD1
Create a directory for your share.
sudo mkdir /media/HD1
sudo mkdir /media/HD1/Documents
sudo chown -R pi /media/HD1
ls -al /media/HD1/Documents
Make sure the owner is pi.
From your Windows 10 computer, use File Explorer to look for your PI3 share. Click on the network icon on the lower left. Then turn on network sharing by click on the bar at the top. You should see your PI3 share show up.
You can access the files on the pi NAS using the Windows File Explorer using the PI user name and password. I use use the free version of Allway Sync windows program to sync specific directories to clone directories created on the PI's external hard drive. https://allwaysync.com/ You can use it to propagate all file changes in the specified directories to their clones on the PI NAS. In Allway Sync, you will need to create a new job, \\RASPBERRYPI\PI3\Documents and give the PI user name and passwords to access the share.Warning, make sure the ARROW points from the Windows directory to the PI share for sync.
On the pi you can check the space on your NAS drive
sudo df -h /dev/sda1
Enjoy your new PI NAS. It is fast and cheap. You can still use your PI for all its other uses.