Persistent USB External Disk
Specific use-case: attaching a large USB drive to the Raspberry Pi for persistent storage.
Contents
- Setting up a persistent USB external disk.
- Setting up a SAMBA share.
Persistent Disk Setup
Confirm Info
Login as pi, or the user you want to own the drive.
At the shell prompt, enter:
lsblk -f
Typical output:
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda
└─sda1 ext4 1.0 1TB 1234abcd-87ae-4a1a-808a-29287af611a1 561.1G 38%
Note or copy the UUID of the USB drive. We use UUID because it is unique to the current format of the drive.
(Optional) If FSTYPE is not ext4 (e.g. ntfs), I recommend backing up and formatting to ext4 with:
sudo mkfs.ext4 /dev/sda1
Although optional, ext4 makes the USB drive easier to manage and is recommended over ntfs. If there are ntfs errors, the drive will not be mountable and a Windows machine is required to reset the file system.
Note: the UUID will change if the drive is re-formatted.
Configure mount point
Create a mount point for the USB drive:
sudo mkdir /mnt/1TB
Next, add an entry to /etc/fstab to mount the USB drive on boot:
sudo nano /etc/fstab
Add the following line to the end of the file:
UUID=1234abcd-87ae-4a1a-808a-29287af611a1 /mnt/1TB ext4 defaults,nofail,x-systemd.device-timeout=30 0 2
Ctrl+O, Ctrl+X to output the file and exit the editor.
This mounts the USB drive on boot but does not cause the system to fail to boot if the drive is not present.
Test the mount
sudo mount -a
df -h | grep /mnt/1TB
You should see something like:
/dev/sda1 917G 28K 871G 1% /mnt/1TB
Set user ownership
ext4 uses real permissions. ntfs, in contrast, needs you to define user/group in the mount options. Make the mount point owned by pi (or your defaultt user) to avoid permission issues:
sudo chown pi:pi /mnt/1TB
Test:
ls -ld /mnt/1TB
Expected output:
drwxr-xr-x 2 pi pi 4096 Jul 30 15:30 /mnt/1TB
Now pi can create files normally:
touch /mnt/1TB/test.txt
Setup SAMBA
Install SAMBA
sudo apt install samba
Install other recommended packages.
Create the share directory:
sudo mkdir /mnt/1TB/share
Configure SAMBA in Webmin
The following steps assume you have installed webmin.
Open a browser on your PC and go to: https://<raspberry_pi_ip>:10000.
If this is your first time, you will be alerted that the connection is not secure because of certificate issues. You can usually ignore this and proceed to the login page. Login with your pi credentials.
Navigate to Un-used Modules then Samba Windows File Sharing.
Use the GUI to:
- Convert Users to Samba Users (e.g. Unix user
pito Samba userpi). - Create a new file share.
- Start the Samba service.
Test the share in Windows by opening File Explorer and navigating to \\<raspberry_pi_ip>\share. You should see the files from the USB drive.
Note: Samba shares are not by default discoverable on the network. However, the AVAHI service means that you can use \\<raspberry_pi_name>.local to address the server and find the share.