[{"content":"Why I built this I wanted a place to back up my lab machines without buying a commercial NAS. Everything in this build is free and open source, and I tried to spend as little as possible.\nI followed this YouTube tutorial for the overall approach. It used NTFS and several drives, and I changed it to fit what I had: one drive, btrfs, and a Samba share. The tutorial is great, but a few of its steps didn\u0026rsquo;t apply to my setup, and that\u0026rsquo;s part of the story below.\nWhat I used, and what it cost Item Cost (UGX) Raspberry Pi 2B 0 (from a colleague) Toshiba 1 TB 2.5\u0026quot; laptop hard drive (after bargaining) 130,000 Haysenser dual-bay HDD docking station, with its own power adapter 110,000 SD card, power supply, Ethernet cable 0 (already owned) Total spent 240,000 Why a Pi 2B? In Uganda I could only find a Pi 4 or newer, at about 385,000 UGX for the board alone. Buying that new would have pushed the total to about 625,000 UGX. A colleague had a Pi 2B, so I used it. It\u0026rsquo;s slower, but for scheduled backups it\u0026rsquo;s good enough.\nThe rest of the setup relies on infrastructure I already had: the router, the cables, the SD card and a power supply.\nThe whole setup: the Pi sits on my fibre router and plugs straight into it with an Ethernet cable. The Toshiba drive sits in the dock beside it, which has its own power. (I covered the drive\u0026rsquo;s serial number, QR code and shop stickers.)\nThe limits of a Pi 2B USB 2.0 only, so the dock can\u0026rsquo;t run at full speed 100 Mbps Ethernet, so expect roughly 8 to 11 MB/s 32-bit, which limits which NAS software runs on it For nightly backups that\u0026rsquo;s fine. For a first big copy, it\u0026rsquo;s slow.\nWhy a docking station? A dock holds a bare drive and powers it from its own adapter. That means the Pi\u0026rsquo;s USB port only carries data, so there are no under-power disconnects, and I can swap drives without opening anything. Mine is a Haysenser dual-bay dock that takes both 2.5\u0026quot; and 3.5\u0026quot; drives, so it can also hold a bigger drive later.\nBefore I bought this, I looked at a listing for a 3.5\u0026quot; SAS drive. It would never have worked: the Pi has no SAS support, and a 3.5\u0026quot; drive needs its own 12V power. A 2.5\u0026quot; SATA laptop drive in a dock is the easy route.\nStep 1: Install the OS I flashed Raspberry Pi OS Lite (32-bit) with Raspberry Pi Imager, set the hostname to Nas, enabled SSH and created a user. The Pi 2B has no Wi-Fi, so it needs a cable.\nAfter the first boot I logged in over SSH and updated everything:\nsudo apt update \u0026amp;\u0026amp; sudo apt full-upgrade -y Step 2: Find the drive I connected the dock to the Pi and ran lsblk. Before touching anything, I confirmed which device was which:\nsda (931.5G) was the Toshiba drive in the dock mmcblk0 (59.5G) was the SD card The drive already had two partitions from Windows, which is why I double-checked. Formatting the wrong device would have wiped the OS.\nStep 3: NTFS or btrfs? The tutorial used NTFS. NTFS has one big advantage: if the Pi dies, I can plug the drive into any Windows PC. I chose btrfs instead, for its checksums, which detect silent corruption, and for its better behaviour after power cuts.\nThe trade-offs I accepted:\nWindows can\u0026rsquo;t read btrfs natively, so recovery means a Linux live USB or the WinBtrfs driver On a single drive, btrfs can detect corruption but can\u0026rsquo;t repair data A single drive is still not a safety net Step 4: Partition, format, mount sudo parted /dev/sda --script mklabel gpt mkpart primary btrfs 0% 100% sudo mkfs.btrfs -f -L nasbackup /dev/sda1 sudo mkdir -p /mnt/nas sudo blkid /dev/sda1 Then I added this line to /etc/fstab, using the UUID from blkid (not the UUID_SUB value):\nUUID=\u0026lt;your-uuid\u0026gt; /mnt/nas btrfs defaults,noatime,nofail 0 0 nofail means the Pi still boots if the dock is off or unplugged. This matters with a dock: switch the dock on before the Pi boots, or the drive won\u0026rsquo;t mount.\ndf -h /mnt/nas showed 932G, so the mount worked:\nStep 5: A dedicated backup user I didn\u0026rsquo;t want to hand out my admin account, so I created a user that can\u0026rsquo;t log in to the Pi and only exists for the share:\nsudo adduser --disabled-password --gecos \u0026#34;\u0026#34; nasuserqk sudo smbpasswd -a nasuserqk sudo chown -R nasuserqk:nasuserqk /mnt/nas sudo chmod 775 /mnt/nas Mistakes I made here Capital letters. I first typed nasuserQK. Linux said invalid user, so I made it lowercase. Running smbpasswd with no arguments. It asked for an \u0026ldquo;old SMB password\u0026rdquo; because it was trying to change my password. The correct command is sudo smbpasswd -a \u0026lt;username\u0026gt;. Copying the tutorial blindly. It used NTFS mount options (uid=, gid=) that btrfs doesn\u0026rsquo;t use. With btrfs, chown does that job. I also skipped its four-drive folders and its rsync mirroring, since I only have one drive. Step 6: The Samba share I added this to the bottom of /etc/samba/smb.conf:\n[nasbackup] path = /mnt/nas browseable = yes read only = no valid users = nasuserqk force user = nasuserqk create mask = 0664 directory mask = 0775 Then I ran testparm -s and restarted Samba with sudo systemctl restart smbd.\nStep 7: Connecting from Windows (where it got interesting) My PC is joined to my lab\u0026rsquo;s Active Directory domain, so Windows tried to log in as DOMAIN\\... instead of as a local account on the Pi. I had also typed the username wrong. The fix was to use Nas\\nasuserqk (or .\\nasuserqk) as the username.\nThen copying a file failed with \u0026ldquo;Destination Folder Access Denied\u0026rdquo;. The clue was in the dialog: total size 58 GB. My drive is 932 GB, and 58 GB is the size of the SD card.\nI had mapped the wrong share. Windows labels a mapped drive with the share\u0026rsquo;s name, and mine said nasuserqk, not nasbackup. The 58 GB size gave it away: that was the SD card, not my 1 TB drive:\nThe fix was to disconnect it and map the correct share:\nnet use N: /delete net use N: \\\\\u0026lt;pi-ip\u0026gt;\\nasbackup /user:Nas\\nasuserqk /persistent:yes Windows then showed nasbackup with 931 GB total. That\u0026rsquo;s the Toshiba drive:\nLesson: after connecting to any NAS, check the total size before you copy anything. If the size doesn\u0026rsquo;t match your drive, you\u0026rsquo;re in the wrong place.\nStep 8: Does it work? Yes. With the correct share mapped, Windows shows nasbackup with 931 GB total and 929 GB free. That\u0026rsquo;s the Toshiba drive, so backups land on the 1 TB disk and not on the SD card.\nI haven\u0026rsquo;t benchmarked it. On the Pi 2B\u0026rsquo;s 100 Mbps Ethernet, expect roughly 8 to 11 MB/s, which is fine for scheduled backups and slow for a first big copy. To keep an eye on the drive, sudo btrfs scrub start /mnt/nas checks the data checksums, and sudo smartctl -a -d sat /dev/sda reads the drive\u0026rsquo;s health data through the dock (some docks don\u0026rsquo;t pass it through).\nWhat I\u0026rsquo;d do differently Use a Pi 4 or 5 if the price allowed, for gigabit Ethernet and USB 3.0 Add a second drive (the dock makes swapping easy) or an offsite copy, because one disk is not a backup strategy Set up btrfs snapshots to protect against accidental deletes Join the Pi to my Samba AD domain, so people log in with their own accounts instead of a shared password Final thoughts The whole thing cost 240,000 UGX, and the most expensive part was the drive. It isn\u0026rsquo;t fast and it isn\u0026rsquo;t fancy, but it gives me a second copy of my lab data on hardware I control. If you\u0026rsquo;re in Uganda and a new Pi at 385,000 UGX is out of reach, ask around for an old board. Mine came from a colleague\u0026rsquo;s drawer.\n","permalink":"https://notes.khomelabug.org/posts/pi-nas-btrfs/","summary":"A borrowed Pi 2B, a 1 TB Toshiba laptop drive and a docking station, for 240,000 UGX. What worked, what broke, and what I\u0026rsquo;d do differently.","title":"Building a Backup NAS on a Raspberry Pi 2B with btrfs and Samba, the Ugandan Way"},{"content":"Hi, I\u0026rsquo;m Sapienk 👋 I work in digital security in Uganda, and outside my work I\u0026rsquo;m a tech enthusiast who learns by building things, breaking them, and writing down what happened.\nWhy I started a home lab Most of my work as a trainer is theory. I started asking why the theory works, and that\u0026rsquo;s when the Dunning-Kruger effect hit me: I didn\u0026rsquo;t know as much as I thought I did. My job wasn\u0026rsquo;t about setting things up, so I had to find my own way to learn it. The home lab became that way.\nWhat\u0026rsquo;s in my lab Everything I run is free and open source. That\u0026rsquo;s deliberate. Many small organisations in Uganda can\u0026rsquo;t afford proprietary tools, so I wanted to find out which options actually work.\nSamba Active Directory domain controller on Ubuntu, running on Proxmox pfSense firewall Raspberry Pi 2B NAS with a 1 TB drive, btrfs and Samba Kali Linux VM, where this blog is written Plus security, networking, servers and VMs, whatever I\u0026rsquo;m trying this month It\u0026rsquo;s also helping my Bachelor\u0026rsquo;s studies in IT, because I get to practise what the lectures describe.\nWhy \u0026ldquo;the Ugandan way\u0026rdquo;? The tutorials out there are great, but when you try to follow them here, things fall short. They point to shops we can\u0026rsquo;t reach, quote prices in dollars while our shilling moves every day, and assume hardware that\u0026rsquo;s out of budget. I write about what it really takes to build these things here, one step at a time.\nWhat you\u0026rsquo;ll find here Hands-on projects, honest write-ups, and the mistakes included. If you\u0026rsquo;re a Ugandan tech enthusiast who likes building things: it\u0026rsquo;s possible, one step at a time.\nSay hello ","permalink":"https://notes.khomelabug.org/about/","summary":"Who is behind the notes","title":"About"}]