Ok, so so far I have the following which lets a user specify devices that are not USB and removes those specific entries from /etc/mtab, storing them in /tmp/mountedusb. From that file the script issues the umount command to unmount all the entries in /tmp/mountedusb. The script gives an "exit 1" to abort suspend/hibernation if umount fails along the way. Is it possible to avoid the use/creation of /tmp/mountedusb and have everything done by passing things in memory? Anything else I might be missing that I should include to make it a little more robust?
Code:
#!/bin/sh
# devices that are known to not be USB
NONUSB="/dev/sda /dev/sdc"
DEVICES="0000:00:1a.0 0000:00:1d.0"
case "${1}" in
hibernate|suspend)
# writes to disk
/bin/sync
# extract first column of /etc/mtab, remove everything that is not /dev/sd?
cat /etc/mtab | cut -d" " -f1 | grep /dev/sd > /tmp/mountedusb
# remove devices listed in NONUSB, essentially creating a file that contains only
# USB/removable devices
for nu in $NONUSB; do
cat /tmp/mountedusb | grep -v $nu > /tmp/mountedusb.tmp
mv -f /tmp/mountedusb.tmp /tmp/mountedusb
done
# unmount devices, abort suspend if umount fails
for um in `cat /tmp/mountedusb`; do
/bin/umount $um 2> /dev/null
if [ $? -gt 0 ]; then
exit 1
fi
done
# Unbind ehci_hcd for all devices
for d in $DEVICES; do
echo -n "$d" | tee /sys/bus/pci/drivers/ehci_hcd/unbind
done
;;
resume|thaw)
# Bind ehci_hcd for all devices
for d in $DEVICES; do
echo -n "$d" | tee /sys/bus/pci/drivers/ehci_hcd/bind
done
;;
esac