Skip to content

Instantly share code, notes, and snippets.

@hoel-bagard
Last active October 17, 2021 11:03
Show Gist options
  • Select an option

  • Save hoel-bagard/13b9d6e336c259bc404df9841ddadc79 to your computer and use it in GitHub Desktop.

Select an option

Save hoel-bagard/13b9d6e336c259bc404df9841ddadc79 to your computer and use it in GitHub Desktop.
NAS Setup

NAS installation using an ODROID-HC4 and armbian.

Setup the OS

Remove Petitboot loader from the odroid

To be able to boot clean Armbian mainline based u-boot / kernel experiences, you need to remove incompatible Petitboot loader that is shipped with the board. From the Petitboot, go for “Exit to shell” and these commands to remove the Petitboot:

# flash_eraseall /dev/mtd0
# flash_eraseall /dev/mtd1
# flash_eraseall /dev/mtd2
# flash_eraseall /dev/mtd3

This will make your SPI flash memory empty and would start from SD on next boot.

Install the OS

From the documentation:

  • Download the OS build from the product page (I went with the Armbian Bullseye version).
  • Put the OS on an SD card using balenaEtcher (just download the exe for a single use, also the AUR is broken).
  • Put the SD card in the odroid and boot.
  • Set root pwd, shell and first user.

Fix the IP

Still from the same documentation

nmcli con mod "Wired connection 1"
  ipv4.addresses "HOST_IP_ADDRESS"
  ipv4.gateway "IP_GATEWAY"
  ipv4.dns "DNS_SERVER(S)"
  ipv4.dns-search "DOMAIN_NAME"
  ipv4.method "manual"

Note: I did not change the dns (maybe I should ?), otherwise I used:

HOST_IP_ADDRESS: 192.168.11.7/24
IP_GATEWAY: 192.168.11.1

Hard drives

Install exFAT packages:

apt install exfat-utils exfat-fuse

Note: exFAT because fat32 has a 4.2GB file size limit, and NTFS doesn't have a super good support on linux.

fdisk /dev/sda
mkfs.exfat /dev/sda1 -n NAS_PUBLIC
mkdir /storage
mkdir /storage/nas_public
mount /dev/sda1 /storage/nas_public

Then modify the fstab so that they are mounted on boot:

# /dev/sdb1 LABEL=NAS_PRIVATE
UUID=2C47-2044  /storage/nas_private    exfat   defaults,rw,noatime,uid=1000,gid=1000   0 0

# /dev/sda1 LABEL=NAS_PUBLIC
UUID=29FD-8E5A  /storage/nas_public     exfat   defaults,rw,noatime,uid=998,gid=998     0 0

Note: Here 1000 is the uid of user "hoel" who is the only one allow to access the private nas, and 998 is the uid of "samba-public", used to access the public NAS.

Setup the Samba server

A detailed tutorial can be found here.

apt update
apt ugrade
apt install samba

Check that it was installed properly with:

samba -V
systemctl status smbd

Add a samba-public user for the public drive, and register the "hoel" user for the private drive:

sudo useradd -rs /bin/false samba-public
sudo chown samba-public /storage/nas_public
sudo chmod u+rwx /storage/nas_public

sudo smbpasswd hoel

/etc/samba/smb.conf

The workgroup is WORKGROUP by default, no need to change it.

Add this at the end of the file

[PublicNAS]
  path = /storage/nas_public
  available = yes
  browsable = yes
  public = yes
  writable = yes
  force user = samba-public

[PrivateNAS]
  path = /storage/nas_private
  available = yes
  browsable = yes
  public = no
  writable = yes
  valid users = hoel

Check that the config is correct:

testparm

Restart the samba server:

systemctl restart smbd
systemctl status smbd

Optional: Can check that it works fine locally with:

apt install smbclient
smbclient -L localhost

Mount it

Linux

sudo mount -t cifs //<server_ip>/<share_name> <mountpoint>

Windows

Allow the disk to spindown (to reduce noise/heat)

hdparm

Uses S.M.A.R.T. and hdparm, they should already be installed.
To see what your drive support: sudo hdparm -I /dev/sda.
To see how fast a drive delivers data: sudo hdparm -t /dev/sda.

To make a drive to spin-down after 15min of inactivity: hdparm -B 254 -S 242 /dev/sda.
To spin down a drive immediately: hdparm -y /dev/sda

After checking that the disk spins down properly, make the change persistent using a udev rule. (You can wait and look at the drive himself (heat, noise) or use smartctl -i -n standby /dev/sda)
Systems with multiple hard drives can apply the rule in a flexible way according to some criteria. For example, to allow all rotational drives to spin down after 15min: In /etc/udev/rules.d/69-hdparm.rules:

ACTION=="add|change", KERNEL=="sd[a-z]", ATTRS{queue/rotational}=="1", RUN+="/usr/bin/hdparm -B 254 -S 242 /dev/%k"

Other option: hd-idle (I did not use / try it)

Worth trying if hdparm doesn't work, also has nice options.

sudo systemctl start hd-idle.service
sudo systemctl enable hd-idle.service
sudo systemctl status hd-idle.service
sudo hd-idle -i 0 -a /dev/sda -i 1200 -l /var/log/hd_idle.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment