Super User is a question and answer site for computer enthusiasts and power users. 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

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

You must log in to answer this question.

Browse other questions tagged .