Skip to content

Instantly share code, notes, and snippets.

@angrammenos97
Created August 20, 2024 17:54
Show Gist options
  • Select an option

  • Save angrammenos97/d7f1b7932c109611b67692f0918369e7 to your computer and use it in GitHub Desktop.

Select an option

Save angrammenos97/d7f1b7932c109611b67692f0918369e7 to your computer and use it in GitHub Desktop.
Portable NAS device using Raspberry Pi 4 with RAID technology support.

Portable Raspberry Pi 4 RAID NAS

Introduction

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.

Disclaimer

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.

Prerequisites

  • Raspberry Pi 4
  • Micro SD card
  • USB Flash Drive (x2 for RAID)
  • Type-C cable
  • Ethernet cable (optional)

Table of contents

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)

Step 1: Install OS

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:

  1. In General tab
    • Check the Set hostname: checkbox and remember the hostname for easy access to the device through the network.
    • Check the Set username and password checkbox to log into the device.
    • Optionally check the Configure wireless LAN checkbox and set the WiFi configuration if no ethernet cable is used.
  2. In Services tab
    • Check the Enable SSH checkbox.
    • Choose Use password authentication.

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.

Step 2: Install OMV

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.

Step 3: Install the MD plugin

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.

Step 4: Setup a RAID configuration

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:

  1. Connect the two USB drives.
  2. On OMV go to Storage > Disks and wipe both drives.
  3. Go to Storage > Multiple Devices and click Create.
  4. Select Mirror as Level, check the two USB devices from the Devices dropdown menu, and then Save.
  5. Apply the Pending configuration changes.

Step 5: Create a shared folder

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:

  1. Go to Storage > File Systems.
  2. Create and mount a file system and select EXT4 from the dropdown menu.
  3. Select the Software RAID from the Devices dropdown menu, click Save, and wait for the format to finish.
  4. Select the /dev/md0 from the File System and click Save.
  5. Apply the Pending configuration changes.
  6. Go to Storage > Shared Folders.
  7. Create a shared folder by giving a Name and selecting /dev/md0 from the File system dropdown menu.
  8. Choose the Everyone: read/write from the Permissions dropdown menu and click Save.
  9. Apply the Pending configuration changes.
  10. Go to Services > SMB/CIFS > Settings.
  11. Check the Enabled checkbox and click Save.
  12. Apply the Pending configuration changes.
  13. Go to Services > Shares.
  14. Create a share by
    • Checking the Enabled checkbox,
    • Selecting the previously created Shared folder from the dropdown menu,
    • Choosing Guests allowed from the Public dropdown menu,
    • Clicking Save and
    • Apply the Pending configuration changes.

Warning

By choosing Guests allowed" in step 14 everyone on the local network can access the shared folder without credentials.

Step 6: Setting USB Gadget (Optional)

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.

@angrammenos97
Copy link
Author

UPDATE: The script in step 6 may not work. Use the following commands instead:

wget https://raw.githubusercontent.com/ahmadSum1/rpi-usb-gadget/master/rpi4-usb.sh
bash rpi4-usb.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment