Denys Vlasenko | e306c11 | 2013-03-30 16:23:12 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Seconds to try to reread partition table |
| 4 | cnt=60 |
| 5 | |
| 6 | exec </dev/null |
| 7 | exec >"/tmp/${0##*/}.$$.out" |
| 8 | exec 2>&1 |
| 9 | |
| 10 | ( |
| 11 | echo "Running: $0" |
| 12 | echo "Env:" |
| 13 | env | sort |
| 14 | |
| 15 | while sleep 1; test $cnt != 0; do |
Denys Vlasenko | 2df1c64 | 2013-04-02 13:26:24 +0200 | [diff] [blame] | 16 | echo "Trying to reread partition table on $DEVNAME ($cnt)" |
Denys Vlasenko | 08dfafc | 2017-07-15 19:18:58 +0200 | [diff] [blame] | 17 | cnt=$((cnt-1)) |
Denys Vlasenko | 2df1c64 | 2013-04-02 13:26:24 +0200 | [diff] [blame] | 18 | # If device node doesn't exist, it means the device was removed. |
| 19 | # Stop trying. |
Denys Vlasenko | e306c11 | 2013-03-30 16:23:12 +0100 | [diff] [blame] | 20 | test -e "$DEVNAME" || { echo "$DEVNAME doesn't exist, aborting"; exit 1; } |
| 21 | #echo "$DEVNAME exists" |
Denys Vlasenko | 2df1c64 | 2013-04-02 13:26:24 +0200 | [diff] [blame] | 22 | if blockdev --rereadpt "$DEVNAME"; then |
| 23 | echo "blockdev --rereadpt succeeded" |
| 24 | exit 0 |
| 25 | fi |
Denys Vlasenko | e306c11 | 2013-03-30 16:23:12 +0100 | [diff] [blame] | 26 | echo "blockdev --rereadpt failed, exit code: $?" |
| 27 | done |
Denys Vlasenko | 2df1c64 | 2013-04-02 13:26:24 +0200 | [diff] [blame] | 28 | echo "Timed out" |
Denys Vlasenko | e306c11 | 2013-03-30 16:23:12 +0100 | [diff] [blame] | 29 | ) & |