0

I have an SD card that's connected via a USB interface.

The output of fdisk -l indicates the following:

Disk /dev/sdb: 3965 MB, 3965190144 bytes

I have a script that re-initializes multiple partitions on a disk using mkfs.ext4 and mkfs.vfat commands, all followed by a sync. Although the sync command finishes with an exit code of 0, the light on the USB SD adapter is still flashing (indicating disk activity).

Currently, in my script I have a count-down timer to just count-down 90 seconds, which I've determined is 'good enough' to ensure that the disk isn't busy before the next operation, but it's really a hack.

Question: Is there a generic way to check whether the physical device /dev/sdb is being accessed, regardless of operation (i.e. including re-writing partitions, re-reading the partition table using sfdisk, or accessing a file on a partition on the disk)?

I've tried fuser /dev/sdb and fuser /dev/sdb*, but it doesn't achieve this goal - when the light is flashing on the USB SD card adapter, there's not always output from the fuser command.

1
  • dd is used as part of the script, but not in the area where I experience problems. So this command initializes the disk: dd if=/dev/zero of=${diskname} count=1 bs=1024
    – CJBS
    Jan 29, 2015 at 20:14

1 Answer 1

1

If you were using dd there is a command that would tell us if still doing its job

 sudo pkill -USR1 -n -x dd

Dont sound like that what you're doing.

I think the reason the activity light is still going after sync is because writing to SD Card tends to be slower...... Or did I totally miss the point

Sorry, couldn't find answer to question about checking if /dev/sdb is in use.

edit

Check out iotop

 sudo apt-get install iotop

Then run it with this command

 sudo iotop --only

This way it will show you only what in use.

Is this what your looking for? If not there are some other suggestions HERE

3
  • Thanks for the suggestion. After reviewing the man page, it appears that this will only work if it's the dd command that hasn't finished. I'm looking for something that will indicate any activity (regardless of which process initiated it).
    – CJBS
    Jan 29, 2015 at 20:42
  • @CJBS See my updated answer
    – geoffmcc
    Jan 29, 2015 at 20:53
  • +1 In theory, this should do what I want. I used it in non-interactive mode with the following command-line: iotop --batch --iter=1 -qqq | grep "dev/sdb" | grep -v grep ... However it seems there's a bug that prevents it from working: File "/usr/sbin/iotop", line 17, in <module> ... UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 115: ordinal not in range(128) ... I think I'll just stay with my countdown timer. Thanks for the help.
    – CJBS
    Feb 5, 2015 at 18:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .