Setting up OpenBSD automount/hotplug USB Drive - If you are like me, you get really tired of having to manually mount your USB stick every time you want to use it. Good for security though, right? In this tutorial, I will show you how to use a magic file to automount your USB stick. You will not have to manually mount it or type doas and your password every time you want to copy files to a USB drive.
First, You will need to create a folder under /mnt (mkdir /mnt/usb)
Next, we want to create a script called attach in /etc/hotplug/ which
looks for the presence of /tmp/automount to execute the USB automount.
#!/bin/sh DEVNAME=$2 export DISPLAY=:0.0 DEVCLASS=$1 if [[ -e /tmp/automount ]]; then case $DEVCLASS in 2) disklabel=`/sbin/disklabel $DEVNAME 2>&1 | \ sed -n '/^label: /s/^label: //p'` case $disklabel in *) /sbin/mount_msdos -o noexec,noatime,nodev -g 1000 -u 1000 /dev/"$DEVNAME"i /mnt/usb ;; esac ;; 3) sh /etc/netstart $DEVNAME ;; esac fi
Now we will create another short script called detach. This short script simply removes the /tmp/automount file, so that no one else can automount.
#!/bin/sh rm /tmp/automount
So now, you are the only one who knows to create the magic file to initiate the automount (touch /tmp/automount). Otherwise, manual mounting is required.
Now, we need to change the permissions on both files to 700
# chmod 700 attach detach
Finally we need to enable and start the hotplug daemon.
# rcctl enable hotplugd # rcctl start hotplugd
Now, simply type touch /tmp/automount and insert your USB stick to automount it. Just pull the USB stick out when you are finished.