A little while ago I had a Netgear ReadyNAS unit which was faulty and wasn’t able to repair it however I thought it would be worth re-using the case to make my own NAS using the Raspberry Pi. I decided to build my own SMPS to provide 5V and 12V to the drives and the Pi and I’m using USB hub with 4x USB to SATA adapters to connect to the 4 hard drives.
https://www.youtube.com/watch?v=-9CjN0F9VXo
(how it all looks at the moment)
After hooking up an 16×2 LCD display to the Pi, I made a start up script in Python to check the drives, assemble the array, mount it and then display the RAID status and free space (see the video above).
lcd.message("NAS4Pi v1.0\nBooting...") time.sleep(5) # Check Disks at start up hdds = ['/dev/sda', '/dev/sdb', '/dev/sdc', '/dev/sdd'] for hdd in hdds: checkdisk1 = subprocess.check_output("/usr/sbin/smartctl -a "+hdd+" | grep Reallocated_Sector_Ct | awk 'NR==1 {print $10}'", shell=True) print hdd+" - Reallocated_Sector_Ct is", checkdisk1[:-1] checkdisk1int = int(checkdisk1) checkdisk2 = subprocess.check_output("/usr/sbin/smartctl -a "+hdd+" | grep Current_Pending_Sector | awk 'NR==1 {print $10}'", shell=True) checkdisk2int = int(checkdisk2) print hdd+" - Current_Pending_Sector is", checkdisk2[:-1] checkdisk3 = subprocess.check_output("/usr/sbin/smartctl -a "+hdd+" | grep Offline_Uncorrectable | awk 'NR==1 {print $10}'", shell=True) checkdisk3int = int(checkdisk3) print hdd+" - Offline_Uncorrectable is", checkdisk3[:-1] lcd.clear() lcd.message("Check "+hdd) if (checkdisk1int == 0 and checkdisk2int == 0 and checkdisk3int == 0): print "- Passed" lcd.message("\nPassed") else: print "- Failing" lcd.message("\n*** Failing ***") time.sleep(1) lcd.clear() lcd.message("Check "+hdd) lcd.message("\nRealloc: ") lcd.message(checkdisk1[:-1]) time.sleep(1) lcd.clear() lcd.message("Check "+hdd) lcd.message("\nCurPend: ") lcd.message(checkdisk2[:-1]) time.sleep(1) lcd.clear() lcd.message("Check "+hdd) lcd.message("\nOffUncorr: ") lcd.message(checkdisk3[:-1]) time.sleep(1) time.sleep(1) # Assemble the array at boot lcd.clear() print "Assembling Array" lcd.message("Assembling Array") subprocess.call("sudo mdadm --assemble --scan", shell=True) time.sleep(1) # Mount the array lcd.clear() print "Mounting Array" lcd.message("Mounting Array") subprocess.call("sudo mount /dev/md0 /media/raid", shell=True) time.sleep(1) while (1): lcd.clear() arraystatus = subprocess.check_output("grep 'level 5' /proc/mdstat | awk 'NR==1 {print $11}' | cut -d '/' -f 2 | cut -d ']' -f 1", shell=True) print "Disks in array: "+arraystatus[:-1] if (arraystatus.find("4") == 0): print "Array ok" lcd.message("Array ok\n") else: print "Array failed" arraybuild = subprocess.check_output("grep 'recovery' /proc/mdstat | awk 'NR==1 {print $4}'", shell=True) print "Rebuilding: "+arraybuild[:-1] lcd.message("Rebuild: "+arraybuild[:-1]+"\n") driveused = subprocess.check_output("df -h | grep /dev/md0 | awk 'NR==1 {print $3}'", shell=True) drivetotal = subprocess.check_output("df -h | grep /dev/md0 | awk 'NR==1 {print $2}'", shell=True) print driveused[:-1]+"/"+drivetotal[:-1]+" Used" lcd.message(driveused[:-1]+"/"+drivetotal[:-1]+" Used") time.sleep(60)
We schedule this boot up script in the crontab under the user root and firstly check the Reallocated Sectors, Current Pending Sector and Offline Uncorrectable in the SMART data for each drive. If any is more than 0, we say the drive is failing and print out the results. Next we assemble the array (it seems the USB to SATA doesn’t initialise before the array is trying to be assembled automatically) and then mount the array. Every 60 seconds afterwards, the array is checked to see that all drives are up and then we grab the used/free space. Download bootup.py
Next time I’ll be putting it NAS enclosure and hopefully with these improvements
- Enable power button which would be independent of the Pi which would switch a relay on or off to power the drives and Pi
- Making the front panel backup button able to run a backup script
- The 4 front panel LEDs to indicate drive status and use iostat to show activity on “Act” LED
- Connect the temperature sensor to both mosfets and power down if over temperature
- Change the inductor to a thicker wire one as it’s reaching 84C when the array was rebuilding (hence why I had a fan on blowing on it)
What kind of usb to sata cables did you use?
Hi, I bought one of the cheapest ones I could find from Ebay – http://www.ebay.com.au/itm/USB-2-0-to-IDE-SATA-5-25-S-ATA-2-5-3-5-Adapter-Cable-for-data-transfer-backup-/360500966945?ssPageName=ADME:L:OU:AU:3160
Hi Alex, I’m tryng to do something like that using the raspberry pi B+ (4 usb port) without use the HUB (I want to connect the HD direct to the raspberry) using the cable that you use with you wifinas (https://www.insidegadgets.com/2014/08/30/building-wifipinas-a-single-bay-2-5-nas-using-the-raspberry-pi/).
We need some help with the electronic ¿can you help me?
Thanks
Hi Dientuki,
The HD directly into the Pi was done using this USB to SATA adapter I bought from Ebay – http://www.ebay.com/itm/USB-2-0-to-SATA-7-15-Pin-22Pin-Adapter-Cable-For-2-5-HDD-Hard-Disk-Drive-SU-/201190304331?pt=LH_DefaultDomain_0&hash=item2ed7e06a4b
I just removed the case, cut the wire a little bit and used a USB A connector I got off Ebay too, the 5V for the USB is powered by the power adapter instead of going through the Pi USB.
Hi Alex, thanks for reply, maybe i don’t comunicate my idea; i want to use 3.5HD (desktop HP), not 2.5HD.
So, I need an SMPS to provide power to the PI and 3 3.5HD Sata, that’s my problem. I don’t understand electronic very well 🙁
Ah I see, if you need something quick, it’s probably best to buy a power adapter from Ebay that are used to power up 3.5″ hard drives like this one: http://www.ebay.com.au/itm/2014-Hot-Sale-12V-5V-AC-Adapter-For-HARD-DISK-Drive-Power-Supply-IDE-Good-/331194556692?pt=AU_Components&hash=item4d1cbbe114
You could power 2 (maybe 3) drives from it, you will need a power cable splitter and then have a different power supply for the Pi.