mkfs: avoid blockdev failing to re-read partition table mika/273
authorMichael Prokop <mika@grml.org>
Thu, 25 Apr 2024 15:02:20 +0000 (17:02 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 25 Apr 2024 15:13:06 +0000 (17:13 +0200)
commit9b2cf8303e8e403b1bd9eaa5dbf6f3e795a4f426
tree6c5f0d99863fda0c142c890109cdbda93587fdbf
parentfa44c61d9c8b7a1559d409a0d6f8fbdcb7350cac
mkfs: avoid blockdev failing to re-read partition table

Invoking `blockdev --rereadpt` straight after creating the file system
might fail with:

| blockdev: ioctl error on BLKRRPART: Device or resource busy
| Unexpected non-zero exit code 1 in /sbin/grml-debootstrap /sbin/grml-debootstrap /sbin/grml-debootstrap at line 1376 2132 0 detected!
| last bash command: blockdev --rereadpt "$main_device"

This is caused by udev kicking in and causing a race condition. Let's
invoke udevadm settle (which watches the udev event queue, and exits if
all current events are handled), and then retry `blockdev --rereadpt
...` up to 30 times/seconds.

Thanks: Darshaka Pathirana for bug report and initial investigation, and Chris Hofstaedtler for feedback
Closes: https://github.com/grml/grml-debootstrap/issues/273
grml-debootstrap