Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question

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.


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


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

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

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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