Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
share|improve this answer
    
Thanks, but it doesn't work for the luks partitions. –  student Jul 21 '12 at 14:08
add comment

Your Answer

 
discard

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.