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.
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