We are starting with an unformatted and unpartitioned SSD connected to the RPi USB port.
- Update your rig
sudo apt update && sudo apt upgrade -y
- Raberry Pi online docs recommend installing exfat-fuse but,
you wont need it if you are formatting fresh drives.
sudo apt-get install exfat-fuse
- find the device
NAME
If it is the only hard drive connected it should be 'sda'. This means the device is located atsudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL
/dev/sda
. You can go check if you want. - It's easy to export this so we don't need to remember it.
export DRIVE=/dev/sda
- Lets Partition the drive
sudo fdisk $DRIVE
- You are now in the fdisk control space.
d
will delete any prior partitions.n
creates new partitions (Defaults will produce a single partition spanning the entire drive).w
writes the changes and exits.p
displays the current partitions.m
for help/manual.
- Time to give that new partition a filesystem.
1
is added due to being the first partition on the drive.sudo mkfs -t vfat -I $DRIVE"1"
- Create a mount point for the drive, generally in
media
ormnt
.export MOUNT="/mnt/SSD" && \ sudo mkdir -p $MOUNT && \ sudo chmod 777 $MOUNT
- Mount it. Note we mount partition1.
sudo mount $DRIVE"1" $MOUNT -o umask=000
- https://thepihut.com/blogs/raspberry-pi-tutorials/17699796-formatting-and-mounting-a-usb-drive-from-a-terminal-window
- https://www.raspberrypi.org/documentation/configuration/external-storage.md
Create an entry for the drive in /etc/fstab
export UUID=$(sudo blkid $DRIVE | awk '{print substr($2,7,9)}') && \
sudo echo "UUID=$UUID $MOUNT vfat defaults,auto,umask=000,users,rw 0 0" | sudo tee -a /etc/fstab
Restart after this step to verify that the fstab setting is correct.
sudo reboot
If your RPi does not boot, don't worry you just need to correct it using the section below.
If something goes wrong when editing the fstab file in the previous step, your RPi will not boot. We gotta correct this as easy as possible. You could wipe the entire card and reload the raspian image, but lets just comment out the bad fstab line instead.
- Virtual Box Ubuntu VM
- USB 3.0 Expansion Pack for Virtual Box
On Mac Machine:
- Unmount MMC card from Mac machine
- Fire up ubuntu inside virtual box
- Go to Devices>USB to enable your MMC card in Ubuntu
rootfs
drive partition is what we want- find your jacked fstab file and sudo edit it.
- Comment out the botched fstab entry
https://inderpreetsingh.com/2014/11/02/ext4-repair-on-mac-osx/
Now, the drive is partitioned, imaged, and set to mount on start. It is time to install the NFS server and configure it.
- Pre-reqs
sudo apt-get install nfs-kernel-server portmap nfs-common
- Make NFS folder and give lenient permissions for local network
mkdir -p $MOUNT/nfs && \ sudo chmod -R 777 $MOUNT/nfs sudo chown nobody:nogroup $MOUNT/nfs
- Add shared folder to
/etc/exports
sudo echo -e "$MOUNT/nfs"\t"192.168.1.0/24(rw,sync,no_subtree_check,insecure,all_squash)" >> /etc/exports
- Reset exports
sudo exportfs -a
- And restart nfs service
sudo systemctl restart nfs-kernel-server
- install nfs utils
sudo apt install nfs-utils nfs-common
- Create local mount directory
export LOCAL_MOUNT_DIR=/mnt/nfs1 && \ sudo mkdir -p $LOCAL_MOUNT_DIR
- Use the mount.nfs tool
export NFS_IP=nfs1.local && \ export NFS_MOUNT_DIR=/mnt/SSD/nfs && \ sudo mount.nfs $NFS_IP:$NFS_MOUNT_DIR $LOCAL_MOUNT_DIR
https://serverfault.com/questions/306204/what-are-typical-nfs-read-write-rates
Test NFS Write speed:
time dd if=/dev/zero of=$LOCAL_MOUNT_DIR/testfile bs=16k count=128k
Test NFS Read speed:
time dd if=$LOCAL_MOUNT_DIR/testfile of=/dev/null bs=16k
sudo echo "$NFS_IP:$NFS_MOUNT_DIR $LOCAL_MOUNT_DIR nfs4 _netdev,auto 0 0" | sudo tee -a /etc/fstab