Auto Mounting External USB drives

Brian Cluff brian at SnapTek.com
Wed Sep 9 17:01:05 MST 2020


You could use the mountpoint command to check if there is something 
mounted on destination drive like:

if ! mountpoint $DESTINATION_DIR >/dev/null; then
         mount -t ntfs PARTUUID=c6040663-9321-4d28-91f0-2f3eb35f72b7 
/mnt/Ext3TB_Data1/
fi
if ! mountpoint $DESTINATION_DIR >/dev/null; then
         mount -t ntfs PARTUUID=f88c9c86-e44d-4846-9fbe-305074347e97 
/mnt/Ext3TB_Video1/
fi

I'll leave it up to you to handle what to do if the drive doesn't mount.

Brian Cluff

On 9/9/20 1:34 PM, AZ Pete via PLUG-discuss wrote:
> Hi all,
>
> I was finally able to do away with an aging Windows machine and 
> replace it with a Raspberry Pi 4 running Buster.  The only purpose for 
> this server is to backup selected folders and files from other servers 
> onto two external USB drives for offsite storage. I've automated the 
> backup process using rsync and a cron job. All is working well and the 
> backups are happening on schedule.
> However, currently I have to manually mount each of the external 
> drives. This isn't a terribly big issue since the drives are rotated 
> to offsite storage only once per month. But, if the Pi gets rebooted, 
> the drives are not being auto-mounted and the backups will then fail. 
> I've tried putting an entry in /etc/fstab to auto-mount them at boot, 
> but if they drives are not connected at boot time, I've found the the 
> Pi doesn't boot (it just seems to hang).
>
> Here is how I mount the drives.
> mount -t ntfs PARTUUID=c6040663-9321-4d28-91f0-2f3eb35f72b7 
> /mnt/Ext3TB_Data1/
> mount -t ntfs PARTUUID=f88c9c86-e44d-4846-9fbe-305074347e97 
> /mnt/Ext3TB_Video1/
>
> How can I "conditionally" mount an external drive based on if the 
> drive is currently connected? I could write a script that checks if 
> the particular partition (PARTUUID) is currently connected but not 
> mounted and put this script in the rc.local folder to be executed at 
> boot.
> Is this the best way? I'm sure that others have encountered this issue 
> and wanted to know what the "best practices" are on how to achieve this?
>
> Any thoughts would be appreciated.
>
> Thanks,
> Peter
>
>
>
>
>
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss at lists.phxlinux.org
> To subscribe, unsubscribe, or to change your mail settings:
> https://lists.phxlinux.org/mailman/listinfo/plug-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.phxlinux.org/pipermail/plug-discuss/attachments/20200909/0f790bea/attachment.html>


More information about the PLUG-discuss mailing list