Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In an effort to create a Linux installation script, I'd like to check if /dev/sda is currently in use by the Kernel, and exit if so. I guess this means finding out what partitions are associated to the device and see if any of them is mounted... am I right with my guess? Is it possible for a device to be in use without having a mounted partition? What's the best way I should make the test? This is what I've come up with until now:

if [ $(findmnt -no SOURCE | grep ^/dev/sda) ];
then
    echo 'Hard disk drive is already in use.'
    exit
fi

I'd appreciate any suggestions.

share|improve this question
    
Yes, it is possible if something accesses the partition/harddisk directly (f.e. dd if=/dev/sda1 ...). –  Bobby Jun 20 '13 at 10:24

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.