🛠 NAS léger : disque USB et partage Samba
Objectives
Turn the board into a small home file server: mount an ext4-formatted USB drive, export it via SMB/CIFS using Samba with an authenticated account, and set realistic expectations — the 4 USB ports and Gigabit Ethernet share the same USB 2.0 bus, which caps real transfer speeds at around 300 Mb/s at best over wired connections, and less in practice once the drive is connected.
Hardware
- Raspberry Pi 3 Model B+ (or similar) running Raspberry Pi OS Lite, 2.5 A power supply
- 2.5"/3.5" hard drive with its own power supply (total USB power budget is 1.2 A)
- Ethernet cable (preferred over Wi-Fi for a NAS)
- No SATA on this board: only USB storage is possible; the microSD card remains reserved for the system.
Full code
# 1. Formater (ATTENTION : efface tout) et monter le disque
sudo apt install -y samba
sudo mkfs.ext4 -L nas /dev/sda1 # verifier : lsblk, sudo blkid
sudo mkdir -p /mnt/nas
UUID=$(sudo blkid -s UUID -o value /dev/sda1)
echo "UUID=$UUID /mnt/nas ext4 defaults,noatime 0 2" | sudo tee -a /etc/fstab
sudo mount -a && df -h /mnt/nas
# 2. Export Samba authentifie
sudo mkdir -p /mnt/nas/partage
sudo smbpasswd -a monuser
sudo tee -a /etc/samba/smb.conf >/dev/null <<'EOF'
[partage]
path = /mnt/nas/partage
valid users = monuser
writeable = yes
create mask = 0664
directory mask = 0775
EOF
sudo systemctl enable --now smbd
# 3. Test de debit (attendu : bien sous les 300 Mb/s theoriques du bus)
# cote client : smbclient //IP-CARTE/partage -U monuser
Expected verification
df -h /mnt/nas shows the drive mounted and it survives a reboot (fstab by UUID). From a machine on the network, smb://BOARD-IP/share opens with the created account, with read/write access. testparm -s reports no configuration errors. iperf3 over wired connection approaches 300 Mb/s when the drive is idle; disk-to-network transfers are significantly slower — this is normal (shared USB 2.0 bus).
Common errors
- Bus-powered drive without external power: voltage drops, undervoltage bit, corruption — always use a powered drive or an active hub.
- Mounting by /dev/sda1: the name changes depending on connection order; use UUID.
- Forgetting
smbpasswd -a: Samba refuses the connection even if the Linux account exists. - ext4 on a drive you also want to connect under Windows: plan for exFAT or a second share, keeping in mind that exFAT is less robust against abrupt shutdowns.
- Shutting down without
sync/poweroffon ext4 while writing: risk of fsck on next boot; consider backups. - 1 GB of RAM: Samba + indexing services increase the load — keep the system lightweight (Lite, no desktop).
Other tutorials for this board
Code examples for this board
led_blink.pyPythonbutton_led.pyPythonservo_sweep.pyPythondht_temp.pyPythonoled_i2c.pyPythonmcp3008_read.pyPython