Categories: LinuxRaspberry Pi

Build a Raspberry Pi RAID NAS Server – Complete DIY Guide


Today I’ll show you how to build a Raspberry Pi 3 RAID NAS server using USB flash drives and the Linux native RAID application mdadm, along with SAMBA so the drive will show up as a normal network folder on Windows PC’s. It’s an intermediate tutorial and shows you how to create a Linux RAID array which is a good skill to have.

Hardware Requirements

Raspberry Pi

You can use Raspberry Pi’s from version 2 onward, so 2B, 2B+ and RPi 3’s are fine, but I recommend the latest Raspberry Pi 4 with 4GB RAM. You’ll also need a good quality micro-USB power pack suitable for the Raspberry Pi you’re using, if in doubt, just buy a combo pack that comes with case, power pack and other goodies.

USB Flash Drives

We will be using USB2.0 flash drives for our RAID array, however you can purchase USB3.0 drives if you’re using a Raspberry Pi 4 (which has 2 USB3.0 ports) and RAID levels 0 or 1. The drives should all be the same size and preferably the same manufacturer for a good RAID array however, if you have an odd one out, just make sure it’s the same size or larger than the smallest drive.

In terms of drive size, your budget will be the determining factor, so just get what you can afford. Remember that with RAID-0 you get the total amount of all drives put together, so 2x 64GB drives will give you 128GB. RAID-1 will halve your total capacity, so 2x 64GB drives will give you 64GB, and RAID-5/6 will give you roughly 2/3 of total capacity, so 3x 64GB drives will give you 128GB of storage. RAID-10 will halve your total capacity, so 4x 64GB drives will give you 128GB storage (more about RAID levels further below).

RAID Levels

The number of drives you have with determine what RAID level you’ll be able to create. I suggest 3 (or more) drives which is the minimum required for a RAID-4/5 array that offers a good balance between redundancy and speed. If you only have 2 drives, I suggest using RAID-0, and even though there is no redundancy, RAID-0 rarely fails on solid state media. I have had my workstation running on SATA-3 SSD RAID-0 for years and it never skips a beat, but If you’re storing important files, go with RAID-1.

If you’re confident in your Linux skills you can create a RAID-10 array with 4 drives, which is 2 sets of RAID-1, then each set is used to form a RAID-0 array giving you the benefit of speed and redundancy (I will show you how to create all types of Linux RAID arrays).

Number of Drives RAID Level Availability
  • RAID-0 Stripe (Fastest, but no redundancy)
  • RAID-1 Mirror (Excellent redundancy, good speed)
  • RAID-0 Stripe (Fastest, but no redundancy)
  • RAID-4 Dedicated parity disk (Good speed & redundancy)
  • RAID-5 Block-level striping with distributed parity (Excellent speed & redundancy)
  • RAID-6 Block-level striping with two parity blocks distributed across all member disks (Excellent speed & redundancy)
  • RAID 10 (nested RAID 1+0) (Excellent speed and redundancy)

Once you’ve chosen a desired RAID level, let’s move onto Install/Update Raspbian and mdadm.

Installing Raspbian

Now we need to prepare our MicroSD card, install Raspbian, update the system and install mdadm Linux RAID. You will need a MicroSD card of 8GB or more and the application Etcher to transfer the .img file to it (Etcher supports Windows, Linux and MAC).

  1. Download the latest version of Raspbian Lite from
  2. Click on and extract the .img file and take note of it’s location
  3. If not already installed, download and install Etcher for Windows, Linux or MAC
  4. Insert your MicroSD card into a card reader, close any automatic windows, prompts or alerts
  5. Fire up Etcher which should detect the MicroSD card automatically (important! if you have multiple choices, be sure to choose the SD card we are working with)
  6. Click on the Select Image button, navigate to your Raspbian .img file, select it and/or click Open
  7. Once you’re sure you have everything right by double checking, click on the Flash! button
  8. Etcher will now start the flashing process, click Yes to the Windows prompt, and close any automatic alerts/windows that appear shortly afterwards
  9. Flashing should take about 5 minutes, then you’ll be presented with the “Flash Complete!” dialog
  10. Close Etcher, remove the card reader and MicroSD card
  11. Insert the MicroSD card into your Raspberry Pi

="expanded?" 8="expanded" 9=":" 10="''"" tabindex="0" 11=">1." 12="Choose" 13="your" 14="microSD" 15="drive," 16="then" 17="click" 18="choose" 19="image" 20="" 21="" 22="class="ampforwp-gallery-item" 23="" 24="tabindex="1">" 25="" 26="[class]="expanded?" 27="expanded" 28=":" 29="''"" 30=">2." 31="Navigate" 32="to" 33="your" 34="Raspbian" 35=".img" 36="file" 37="and" 38="select" 39="it" 40="" 41="" 42="class="ampforwp-gallery-item" 43="" 44="tabindex="2">" 45="" 46="[class]="expanded?" 47="expanded" 48=":" 49="''"" 50=">3." 51="Click" 52="on" 53="the" 54="Flash!" 55="button" 56="in" 57="Etcher" 58="" 59="" 60="class="ampforwp-gallery-item" 61="" 62="tabindex="3">" 63="" 64="[class]="expanded?" 65="expanded" 66=":" 67="''"" 68=">4." 69="Etcher" 70="will" 71="flash" 72="the" 73=".img" 74="file" 75="to" 76="your" 77="microSD" 78="card" 79="" 80="" 81="class="ampforwp-gallery-item" 82="" 83="tabindex="4">" 84="" 85="[class]="expanded?" 86="expanded" 87=":" 88="''"" 89=">5." 90="Flash" 91="complete" 92="" 93="" id="gallery-lightbox" 94="layout="nodisplay">" 95="" 96="tabindex="0">" 97="" 98="tabindex="0">" 99="" 100="" 101="


Raspbian Initial Setup

Now we need to do some initial setup of Raspbian, so go ahead and hook up a screen, keyboard and power up your Raspberry Pi and remember, on first boot your RasPi will automatically expand the file system to fit your MicroSD card size, then it will reboot. Once rebooted, login with username: pi password: raspberry

raspi-config Options

Now we’ll do some basic setup options for our RasPi NAS server, so enter the following and use raspberry for the password prompt:

sudo raspi-config

Then change the following:

  • Note* Use the Arrow keys to move up and down, use Enter key to select/confirm, use Tab key to select Cancel or Finish
  • Select “Change User Password” and change user:pi’s password
  • Select Hostname, then type RASPINAS for host-name (or anything you want) hit Ok
  • Select Interfacing Options > SSH, then Yes to enable
  • On Home Screen, hit Tab key until the <Finish> item is selected, hit Enter to reboot
  • You Raspberry Pi is now configured

Step-by-step screenshots of the above process:


1. Enter username pi and password raspberry
2. Enter sudo raspi-config
3. Select Change user password
4. Click OK to confirm
5. Enter your new password
6. Click OK
7. Select Network Options
8. Select Hostname
9. Click on OK
10. Enter RASPINAS or whatever you like, then click OK
11. Select Interfacing Options
12. Select SSH
13. Select Yes to enable the SSH service
14. Click on OK
15. Select Finish using the Tab key
16. Click on Yes to reboot

Update & Install MDADM

Now we just need to update Raspbian and install the mdadm RAID package:

sudo apt-get update 
sudo apt-get upgrade -y 
sudo apt-get install mdadm -y

Setup Drives and RAID Volume

Just to make things easier for identifying our USB drives, we need to format and label each one sequentially:

  1. Windows
  2. Insert one of your USB drives (close any automatic windows)
  3. (Win7,XP,Vista) Go to Start > Computer (Win8,10) search “File Explorer” and open top result
  4. Right-click on the USB drive icon, then select Format
  5. In the Format window, change the following options: File system: NTFS, Volume label: USB01
  6. Now click the Start button, then Yes to alert box
  7. Repeat this process for each USB drive you want to use, increment Volume label: to USB02, USB03 etc
  1. MAC OS X
  2. Insert one of your USB drives (close any automatic windows)
  3. Go to Finder > Applications > Utilities > Disk Utility
  4. Locate the USB drive from the left hand-side and select it
  5. Click on the Erase tab and choose the following options: Format: ExFAT, Name: USB01
  6. Now click on Erase button, then confirm the Erase on the alert box
  7. Repeat this process for each USB drive you want to use, increment Name: to USB02, USB03 etc
  1. Linux (Ubuntu/Debian)
  2. Insert one of your USB drives (close any automatic windows)
  3. Open “All applications” icon bottom-left of your screen, then choose Utilities > Disks
  4. Select the USB drive from left side panel, then click the Gears icon, select Format partition
  5. Choose the following options: Erase: Don’t overwrite existing data (quick), Type: NTFS, Name: USB01
  6. Now click Format… button, then confirm by clicking Format button on alert window
  7. Repeat this process for each USB drive you want to use, increment Name: to USB02, USB03 etc

Now it’s time to insert your USB drives into your Raspberry Pi, it doesn’t matter which drive goes where. We need to find out the mount points for each drive using the following command:

sudo blkid

Which should produce something like the following:

pi@RASPINAS:~ $ sudo blkid 
/dev/mmcblk0p1: LABEL="boot" UUID="CDD4-B453" TYPE="vfat" PARTUUID="498dcd43-01" 
/dev/mmcblk0p2: LABEL="rootfs" UUID="72bfc10d-73ec-4d9e-a54a-1cc507ee7ed2" TYPE="ext4" PARTUUID="498dcd43-02" 
/dev/sda1: LABEL="8GB01" UUID="8A44B0F244B0E1DD" TYPE="ntfs" PARTUUID="01411281-01" 
/dev/sdb1: LABEL="8GB02" UUID="2CF48901F488CE90" TYPE="ntfs" PARTUUID="bd5d9029-01" 
/dev/sdc1: LABEL="8GB03" UUID="A8CE3E46CE3E0D56" TYPE="ntfs" PARTUUID="0fb30d0e-01" 
/dev/sdd1: LABEL="8GB04" UUID="3AC2CC7DC2CC3F3F" TYPE="ntfs" PARTUUID="0fb30d2b-01" 
/dev/mmcblk0: PTUUID="498dcd43" PTTYPE="dos" 

We need to confirm the mount points of our USB drives, most of the time it will be /dev/sda1, /dev/sdb1, /dev/sdc1 and /dev/sdd1

/dev/sda1: LABEL="8GB01" 
/dev/sdb1: LABEL="8GB02" 
/dev/sdc1: LABEL="8GB03"
/dev/sdd1: LABEL="8GB04"

If you have different mount points than shown here, it doesn’t really matter, you’ll just need to replace the code snippets with the mount points you have. It also doesn’t matter if the drive labels are out of order, just so long as they match up to your mount points.

Depending on how many drives you have, choose your RAID level and follow the instructions for your chosen level below.

Setup RAID-0 Volume

Enter the following code to setup two or more USB drives into a high-performance RAID-0 array in parallel, replacing --raid-devices=X with the number of drives you’re using, and /dev/sda1 /dev/sdb1 with your mount points:

sudo mdadm --create --verbose /dev/md0 --level=stripe --raid-devices=2 /dev/sda1 /dev/sdb1

If I were using 4 drives in my RAID-0 array the code would be as follows:

sudo mdadm --create --verbose /dev/md0 --level=stripe --raid-devices=4 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1

Setup a RAID-1 Volume

To setup a redundant RAID-1 array using two drives, enter the following code:

sudo mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sda1 /dev/sdb1

Setup RAID-4/5/6 Volume

To setup a redundant RAID-4, RAID-5 with three drives, or RAID-6 array with four drives, use the following code, replacing --level=X with the RAID level you want:

sudo mdadm --create --verbose /dev/md0 --level=4 --raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1

If I wanted a RAID-5 array using three drives and a hot spare, I would use the following code:

sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1 --spare-devices=1 /dev/sdd1

Setup RAID-10 Volume

To setup a fast, redundant RAID-10 (aka Nested RAID-1+0) use the following code:

sudo mdadm --create --verbose /dev/md0 --level=10 --raid-devices=4 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1

Confirm your RAID Array

Now let’s confirm all went well creating your RAID array with the following command:

cat /proc/mdstat

Which should produce something like this (replace raid10 with whatever RAID level you chose):

pi@RASPINAS:~ $ cat /proc/mdstat 
Personalities : [raid10] 
md0 : active raid10 sdd1[3] sdc1[2] sdb1[1] sda1[0] 
15319040 blocks super 1.2 512K chunks 2 near-copies [4/4] [UUUU] 
[>....................] resync = 0.4% (61504/15319040) finish=28.9min speed=8786K/sec 
unused devices: <none>

Save your RAID array

For some reason Raspbian won’t let us save the RAID array as user:pi even using sudo, so we need to temporarily change to root account, enter the following:

sudo -i

Now we can save our RAID array by entering the following code:

mdadm --detail --scan >> /etc/mdadm/mdadm.conf

It’s also good to confirm it was saved by viewing the mdadm.conf file and look for something like this at the bottom of the file:

# This configuration was auto-generated on Fri, 19 Jan 2018 08:14:18 +0000 by mkconf 
ARRAY /dev/md0 metadata=1.2 name=RASPINAS:0 UUID=0d7c55bd:ae5f8fbc:0e048a15:79de5064

Then exit from root user:


Create File System

You have a number of choices when it comes to Linux file systems, but I will be using the EXT4 file system as it’s the best choice for our RAID array. If you want to learn more about some of the flags (stride, stripe-width, block options) see this article. The following code will produce an EXT4 filesystem with a block size of 4096kb, stride of 32, a stripe-width of 64 and will leave 1% free so it won’t fill up and cause issues:

mkfs.ext4 -v -m .1 -b 4096 -E stride=32,stripe-width=64 /dev/md0

If successful, you should see the following output:

pi@RASPINAS:~ $ sudo mkfs.ext4 -v -m .1 -b 4096 -E stride=32,stripe-width=64 /dev/md0 
mke2fs 1.43.4 (31-Jan-2017) 
fs_types for mke2fs.conf resolution: 'ext4' 
Filesystem label= 
OS type: Linux 
Block size=4096 (log=2) 
Fragment size=4096 (log=2) 
Stride=32 blocks, Stripe width=64 blocks 958464 inodes, 3829760 blocks 3829 blocks (0.10%) reserved for the super user 
First data block=0 Maximum filesystem blocks=2151677952 117 block groups 32768 blocks per group, 
32768 fragments per group 8192 inodes per group Filesystem UUID: 394fd8f2-7b2a-474f-8e58-48b81a6ca8fb 
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 
Allocating group tables: done 
Writing inode tables: done 
Creating journal (16384 blocks): done 
Writing superblocks and filesystem accounting information: done 


We also need to mount the file system so we can access it using the following command:

sudo mount /dev/md0 /mnt

We need to automatically mount the file system at boot, so let’s find out the UUID of our mounted file system by entering the following command:

sudo blkid

Which should produce something like the following:

pi@RASPINAS:~ $ sudo blkid 
/dev/mmcblk0p1: LABEL="boot" UUID="CDD4-B453" TYPE="vfat" PARTUUID="498dcd43-01" 
/dev/mmcblk0p2: LABEL="rootfs" UUID="72bfc10d-73ec-4d9e-a54a-1cc507ee7ed2" TYPE="ext4" PARTUUID="498dcd43-02" 
/dev/mmcblk0: PTUUID="498dcd43" PTTYPE="dos" 
/dev/sda1: UUID="0d7c55bd-ae5f-8fbc-0e04-8a1579de5064" UUID_SUB="f954ff33-87db-4e26-8be9-e978aa0ef815" LABEL="RASPINAS:0" TYPE="linux_raid_member" PARTUUID="bd5d9029-01" 
/dev/sdb1: UUID="0d7c55bd-ae5f-8fbc-0e04-8a1579de5064" UUID_SUB="eea15556-4e0a-1985-163a-064670df9db2" LABEL="RASPINAS:0" TYPE="linux_raid_member" PARTUUID="01411281-01" 
/dev/md0: UUID="394fd8f2-7b2a-474f-8e58-48b81a6ca8fb" TYPE="ext4" 
/dev/sdc1: UUID="0d7c55bd-ae5f-8fbc-0e04-8a1579de5064" UUID_SUB="2a8456d7-6fea-eba2-7728-ebd20aa238e5" LABEL="RASPINAS:0" TYPE="linux_raid_member" PARTUUID="0fb30d2b-01" 
/dev/sdd1: UUID="0d7c55bd-ae5f-8fbc-0e04-8a1579de5064" UUID_SUB="51019b58-995f-cf35-f6c3-33d61a104d76" LABEL="RASPINAS:0" TYPE="linux_raid_member" PARTUUID="0fb30d0e-01"

The item we’re after is the UUID of /dev/md0: which in my case is 394fd8f2-7b2a-474f-8e58-48b81a6ca8fb but yours will be different. Highlight and copy the UUID, then add it to fstab and backup the original fstab just in case:

sudo cp /etc/fstab /etc/fstab.bak 
sudo nano /etc/fstab

Just before the bottom comments, make a space and enter the following on a single line (replace [your_uuid] with the UUID of your file system):

UUID=[your_uuid] /mnt ext4 defaults 0 0

So, my fstab entry would look like this:

UUID=394fd8f2-7b2a-474f-8e58-48b81a6ca8fb /mnt ext4 defaults 0 0

Now save Ctrl+O and exit Ctrl+X.

Install and Setup SAMBA

SAMBA is a Windows file sharing system that runs on Linux, works flawlessly, and is easy to setup too. Let’s install SAMBA and then configure it with the following command:

sudo apt-get install samba samba-common-bin -y

After SAMBA finishes installing, let’s add user:pi and share password by entering the following command (enter a password at the prompts):

sudo smbpasswd -a pi

Which should produce the following result if successful:

pi@RASPINAS:~ $ sudo smbpasswd -a pi 
New SMB password: 
Retype new SMB password: 
Added user pi. 

Before we start altering the SAMBA config file, let’s make a backup:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

Now we edit the smb.conf file:

sudo nano /etc/samba/smb.conf

Scroll down to the bottom of the file using your arrow key, then add the following code to create your NAS file share:

# NAS Share 
path = /mnt 
comment = RasPi NAS Share 
valid users = pi 
writable = yes 
browsable = yes

The save Ctrl+O and exit Ctrl+X. Now let’s make sure our changes work, enter the following:


Which should product the following (if you want a full output, press Enter at the prompt):

pi@RASPINAS:~ $ testparm 
Load smb config files from /etc/samba/smb.conf 
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) 
WARNING: The "syslog" option is deprecated 
Processing section "[homes]" 
Processing section "[printers]" 
Processing section "[print$]" 
Processing section "[NAS]" 
Loaded services file OK. 

Press enter to see a dump of your service definitions

If the line reads “Loaded services file OK.” then you’re good to go.

Finally, we need to restart the SAMBA service by with the following command:

sudo /etc/init.d/samba restart

Connect to your NAS

Now let’s connect to your NAS share and make it automatically show up in your Network drive. Open File Explorer (Win8/10 search “File Explorer” and open top result) (WinXP/Vista go to Start > Computer), then click on the Network item on left-side window pane. Click inside the address bar, then type \\RASPINAS (or whatever you chose for a hostname during Debian setup, if you’re unsure enter the hostname command) and hit Enter

="expanded?" 8="expanded" 9=":" 10="''"" tabindex="0" 11=">1." 12="Enter" 13="your" 14="Raspberry" 15="Pi's" 16="hostname" 17="" 18="" 19="class="ampforwp-gallery-item" 20="" 21="tabindex="1">" 22="" 23="[class]="expanded?" 24="expanded" 25=":" 26="''"" 27=">2." 28="Inside" 29="your" 30="NAS" 31="" 32="" 33="class="ampforwp-gallery-item" 34="" 35="tabindex="2">" 36="" 37="[class]="expanded?" 38="expanded" 39=":" 40="''"" 41=">3." 42="Click" 43="on" 44="your" 45="NAS" 46="folder," 47="then" 48="enter" 49="your" 50="credentials" 51="" 52="" 53="class="ampforwp-gallery-item" 54="" 55="tabindex="3">" 56="" 57="[class]="expanded?" 58="expanded" 59=":" 60="''"" 61=">4." 62="Inside" 63="your" 64="NAS" 65="folder" 66="" 67="" 68="class="ampforwp-gallery-item" 69="" 70="tabindex="4">" 71="" 72="[class]="expanded?" 73="expanded" 74=":" 75="''"" 76=">5." 77="Click" 78="on" 79="Map" 80="network" 81="drive," 82="enter" 83="your" 84="Raspberry" 85="Pi" 86="hostname" 87="and" 88="nas" 89="folder" 90="name" 91="" 92="" 93="class="ampforwp-gallery-item" 94="" 95="tabindex="5">" 96="" 97="[class]="expanded?" 98="expanded" 99=":" 100="''"" 101=">6." 102="Your" 103="new" 104="NAS" 105="folder" 106="as" 107="a" 108="permanent" 109="drive" 110="" 111="" id="gallery-lightbox" 112="layout="nodisplay">" 113="" 114="tabindex="0">" 115="" 116="tabindex="0">" 117="" 118="" 119="



Well I hope this guide has shown you some cool RasPi and Linux stuff and that you had fun 🙂 Something to think about is adding a USB hub to expand the drive number capacity instead of forking out big $$ for large capacity USB drives. You can also add normal 2.5″ or 3.5″ SATA drives via a USB adapter, see this article. If you have any questions or comments, leave them below.

Richie @RicmediaPCHelp

I've been a web developer since 2006 and also have a keen interest in everything Linux and Raspberry Pi. This is where I share my knowledge and projects.

View Comments

  • I'm excited to give this a shot in my own home as I've never built a RAID before. With that said, how would I rebuild this raid in the event one drive crashes? Is it as easy as plugging in a new blank drive and the software does it for me? or would I have to rebuild the project?

  • I think "sudo /etc/init.d/samba restart"
    Needs to be changed to:

    sudo service smbd restart
    sudo service nmbd restart

    Thanks for the article!

    • Hi Kelly, speed overall isn't great, this guide is more leaning toward learning Linux software RAID and it's a really fun project to do. I haven't tried on new RasPi 4 yet which has USB3.0 so I am guessing there would be speed improvements there.


  • Hi!

    In the “Setup Drives and RAID Volume” section of the guide, why choose NTFS as the filesystem to place on the individual drives when performing the step in Linux? Is there any disadvantage to choosing ext4?

    I like your guide quite a bit. Thanks!

    • Hi Thomas, thanks mate. The only reason we need to format the drives is so we can give them a label (in this case USB1/2/3/4) so as to visually identify them on Linux. NTFS is overwritten with EXT4 anyway but the labels remain.


  • Hi, Thanks for making a creat tutorial. I was able to complete everything and get my volume mounted to my Windows system. I am however running into a permissions issue when I try to create a new folder or access the folder that is already inside the NAS folder. I did add my user 'pi' in the samba configuration per the tutorial and I can use the credentials to mount the volume. Is there another place I need to set permissions to allow my windows system to store things on this mounted partition?


    • Hi Nick, no worries glad you liked the guide. When you got to the "Connect to your NAS" step, were you prompted to enter username and password on Windows? And did you check the "Remember Credentials" checkbox?


Recent Posts

Change default email client on Windows 10

Today I'll show you two ways to change your default email client on Windows 10: first using the search box,… Read More

3 months ago

Install HTTP/2 LAMP Stack on Ubuntu 18.04 Server (Linux, Apache, MySQL, PHP)

This tutorial shows you how to install a super-fast HTTP/2 LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 18.04 LTS… Read More

3 months ago Launch

After the success of Ricmedia PC Help, I have decided to migrate over to the root domain and publish… Read More

4 months ago