Raspberry Pi NAS
by Frank Bernhardt in Circuits > Raspberry Pi
93097 Views, 559 Favorites, 0 Comments
Raspberry Pi NAS
Building a NAS based on a Raspberry Pi
When I decided to replace my old NAS with a new one, I didn't want to spend too much money on this. So I looked around and found that there are many NAS kits based on a Raspberry Pi. Now you may ask what was my motivation to create another one instead of choosing one of the existing NAS models? This is quite easy to answer. None of these available models matched my requirements for 100%. And I also enjoy developing new things ...
These were my design goals for the enclosure:
Cabling
- Just only the power and network connectors should be accessible from the outside
- Both connectors are on the rear side and next to each other
- Avoid the 90 degree offset for power and network connectors which is typical for Raspberry Pi
- The USB connectors and cables must be all inside the case for a clean design
Printing
- There are only a few parts to print: the enclosure tray, device rack and side lid - optional: a stand
- Quick and easy printability is secondary to design - supports are mandatory for the enclosure tray
- A compact size which can be printed on a 200 x 200 mm printer - no large format printer required
- Durable connections - melt-in brass threaded inserts instead of printed threads or clips
Miscellaneous
- Must be suitable for the Raspberry Pi model 4 and the new Pi 5
- No active cooling for noise reduction (0dB noise emission with SSD) @idle: 55°C CPU / 40°C SSD
- Meaningful multi-line display instead of simple status LEDs
- The display brightness will be reduced at night
- Cheap and easily available standard components
What can you expect?
The following Instructable will show you how to build a Raspberry Pi NAS with the specific enclosure I have designed.
But it will NOT instruct you how to ...
- slice and print STL files with your 3D printer
- setup your Raspberry Pi itself and connect it to the network
- login to your Raspberry Pi via SSH
- use a Linux text editor
- configure the NAS software
Skill requirements:
- This project requires some craftsmanship experience
- You have to be able to solder
- If you want to make your display cable from scratch, you must know how to use a crimping tool
- You must know (or learn) how to configure and manage the NAS software on your Raspberry Pi
Important advice:
Before you start printing the enclosure or buying parts from the BOM below, just assemble the Raspberry Pi and the hard disk loosely wired and check if you get it up and running. If you're successful and you want a cool enclosure for your NAS now, then continue with this Instructable.
Supplies
Notice: The links below are affiliate links. Clicking these links won't cost you anything extra, but it helps me to offset the costs for prototyping material and tools.
Thanks for your support!
Tools
3D printer with a 200 x 200 mm bed
Soldering iron, a tip for threaded inserts recommended
Screwdriver
Optional: Crimping tool for dupont connectors
Devices for compute and storage
Raspberry Pi 4 or 5 with power supply, 2GB RAM is sufficient
32 GB micro SD card, SanDisk Extreme PRO recommended
One or two 2.5" SATA hard disk drives, SSD recommended
One or two USB 3.0 to SATA adapter(s), Sabrent adapter(s) recommended
Software
Raspberry Pi Operating System Image (Pi OS Lite, 64-bit no desktop)
NAS Software for Raspberry Pi OS, openmediavault recommended
Component parts
10 x M3 brass threaded inserts
10 x M3x5 screws (4 more for the second hard disk drive)
4 x M2.5 brass threaded inserts
4 x M2,5x6 screws
4 x M3x6 countersunk head screws
1 x Keystone module RJ45 Cat 6
1 x RJ45 Cat 6 patch cable (length or color doesn't matter)
1 x USB type C male connector plug to solder
1 x USB type C female connector jack 2 pin with wire
1 x SH1106 1.3" OLED module I2C 128X64 4 pin
1 x 4 pin cable with Dupont female connectors, either self-made or ready-made
And last but not least, some PLA filament for your printer with the colors you prefer.
Prepare Your Raspberry Pi
Installing the Raspberry Pi OS Image
The easiest way to install an Operating System (Pi OS) on your Raspberry Pi is to use the Raspberry Pi Imager. You can download it from here: https://www.raspberrypi.com/software/
The Raspberry Pi Imager is really easy to use.
- Insert the micro SD card into your computer
- Start the Raspberry Pi Imager
- Choose your Raspberry Pi Model
- Choose the Operating System -> Select 'Raspberry Pi OS (Other)' -> Select 'Raspberry Pi OS Lite (64-bit)'
- At 'Choose Storage' select your micro SD memory card
- Click 'Next' and follow the further instructions
The following settings should be defined when specifying the image options:
- Hostname
- Username
- Password
- Time zone
- Keyboard layout
- Enable SSH -> Checked
When the imaging process has finished successfully, remove the SD card from your computer and insert it into the SD card slot of your Raspberry Pi. Now connect the power cable and the network cable to your Raspberry Pi and wait for the Raspberry Pi to start up.
After a few minutes take a look at your router to determine which IP address has been assigned to your Raspberry Pi. Now you can login to your Raspberry Pi via SSH. Congratulations, you're well on the way to your new Pi NAS.
Assigning a static IP address
Important: A network device like a NAS should always have a fixed IP address. The fixed IP address can either be set in the Raspberry Pi OS, via openmediavault or as a static assignment on a DHCP server.
Network name resolution
The name resolution can be done via DNS. If there is no DNS server in your network, the host name can alternatively be stored locally in the host file on all computers in the network. The NAS can also be operated without name resolution, but then it can only be accessed by it's IP address.
Install Updates and Additional Packages
For a fresh OS installation it's recommended to install any missing updates immediately. Login to your Raspberry Pi via SSH and run this command:
sudo apt-get -y update && sudo apt-get -y upgrade && sudo reboot
This will install all available updates and then reboot the system.
After the Raspberry Pi has rebooted successfully, login again and run the following commands one by one to install some packages we will need later:
sudo apt-get -y install i2c-tools
sudo apt-get -y install python3-pip
sudo apt-get -y install python3-psutil
sudo apt-get -y install python3-luma.oled
When all packages are installed, you can shutdown and power off the Raspberry Pi.
Print the Enclosure Parts
The NAS enclosure consists of just four parts. Below you will find the STL files.
The average printing times for the enclosure parts are:
- Enclosure tray: approx. 14h 45m
- Device rack: approx. 3h 30m
- Side lid: approx. 5h 45m
- Stand: approx. 5h 15m
- Total printing time: approx. 29 hours
You need about 350g of filament for all parts.
Printing instructions for the Enclosure Tray
The enclosure tray requires support at least for the connector openings at the rear side and the display window at the front. In your slicer software you can choose "everywhere" for support. This may generate support for the lid attachment points as well, but this doesn't matter. You should enable organic supports if your slicer software offers this feature.
Printing instructions for the Lid
It's recommended to print the outer side on the bed (default setting). This will create the same texture like the outer side of the enclosure.
Printing instructions for the Rack and for the Stand
There are no specific recommendations for printing.
Mount the Devices to the Rack
Use the soldering iron to melt the four M2.5 brass threaded inserts into the rack as shown in the picture. You can use a special adapter for melt-in threads for your soldering iron, as the picture in the next step shows. This makes the process a little bit easier. However, you can also use a normal soldering tip for this. No matter which tool you use, make sure that the threaded insert is melted in vertically and not at an angle.
When you're done with this, mount the hard disk(s) to the rack, each with four M3 screws.
Once the hard disk(s) are in place, attach the Raspberry Pi to the rack with four M2,5 screws. If you perform this step before installing the hard disk(s), it will be very difficult to tighten the screws for the bottom hard disk. This means, whenever you plan to replace a hard disk at a later time, you have to remove the rack from the enclosure and the Raspberry Pi from the rack. This may not be maintenance friendly, but to be honest, how often will you replace a hard disk in your NAS?
Now connect the hard disk(s) to the Raspberry Pi with the SATA to USB cable(s).
Prepare the Enclosure Tray
After printing the enclosure tray, remove all supports. Use the soldering iron to melt six of the M3 brass threaded inserts into the bottom of the enclosure tray. Then melt another four M3 brass threaded inserts into the lid attachment points.
The next step is to prepare the power connection. As the rear opening on the enclosure is unfortunately too small for a USB plug, the wires of the USB socket must be soldered to the USB plug inside the enclosure. If not already done, both wire ends must be stripped and tinned. Now guide the two wires of the USB-C socket into the housing from the outside and press the socket firmly into the opening from the outside. Before you start soldering, don't forget to slide the connector housing over the wires. Now solder the wires to the plug, the black wire to pin G and the red wire to pin V. The position of these pins may vary by the manufacturer of the USB plug. Finally, slide the housing over the USB plug. A drop of hot glue inside the housing will fix the plug housing components much better.
Now it's time to install the OLED display to the enclosure. Important: The OLED display is quite sensitive and installation is not that easy. Make sure that you do not exert too much pressure on the display and do not bend it under any circumstances. It is better to bend the housing slightly to place the display in the holder.
The upper side of the display is the side with the four post connectors. Put the display with the bottom side into the holder and then let it snap into place with the upper side a the two brackets, as shown in the picture.
Install the Rack Into the Enclosure
Place the rack in the enclosure and secure it with six M3 screws. It is advantageous to use a magnetic screwdriver for this, as there is little space at the back of the enclosure.
Plug the USB-C connector into the power supply socket in the Raspberry Pi.
Assemble the Network Cable
Using a keystone module for the network connection gives you a lot of advantages to direct cabling. The LAN port is accessible from outside, you can connect and disconnect the LAN cable very easily. If you are currently using a Raspberry Pi 4 for your NAS and want to upgrade to a Raspberry Pi 5 at a later time, you don't need a new enclosure because the internal adapter is flexible and fits to the Raspberry 4 as well to the Raspberry Pi 5.
Since written instructions are not so easy to understand, especially if you never wired a keystone module, I have added some pictures to clearly explain the individual steps.
- Cut 25 cm off one end of a patch cable and strip 3 cm of insulation from the cable at the open end.
- Bend the shield back to gain access to the wires. Twist the shield around the cable.
- Remove the plastic wrap which is around the wires
- Feed the wires through the frame: The wires for pins 1,2,3 and 6 on the left, the wires for pins 4,5,7 and 8 on the right.
- Fix the wires in the frame and use a sidecutter to cut them off
- Push the frame onto the contacts and close the metal housing halves until they click firmly into place
- Use the cable tie to create the strain relief
- Install the keystone module to the enclosure. First insert the module at the top and then swing it downwards until the plastic hook clicks into place
- Plug the patch cable connector into the Raspberry Pi's network socket
- Now connect a network cable and the power supply to your NAS and check whether the network connection is functional
Connect the OLED Display to the Raspberry Pi
The OLED display has four pins and the Raspberry Pi GPIO has 40 pins. The challenge is to connect the right pins together.
That's why we have to define the cabling diagram beforehand:
- GPIO pin 1 <=> display VCC
- GPIO pin 3 <=> display SDA
- GPIO pin 5 <=> display SCK
- GPIO pin 9 <=> display GND
These are the GPIO pin numbers and not the GPIO port numbers!
If you are not sure with the GPIO pin numbering, you can run the command
pinout
on your Raspberry Pi. This gives you an overview of your Raspberry Pi board to identify the corresponding GPIO pins.
Important: The position of the pins on your OLED display may vary depending on the manufacturer. Be sure to check the designation of the pins on the display before connecting the display to the Raspberry GPIO pins!
There are different ways for connecting the the OLED display to the Raspberry Pi. The professional method is to build your custom cable like I did for my production NAS. I took a 4-pin CD-ROM audio cable and cut the cable to approx. 30 cm length. At each end I crimped four female Dupont connectors to the wires. The four Dupont connectors are inserted into suitable connector housings. There is a 4-pin connector housing on the display side, and a 5-pin housing on the side for the Raspberry Pi. The connectors are inserted into the housings according to the wiring diagram. The cable ends are finished with shrink tubing to make it look nice.
If you're not familiar with crimping or don't want to buy a complete set with crimping pliers and connectors for one-time use, then can use female Dupont jumper cables with sockets on both sides instead. They cables must be at least 20 cm long. It's not quite as pretty, but it's a very cheap, easy and quick solution and it serves exactly the purpose.
Install the OLED Software
At the end of this section you find the file oledinfo.py attached. This program shows different screens on the OLED display with useful information about your NAS. The screens do change every 10 seconds in an endless loop. The brightness of the display will be reduced between 10 p.m. and 7 a.m. As this program is Python code you may easily modify it for your own needs.
Before you start installing the software, you must enable the I2C interface on your Raspberry Pi. Login to your Raspberry Pi via SSH and start the Raspberry Pi Configuration Tool by entering
sudo raspi-config
on the command line.
In the Configuration Tool go to '3 Interface Options' and select 'I4 I2C'. Then you will be asked
Would you like the ARM I2C interface to be enabled?
Choose '<Yes>' to enable the I2C interface. After confirming the success dialog, leave the Configuration Tool by selecting the '<Finish>' button or pressing the Esc key.
Now run the command
sudo i2cdetect -y 1
and you should get a table like this one:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
If you see the '3c' in this table, the OLED display was detected and everything is fine. If not, so check the cabling as described in step before.
The attached file oledinfo.py contains the Python code for the display output. Now as your OLED display is functional, you can copy the file oledinfo.py to your user's home directory on your Raspberry Pi. The easiest way to do this is to copy the file using the scp command. The scp command is available on most platforms, not just Linux.
scp oledinfo.py admin@192.168.1.4:/home/admin
This example assumes that your Raspberry Pi user is 'admin' and your Raspberry Pi has the IP address 192.168.1.4. Adjust the values to your configuration.
Now login to your Raspberry Pi and run the following commands
sudo mv /home/admin/oledinfo.py /usr/local/bin/
sudo chown 0:0 /usr/local/bin/oledinfo.py && sudo chmod 755 /usr/local/bin/oledinfo.py
to move the file to the right location, set the owner and the permissions of this file.
To test the display run the command
/usr/local/bin/oledinfo.py
When everything went well, your OLED display should now begin to show some output.
You can stop the execution of this program by hitting Ctrl+C.
Finally you have to configure the file to be executed each time when your Raspberry Pi starts. This will be done by adding a command with the tag @reboot in the system's crontab.
Enter the command
sudo crontab -e
to edit the crontab.
Add the line
@reboot /usr/bin/python3 /usr/local/bin/oledinfo.py
to the end of the crontab. When you save the file and leave the editor, the new crontab will be installed.
Now reboot your Raspberry Pi to check whether the display is activated on system start:
sudo reboot
Don't worry if the openmediavault logo does not appear on the display. As long as openmediavault is not installed, the logo will not be shown.
Downloads
Completion of the NAS Enclosure
Use the four M3x6 countersunk head screws to attach the side lid to the enclosure tray and place the enclosure on the stand. And that was about it.
Now plug in the network cable and the power supply and let yor NAS start up.
Install the NAS Software Openmediavault
After the hardware is ready for operation, comes the most important point: the NAS software.
Of course you can install any NAS software you like. In the following, the installation of openmediavault is described, as the installation is easy to perform and the web-based user interface makes it simple to manage.
Installing openmedivault is quite straightforward. To install the openmediavault software, login to your raspberry Pi via SSH and run the command
sudo wget -O - https://github.com/OpenMediaVault-Plugin-Developers/installScript/raw/master/install | sudo bash
This may take a while, depending on your Internet connection speed and the speed of your micro SD card. Enough time for a cup of coffee.
When the installation has finished, start a browser on your computer and go to
http://192.168.1.4
(or whatever IP address your Raspberry Pi has)
Important: Use the http:// prefix as the HTTPS protocol is not enabled by default. You may enable HTTPS later.
The openmediavault login page should appear in your browser and you can login to your openmediavault instance with the following credentials:
User: admin
Password: openmediavault
Now you can start to configure your NAS. Have a lot of fun!