Skip to content

Instantly share code, notes, and snippets.

@mbierman
Last active September 26, 2023 17:56
Show Gist options
  • Save mbierman/85c9672d212bdda09d9d4f5d27574d1f to your computer and use it in GitHub Desktop.
Save mbierman/85c9672d212bdda09d9d4f5d27574d1f to your computer and use it in GitHub Desktop.
Mount/unmount USB on Firewalla
#!/bin/bash
# V 1.0
# Copyright Michael Bierman
# https://gist.github.com/mbierman/85c9672d212bdda09d9d4f5d27574d1f
mount_point=/mnt/usb-stick/
mounted=$(mount -l | grep -c "/mnt/usb-stick")
if [ "$1" = "u" ] && [ "$mounted" -eq "1" ] ; then
read -p "Want to Unmount the drive. Please press 'Y' to continue or any key to stop: " -n1 now
if [[ "$now" = "Y" || "$now" = "y" ]]; then
sudo umount $mount_point && \
mounted=$(mount -l | grep -c "/mnt/usb-stick")
if [ "$mounted" -eq "0" ] ; then
echo "✅ Drive unmounted. Save to remove!"
else
echo "⛔️ Drive not unmounted. DO NOT Remove!"
fi
exit
fi
fi
read -p "Insert USB. Please press 'Y' to continue or any key to stop: " -n1 now
if [[ "$now" = "Y" || "$now" = "y" ]]; then
lsusb
drive="/dev/$(lsblk -o NAME,TRAN | grep 'sd' | grep -E '[0-9]' | sed -e 's/─//g' -e 's/└//g')"
if [ ! -d $mount_point ]; then
sudo mkdir $mount_point
fi
mounted=$(mount -l | grep -c "/mnt/usb-stick")
if [ "$mounted" -eq "0" ] ; then
sudo mount $drive $mount_point
elif [ "$mounted" -eq "1" ] ; then
echo -e "✅ Drive mounted. to unmount, run again,\n\n $0 u\n"
fi
ls $mount_point
cd $mount_point
echo $mount_point
else
exit
fi
@mbierman
Copy link
Author

mbierman commented Sep 23, 2023

What

You can use this to mount or unmount a USB dive on Firewalla.

Why

You might want to throw a USB to backup some files or for a little extra space that doesn't impinge in Firewalla. (e.g. running a docker container)

Install

  1. SSH into your Firewalla (learn how if you don't know how already.)
  2. Create the file and permissions.
sudo touch /data/mount_usb.sh && sudo chmod 777 /data/mount_usb.sh
  1. Save this file and change permissions
sudo curl -s -L -C - 
"https://gist.githubusercontent.com/mbierman/85c9672d212bdda09d9d4f5d27574d1f/raw/9152d1e2f507e6385001958dc58be3e04782c888/mount_usb.sh" > /data/mount_usb.sh

Mount

/data/mount_usb.sh

Unmount

/data/mount_usb.sh u

Format

You may want to format the drive (NOTE: This will erase any contents!)
$ sudo mkfs.ext4 /dev/sda1

Note the "/dev/sda1" part you have to check using

$ lsblk -o NAME,TRAN | grep 'sd' | grep -E '[0-9]' | sed -e 's/─//g' -e 's/└//g'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment