Fri. Mar 24th, 2023
HomeMade NAS

Time: 40 Minutes

Generally I don’t really care about the details or best practices but over my career I have learned the importance of why best practices exist. I decided to build my own NAS from parts I had laying around. I had a RPi 4 model b (2 gb) and (2) 2 tb firecuda drives (spindle drives) I bought two sata to usb cables with power adapters to complete this build.

This is kind of a long article I apologize, but I felt the need to give all of the details of this particular build.

Here are the Pre-Requisites:
1 – Ubuntu Server/RPi OS Buster/Bullseye
2 – Webmin installed to manage it.
3 – iSCSI, nfs-kernel-server, & Samba

If using the RPi 4 Device you will need the following:

1 – RPi 4 Model B Device
2 – (2) sata to usb cables/adapter w/power adapter
3 – (2) 2tb Hard Drives
4 – RPi OS installed on the device
5 – 30 minutes of time
6 – patience

Use RPi Imager to burn the os to the SD Card:

Erase the SD Card unless it’s new.
Choose the correct sd card.
Click write to start the erase procedure.
Click YES
Click Continue
Choose OS again then
Raspberry Pi OS or Other (Ubuntu Server is located under here).
Choose RPi OS Lite (Highlighted is Buster)
Choose your storage
Choose the Customisation tool on the right
Give the device your hostname
Enable SSH
Set the username and password
Set your timezone here
Uncheck Telemetry and Click Save button, Then Click write to start.
Click YES
Click Continue

Remove the SD Card and plug it back in we have some things we need to do before we boot the pi with it.

Open File Explorer

Open cmdline.txt with a text editor
The Above can be copied and pasted into this file I always put it at the start of the line:

ip=12.18.2.21::12.18.2.1:255.255.255.0:rpi4-k3s-w02:eth0:off cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 swapaccount=1

Next we need to open the config.txt

sudo nano -c config.txt

### This will disable WiFi and Bluetooth ###dtoverlay=disable-wifi
dtoverlay=disable-bt

# dtparam=audio=on
dtparam=audio=off

### Add on the last line after the [all] section This makes sure 64bit is used ###
arm_64bit=1

Check to see if the drives are recognized:
1 – lsblk
Make sure we update the repositories and the OS packages
2 – sudo apt update && sudo apt -y full-upgrade
Let’s install the needed software:
3 – sudo apt -y install tgt samba nfs-kernel-server
Create the array
4 – sudo mdadm –create –verbose /dev/md0 –level=0 –raid-devices=3 /dev/sdb /dev/sdc /dev/sdd
note: The dashes (in the command above) are 2 dashes, not one for some reason Word Press doesn’t show them as 2.

Let’s make sure it was created properly
5 – cat /proc/mdstat
Create the filsystem on the raid
6 – sudo mkfs.ext4 /dev/md0
Create the mount point
7 – sudo mkdir -p /mnt/Stor2
8 – sudo mount /dev/md0 /mnt/Stor2
Let’s append the config to the mdadm config file
9 – sudo mdadm –details –scan | sudo tee –a /etc/mdadm/mdadm.conf
Enable the Raid at boot
10 – sudo update-initramfs -u
Put the raid mount point in the fstab file
11 – /dev/md0 /mnt/Stor2 ext4 defaults,nofail,discard 0 0
Test the raid to make sure it’s functioning properly
12 – sudo chmod -Rf 777 /mnt/Stor2/
13 – sudo timedatectl set-timezone America/New_York

Let’s install your new GUI: (IF YOU ARE INSTALLING THIS ON A RPi 4 GOTO RPi4 install below)
14 – sudo apt -y install software-properties-common apt-transport-https
15 – sudo wget -q http://www.webmin.com/jcameron-key.asc -O- | sudo apt-key
16 – sudo add-apt-repository “deb [arch=amd64] http://download.webmin.com/download/repository sarge contrib”
17 – sudo apt -y install webmin
18 – sudo systemctl status webmin
Goto the interface in your browser
19 – https://[your server’s IP]:10000/

RPi4 INSTALL:

### Install OS on the RPi4 device ###
If this is a RPi Device use RPi imager to burn to a SDCard.
2 - Once booted ssh into the VM/Device (ssh user@ip_address_here)
3 - sudo apt update && sudo apt -y full-upgrade
4 - sudo timedatectl set-timezone America/New_York

### Install Virtualmin on the RPi4 w/Buster ###
You can install Virtualmin on a Raspberry Pi with just a simple modification 
in the install script.

I have my Raspberry Pi 4 installed with "RaspberryPi OS Buster" and it 
is based on Debian Linux 10 using the install script.

What you need to do is

1. wget http://software.virtualmin.com/gpl/scripts/install.sh
2. sudo nano install.sh
3. Find the text "get_distro"
4. Add in os_type="debian" after get_distro

get_distro
os_type="debian" 
log_debug "Operating system name: $os_real"
log_debug "Operating system version: $os_version"
log_debug "Operating system type: $os_type"
log_debug "Operating system major: $os_major_version"

What this does is, it will force the script to recognize the host 
as a debian operating system.

Execute the script ... It should install without any issues.

5. chmod 755 install.sh
6. ./install.sh

### wait for the script to finish then: ###
7 - https://ip_address_here:10000 
### and login with your account. ###
Your NAS login
This is your dashboard
You will need to create your directories.

On the left navigation goto Tools>File Manager
I created my directories under /mnt directory
Mine look like this /mnt/Stor2/dir_name_here

/mnt/Stor2/dir_name_here

Now we need to share them. I will use NFS here, but I will also give an example smb/cifs/samba.

On the left goto Networking > NFS Exports > Click the hamburger to open up the screen.
Add a new export
Use the highlighted portions
Make sure to choose no on read-only and no on clients must be on secure port.
Check all the shares then click Enable Selected then Apply Changes

Enable Samba Share

On the left goto Servers > Samaba Windows File Sharing
Choose create new file share
Name your share > navigate to share location > Create with permissions 777 or whatever you want.
Click on the share you created
Click on Security an Control
Choose Yes on Writable and Choose Yes on Guest Access
Check your File permissions, make sure they are correct.
Check the share then click the Restart Samba Servers

That completes the process for Samba/NFS shares. If you have any questions you can email us support@rpihobby.org. Also use the comments also if you like.

I will not take credit for this the individual below gets all the credit.
This is per enzochzng on the Raspberry Pi forums
Post is here -> https://forums.raspberrypi.com/viewtopic.php?t=254307

Thank you for reading and stopping by.

By Michael Cooper

Senior Systems Engineer | 30 years in IT | RPi Hobbiest

Leave a Reply

Your email address will not be published. Required fields are marked *