Skip to main content
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266
Source Link

Wait to Mount Until Process Not Busy

I am writing/reading to an SSD over NVMe. I would like to unmounts the SSD partitions and remount them after writing and before reading so as to avoid caching problems. It seems when I try to perform this operation, I get an error saying that the device is busy and it does not perform this action.

Here are the commands

/root/bin/mountfs -u sleep 5 /root/bin/mountfs -m sleep 10 

Here is mountfs

#!/bin/bash # Mount/unmount ext4 file systems exit_status=1 if [ "-m" = "$1" ] then mount -t ext4 /fsmnt/fs1 mount -t ext4 /fsmnt/fs2 mount -t ext4 /fsmnt/fs3 mount -t ext4 /fsmnt/fs4 exit_status=0 elif [ "-u" = "$1" ] then umount /fsmnt/fs1 umount /fsmnt/fs2 umount /fsmnt/fs3 umount /fsmnt/fs4 exit_status=0 else echo "mountfs -m | -u" fi exit $exit_status 

Is there any way in bash to programmatically wait for all reads/writes to complete, so the devices are not busy and I can successfully remount the partitions to clear NVMe Controller/OS caches?