Last active
September 26, 2023 17:56
-
-
Save mbierman/85c9672d212bdda09d9d4f5d27574d1f to your computer and use it in GitHub Desktop.
Mount/unmount USB on Firewalla
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Mount
Unmount
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