Created
March 25, 2024 15:44
-
-
Save rms1000watt/45dd96ef9662121710306343caf84bd4 to your computer and use it in GitHub Desktop.
remount my removable storage on my raspberry pi
This file contains hidden or 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
#!/usr/bin/env bash | |
set -e | |
# check if disk is attached | |
sda1_attached=false | |
sdb1_attached=false | |
if lsblk | grep -q "sda1"; then | |
sda1_attached=true | |
fi | |
if lsblk | grep -q "sdb1"; then | |
sdb1_attached=true | |
fi | |
if [[ "${sda1_attached}" == "true" ]] && [[ "${sdb1_attached}" == "true" ]]; then | |
echo "ERROR: both sda1 and sdb1 are attached.. only 1 should be attached" | |
exit 1 | |
fi | |
if [[ "${sda1_attached}" == "false" ]] && [[ "${sdb1_attached}" == "false" ]]; then | |
echo "ERROR: neither sda1 and sdb1 are attached.. check if drive is plugged in" | |
exit 1 | |
fi | |
disk_name="/dev/sda1" | |
if [[ "${sdb1_attached}" == "true" ]]; then | |
disk_name="/dev/sdb1" | |
fi | |
echo " | |
sda1_attached=${sda1_attached} | |
sdb1_attached=${sdb1_attached} | |
disk_name=${disk_name} | |
" | |
# check if remount is needed | |
if mount | grep -q "${disk_name} on /mnt/usb1"; then | |
echo "No remount is needed.." | |
exit 0 | |
fi | |
# umount and mount | |
sudo umount /mnt/usb1 | |
sudo mount "${disk_name}" /mnt/usb1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment