7

Is there a (safe) way to umount all partitions on all attached usb devices (usb-hdds, usb-sticks) with a single commandline command, including several encrypted luks partitions?

Only the partitions on the usb-devices should be umounted, nothing more!

3

Tried my best to stay posix with this, note that it will fail if you do not have a suitable "udevadm" package available for displaying udev info.

#!/bin/bash

command_exists () {
    type "$1" &> /dev/null
}

CMD=""

if command_exists udevadm; then
        CMD="$(which udevadm) info -q all -n"
fi

if command_exists udevinfo; then
        CMD="$(which udevinfo) -q all -n"
fi

echo "The udevinfo command for this system is $CMD"


for disk in /dev/sd*
do
        DISK=$($CMD $disk | grep ID_BUS)
        if [[ "$DISK" == *usb ]]; then
                echo "$disk is USB, now unmounting.."
                umount $disk
        fi
done
  • Thanks, but it doesn't work for the luks partitions. – student Jul 21 '12 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.