This GitHub Gist presents how to set up a Raspberry Pi 4 as a Network Attached Storage (NAS) device that supports a Redundant Array of Inexpensive Disks (RAID) technology. Optionally, the Pi's Type-C port can be configured to host mode, making the device a USB Gadget. This way, with only one Type-C cable, you can access the NAS while powering the device simultaneously.
Information Accuracy: The instructions provided in this Gist are based on the author's knowledge and experience as of the publication date. The technology and software described may have evolved, and newer versions may exist, resulting in this solution partially working.
Data Backup: Before proceeding to this setup, users should ensure they have backed up all important data. The process of configuring RAID and NAS involves formatting storage devices, which leads to data loss.
User Responsibility: This Gist intends to inform the users rather than utilize the setup as an end product. They are responsible for using this setup. Using USB storage devices for such an application is unreliable, as sudden disconnection or inefficient power supply can cause permanent data loss.
- Raspberry Pi 4
- Micro SD card
- USB Flash Drive (x2 for RAID)
- Type-C cable
- Ethernet cable (optional)
Step 1: Install OS
Step 2: Install OMV
Step 3: Install the MD plugin
Step 4: Setup a RAID configuration
Step 5: Create a shared folder
Step 6: Setting USB Gadget (Optional)
The fastest and easiest way to install an OS on the Pi is using the Raspberry Pi Imager tool. Suggest the official website for more detailed instructions here.
In the Choose OS step, a valid choice is the Raspberry Pi OS Lite (64bit) under Raspberry Pi OS (other), as the device will be used portably without a desktop environment, and thus, the OS needs to be as lightweight as possible.
In the OS customization step, also do the following configurations:
- In
Generaltab- Check the
Set hostname:checkbox and remember the hostname for easy access to the device through the network. - Check the
Set username and passwordcheckbox to log into the device. - Optionally check the
Configure wireless LANcheckbox and set the WiFi configuration if no ethernet cable is used.
- Check the
- In
Servicestab- Check the
Enable SSH checkbox. - Choose
Use password authentication.
- Check the
Once the tool finishes, plug the SD card into the device, power it up, and wait a few minutes to finish the first boot initialization procedure.
After a while, try to SSH to the device using the hostname and the login credentials provided in the previous step.
The software that performs the NAS procedures is the OpenMediaVault (OMV). There is a script that makes this procedure simple, and it is available here.
Execute the following commands on the terminal to install OMV. Note that the installation will take some time to complete.
wget https://github.com/OpenMediaVault-Plugin-Developers/installScript/raw/master/install
chmod +x install
sudo ./install -n
When the installation finishes, typing the device's hostname (e.g. "raspberrypi/") on the browser's address bar will open the OMV's login screen. The default login credentials are:
admin
openmediavault
Note
It is recommended to modify these credentials for security reasons.
The Multiple Devices (MD) plugin must be installed on the NAS device to support the RAID technology. To do so, go to System, then Plugins, search openmediavault-md and install.
The only way to plug storage devices into the Raspberry Pi 4 is through the USB ports. However, the MD plugin does not allow the creation of RAID configurations with USB storage devices. To avoid this check, commend the lines
if (TRUE === $sd->isUsb())
continue;
of the /usr/share/openmediavault/engined/rpc/mdmgmt.inc file. After reboot, the plugin should recognize the USB storage devices.
Caution
The following steps will ERASE everything saved in the storage devices!
The steps to create a Mirror RAID configuration using two USB3 storage devices (e.g. flash drives) are as follows:
- Connect the two USB drives.
- On OMV go to
Storage > Disksandwipeboth drives. - Go to
Storage > Multiple Devicesand clickCreate. - Select
MirrorasLevel, check the two USB devices from theDevicesdropdown menu, and thenSave. ApplythePending configuration changes.
A shared folder needs to be set to use the RAID configuration from a host machine. This procedure requires installing the Logical Volume Manager (LVM) plugin. Similarly to the MD plugin installation method, navigate to the System > Plugins, and search and install the openmediavault-lvm2 plugin.
Then the steps to create a shared folder are:
- Go to
Storage > File Systems. Create and mount a file systemand selectEXT4from the dropdown menu.- Select the
Software RAIDfrom theDevicesdropdown menu, clickSave, and wait for the format to finish. - Select the
/dev/md0from theFile Systemand clickSave. ApplythePending configuration changes.- Go to
Storage > Shared Folders. Createa shared folder by giving aNameand selecting/dev/md0from theFile systemdropdown menu.- Choose the
Everyone: read/writefrom thePermissionsdropdown menu and clickSave. ApplythePending configuration changes.- Go to
Services > SMB/CIFS > Settings. - Check the
Enabledcheckbox and clickSave. ApplythePending configuration changes.- Go to
Services > Shares. Createa share by- Checking the
Enabledcheckbox, - Selecting the previously created
Shared folderfrom the dropdown menu, - Choosing
Guests allowedfrom thePublicdropdown menu, - Clicking
Saveand ApplythePending configuration changes.
- Checking the
Warning
By choosing Guests allowed" in step 14 everyone on the local network can access the shared folder without credentials.
The Type-C port of the Raspberry Pi 4 can be set in host mode, allowing both power supply and data transfer. This way, the device with USB storage devices being plugged in can act as a portable NAS device when connected to a host machine through a single Type-C cable.
The procedure to set the Type-C port into host mode is simple, as presented here. Just connect to the device through SSH and execute as root the commands
wget https://raw.githubusercontent.com/kmpm/rpi-usb-gadget/master/rpi4-usb.sh
bash rpi4-usb.sh
Follow the script's setup procedure by answering yes to all the questions. Type the first three groups of the IP address and select RNDIS Network device type (best with windows) in the network device type. When the script is complete, reboot the device.
UPDATE: The script in step 6 may not work. Use the following commands instead: