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.
In the end our target architecture will look like this.
The goal is to make our NAS accessible by different devices on our network.
As discussed above, we can create a low cost NAS by recycling old computer hardware.
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).
First we need to install Debian as brilliantly explained here.
allow-hotplug ens192
iface ens192 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.254
dns-nameservers 192.168.1.254
root@host:~# reboot
root@host:~# apt update && apt install mdadm gdisk
root@host:~# wipefs -a /dev/sdb[1-9]*
root@host:~# wipefs -a /dev/sdb
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.
root@host:~# sfdisk -d /dev/sdb | sfdisk --force /dev/sdc
root@host:~# sfdisk -d /dev/sdb | sfdisk --force /dev/sdd
mdadm is a utility used to create, manage and monitor software RAID devices on GNU/Linux.
root@host:~# apt install mdadm
root@host:~# mdadm --create --level=5 --raid-devices=3 /dev/md0 /dev/sdb1 /dev/sdc1 /dev/sdd1
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>
root@host:~# mkfs.ext4 /dev/md0
root@host:~# mkdir /data
root@host:~# mount /dev/md0 /data
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
root@host:~# mdadm --detail --scan >> /etc/mdadm/mdadm.conf
root@host:~# update-initramfs -u
root@host:~# echo "/dev/md0 /data ext4 rw,nofail,relatime,x-systemd.device-timeout=20s,defaults 0 2" >> /etc/fstab
We are now going to install and configure the
root@host:~# apt install samba
root@host:~# adduser --home /data --system samba
root@host:~# chown samba: /data
root@host:~# smbpasswd -a samba
[global]
workgroup = WORKGROUP
server string = nas
[share]
path = /data
read only = no
valid users = samba
root@host:~# systemctl restart smbd; systemctl restart nmbd
Contact :