I was recently inspired by one of my coworkers to attempt to configure a Raspberry Pi to be used as a NAS. Throughout the past week, I did a little research and came up with a plan and then executed it over the weekend. I roughly followed directions given by a link from PC Magazine and also used Chat GPT for trouble shooting.
---------------------------------------------------System ASCII block diagram
[Internet]
|
[GigaSpire GS4220E Router]
|
[Raspberry Pi 4]
├─ USB Flash Drive
└─ Running Samba, etc.
MacBook Pro as client computer
Raspberry Pi 4 Model B 8 GB Ram
GigaSpire GS4220E, 5 port Gigabit Ethernet Router (4 LAN and 1 WAN)
Cat5e or Cat6 Ethernet to support and prevent bottlenecking the Raspberry Pi 4 Model B's Gigabit Ethernet port
VNC Viewer on client computer
* I would have SSHed into the Raspberry Pi but I was having issues noted below.
Raspberry Pi OS -
Raspbian GNU/Linux 10 (buster)
To check OS version
cat /etc/os-release
GNU Parted 3.2
To check version
parted --version
GNU nano, version 3.2
To see version
nano --version
Samba version 4.9.5-Debian - Server Message Block (SMB) Communication Protocol
To check version
sudo smbstatus
Make sure Raspberry Pi is up to date
sudo apt update && sudo apt upgrade -y
Install Samba
sudo apt install samba samba-common-bin -y
We need to list information about all available block devices (i.e., storage devices) and their partitions.
The mmcblk0
device is typically your microSD card.
We are looking for storage devices labeled as sda
(Device A), sdb
(Device B), sdc
(Device C), etc.
lsblk
The fdisk -l
command gives us more technical, low-level details than lsblk
. It shows partition table information and requires sudo
privileges.
sudo fdisk -l
We need to unmount the partitions that were identified using lsblk
just to make sure the OS isn't actively using them so they can be formatted for Linux use.
In this example, my drive was identified as sda
, and the partition I want to unmount is sda1
.
umount /dev/sda1
Next we need to open the partition table editor for the entire drive so that we can erase and format your drive (sda)for Linux usage. When you run sudo parted /dev/sda
, it'll open a wizard called Parted, which will allow you to create a new partition on the drive
sudo parted /dev/sda
The first command we will use is mklabel gpt
(parted) mklabel gpt Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? Y
The next command we will use is mkpart
(parted) mkpart Partition name? []? partition1 File system type? [ext2]? ext4 Start? 0% End? 100% (parted) quit Information: You may need to update /etc/fstab.
* How to update /etc/fstab (This NAS project makes use of editing fstab)
Updating /etc/fstab requires administrative privileges, so make sure you are logged in as the root user or use the "sudo" command before making any changes. Here's a step-by-step guide:
1. Open /etc/fstab in a text editor: You can use any text editor you are comfortable with, such as nano or vi. For example, to open /etc/fstab using nano, run the following command in the terminal:
sudo nano /etc/fstab
2. Locate the entry you want to update: Each line in /etc/fstab represents a file system. Find the line corresponding to the storage device or partition you want to update.
3. Edit the entry: Modify the necessary fields, such as the mount point, file system type, options, and device path. Be cautious while making changes, as incorrect entries can cause issues.
4. Save and exit the text editor: In nano, press Ctrl + O to save the changes and Ctrl + X to exit the editor.
After updating /etc/fstab, you can either reboot your system for the changes to take effect or remount the file systems manually using the "mount" command. Remember to double-check your changes and ensure they are correct before rebooting.
So we created the partion with mkpart
, now we need to format it with Make ext2 Filesystem which is part of the e2fsprogs package
pi@raspberrypi:~ $ sudo mkfs.ext4 /dev/sda1 mke2fs 1.44.5 (15-Dec-2018) Creating filesystem with 3787264 4k blocks and 948416 inodes Filesystem UUID: bf5b1b5c-88be-472b-a5e5-060764b59ac8 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
Next, we need to name our drive
pi@raspberrypi:~ $ sudo e2label /dev/sda1 partition1
At this point, we can restart our pi with shutdown -r now
We now should see a drive with a name we gave it.
You will, however, have to run sudo chown -R pi /media/pi/MyExternalDrive
(replace MyExternalDrive with your drive's name) to give yourself permission to write new files to the drive.
When you open the drive, you will notice a folder call lost+found. What is lost+found?
* It’s a special Linux file system directory created automatically at the root of every ext2/ext3/ext4 file system.
* It’s used by fsck (the file system check utility) to store orphaned file fragments it recovers when the drive wasn't shut down properly or has corruption.
* It's created by the file system formatter, like mkfs.ext4, when the disk or partition is initialized.
🪇Samba time!
sudo nano /etc/samba/smb.conf
[MyMedia] path = /media/pi/partition1/ browseable = yes read only = no writeable = yes guest ok = no create mask = 0775 directory mask = 0775 public=no valid users = pi
To add a password to the existing pi user, run sudo smbpasswd -a pi
Restart Samba after editing
sudo systemctl restart smbd
Seagate 160 GB ST90000U2, 5V DC 650 mA, was f**king S**t up 🤬. It experienced some sort of failure that caused the shared folder to become read only. The drive had two usb a connectors, one data+power and the second was power only. I had the power only plugged into a j5create Model No JUP60 (5) 2.4 Amp USB A ports & (1) Quick Charge USB A port 3 Amps. Before figuring out it was a hard drive failure, I had gone through the following;
pi@raspberrypi:~ $ sudo chown -R $USER /media/pi/partition0 chown: changing ownership of '/media/pi/partition0/._.DS_Store': Read-only file system chown: changing ownership of '/media/pi/partition0/Test': Read-only file system chown: changing ownership of '/media/pi/partition0/lost+found': Read-only file system chown: changing ownership of '/media/pi/partition0/.DS_Store': Read-only file system chown: changing ownership of '/media/pi/partition0': Read-only file system
I tried the following to no avail:
pi@raspberrypi:~ $ mount | grep /media/pi/partition0 /dev/sda1 on /media/pi/partition0 type ext4 (ro,nosuid,nodev,relatime,errors=remount-ro,uhelper=udisks2) sudo mount -o remount,rw /dev/sda1 sudo shutdown -r pi@raspberrypi:~ $ mount | grep /media/pi/partition0 /dev/sda1 on /media/pi/partition0 type ext4 (rw,nosuid,nodev,relatime,errors=remount-ro,uhelper=udisks2)
I checked the filesystem type
pi@raspberrypi:~ $ df -Th /media/pi/partition0 Filesystem Type Size Used Avail Use% Mounted on /dev/sda1 ext4 146G 61M 139G 1% /media/pi/partition0
Check Mount Options
pi@raspberrypi:~ $ cat /proc/mounts | grep sda1 /dev/sda1 /media/pi/partition0 ext4 ro,nosuid,nodev,relatime,errors=remount-ro 0 0
Check if it’s writable again:
touch /media/pi/parttition0/test999
I finally checked to see if there are power issues which ultimately solved the mystery.
dmesg | grep -i usb
I fed Chat GPT the results and...⚠️ Your USB drive is having serious communication issues — likely power-related or cable/hardware failure.
And then…
Oh no — that "clunk-dit-dit" rhythmic sound is not good. That's often called the click of death in hard drive circles.
What That Usually Means:
That sound typically comes from the drive's actuator arm repeatedly trying and failing to read from the disk. It's mechanical and often means:
The drive is failing or already failed.
It might be struggling to spin up due to low power.
The internal firmware is restarting the read process, hence the rhythm.
It could also be a bad controller board on the drive.
After several days of spinning my wheels trying to figure out why I couldn’t establish a proper Ethernet cable connection to my router, I discovered that my MacBook was set to share its internet connection, effectively turning it into a router that was handing out IP addresses.
mac OS Command+K – shortcut to connect to a server
control+D to end SSH session with Raspberry Pi without shutting it down
iOS Files app, Open the app, navigate to the Browse view, and select the three dots icon in the top right of the screen
hostname -I #to see ip address of raspberry pi on the network ifconfig #for more detail netstat -i #activity on network interfaces like eth0(ethernet) wlan0(Wi-Fi) route -n #how network traffic is routed netstat -tuln #what devices are connected to raspberry pi arp -a #ip addresses along with the corresponding MAC addresses #arp address resolution protocol #route Routing Table #netstat Network Statistics #ifconfig Interface Config