GNU/Linux - How to create a NAS

Tux logo

We will see here how to create our own Network-attached storage under GNU/Linux.

The main advantage is to have a NAS that is inexpensive (you can for example consider recycling an old PC), highly flexible and configurable.

I will use Debian Linux distribution with mdadm utility to manage RAID and samba for providing shared access to files.

Target Architecture

In the end our target architecture will look like this.

The goal is to make our NAS accessible by different devices on our network.

NAS with three 2 TB disks
NAS Architecture


Hardware Requirements

As discussed above, we can create a low cost NAS by recycling old computer hardware.

  • Here is an example of a hardware configutation :
    • CPU : > intel dual core
    • RAM : 512 MB
    • HDD : 1x 500 GB (OS) + 3x 2TB (data)
NAS with three 2 TB disks
NAS Hardware Configuration

Software Configuration

We will install Debian on our first hard drive (/dev/sda) then create a RAID 5 with our three 2 TB disks (sdb, sdc and sdd).

Debian NAS with three 2 TB disks
Debian NAS


First we need to install Debian as brilliantly explained here.

Network Configuration

  • Edit /etc/network/interfaces (replace ens192 by your own interface) :
allow-hotplug ens192
iface ens192 inet static
  • Reboot :
root@host:~# reboot

Partition Table

  • Install gdisk tool, the gpt version of fdisk :
root@host:~# apt update && apt install mdadm gdisk
  • Clean partition table for /dev/sdb :
root@host:~# wipefs -a /dev/sdb[1-9]*
root@host:~# wipefs -a /dev/sdb
  • Create partition table for /dev/sdb :
Let's assume that our disks are allocated as follows (use fdisk -l to be sure) : sdb, sdc, sdd
root@host:~# gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-4194270, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-3907028991, default = 3907028991) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): FD00
Changed type of partition to 'Linux RAID'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
  • Copy partition table from /dev/sdb to /dev/sdc and /dev/sdd :
root@host:~# sfdisk -d /dev/sdb | sfdisk --force /dev/sdc
root@host:~# sfdisk -d /dev/sdb | sfdisk --force /dev/sdd


  • Install mdadm tool :
root@host:~# apt install mdadm
  • Create RAID 5 :
root@host:~# mdadm --create --level=5 --raid-devices=3 /dev/md0 /dev/sdb1 /dev/sdc1 /dev/sdd1
  • Check RAID status :
root@host:~# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdd1[3] sdc1[1] sdb1[0]
      418713600 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
  • Create file system on /dev/md0 :
root@host:~# mkfs.ext4 /dev/md0
  • Create mount folder :
root@host:~# mkdir /data
  • Mount filesystem located on /dev/md0 device to /data directory :
root@host:~# mount /dev/md0 /data
  • Show mount points :
root@host:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            983M     0  983M   0% /dev
tmpfs           200M  5.6M  194M   3% /run
/dev/sda2        14G  1.5G   12G  12% /
tmpfs           998M     0  998M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           998M     0  998M   0% /sys/fs/cgroup
/dev/sda1       511M  3.3M  508M   1% /boot/efi
tmpfs           200M     0  200M   0% /run/user/0
tmpfs           200M     0  200M   0% /run/user/1000
/dev/md0        1.8T   16M  1.7T   1% /data
  • To tell mdadm to assemble our array at boot :
root@host:~# mdadm --detail --scan >> /etc/mdadm/mdadm.conf
  • Update initramfs to take into consideration :
root@host:~# update-initramfs -u
  • Add fstab entry to mount at boot :
root@host:~# echo "/dev/md0 /data ext4 rw,nofail,relatime,x-systemd.device-timeout=20s,defaults 0 2" >> /etc/fstab


  • Install :
root@host:~# apt install samba
  • Create samba user :
root@host:~# adduser --home /data --system samba
  • Set rights :
root@host:~# chown samba: /data
  • Create a password to access share :
root@host:~# smbpasswd -a samba
  • Edit /etc/samba/smb.conf :
   workgroup = WORKGROUP
   server string = nas
   path = /data
   read only = no
   valid users = samba
  • Restart services :
root@host:~# systemctl restart smbd; systemctl restart nmbd
  • From your computer check that you can access to your share :
Kibana | Main menu, Management, Stack Management
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :