I have a script which writes data to an SD card connected via USB,
then umounts it.
The data is several GB in size so it hangs at the umount stage while
the writes complete, and I want to give user feedback.
(Note: I have had no luck whatsoever using sync to force the data to
sync first, it always returns immediately.)
At the moment I send umount into the background and grep /proc/meminfo
for a "Dirty" value which I display, repeating until the umount
command closes. This is reliable and fairly meaningful, but because it
takes a few minutes is throwing a kernel INFO message into syslog:
INFO: task umount:17976 blocked for more than 120 seconds
Ideally I would just wait for writes to complete before even trying to
umount, but I can't see a way to do that. Is there a way to determine
if (say) /dev/sdc is still busy, and if so how much data is pending?
Or any other suggestions?
Current code (modified a bit for clarity in posting):
echo -e "\n\nWaiting for writes to complete"
sudo umount /dev/sdc[1-9] &
while jobs -r | grep 'Running' > /dev/null ; do
pending=$(grep -Po 'Dirty: *\K.*' /proc/meminfo)
echo -ne "\rBuffer remaining: ~$pending "
sleep 1
done
echo -e "\rUnmounted - you can now remove the disk.
"
--
Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450
Registered in England (0456 0902) 21 Drakes Mews, Milton Keynes, MK8 0ER