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
Disclaimer: I am not a fan of sleep loops, but I guess any other solution would need something similar "under the hood".
Just tested the PR and it works for me:
root@grml ~ # ./grml-debootstrap -r bookworm -t /dev/sda1 --grub /dev/sda --hostname grml-debootstrap --mirror http://mirror.hetzner.de/debian/packages
* EFI support detected, but system seems to be running in BIOS mode.
* grml-debootstrap [0.108] - Please recheck configuration before execution:
Target: /dev/sda1
Install grub: /dev/sda
Install efi: no
Using release: bookworm
Using hostname: grml-debootstrap
Using mirror: http://mirror.hetzner.de/debian/packages
Using arch: amd64
Config files: /etc/debootstrap
Important! Continuing will delete all data from /dev/sda1!
* Is this ok for you? [y/N] y
[...]
mke2fs 1.47.0 (5-Feb-2023)
/dev/sda1 contains a ext4 file system
created on Fri Jun 7 09:56:39 2024
Proceed anyway? (y,N) y
Discarding device blocks: done
Creating filesystem with 2096896 4k blocks and 524288 inodes
Filesystem UUID: 43bba0a1-121f-4666-95ee-2220b6d31079
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
* Disabling automatic filesystem check on /dev/sda1 via tune2fs
tune2fs 1.47.0 (5-Feb-2023)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
* Mounting /dev/sda1 to /mnt/debootstrap.9433
mount: (hint) your fstab has been modified, but systemd still uses
the old version; use 'systemctl daemon-reload' to reload.
* Identified UUID 43bba0a1-121f-4666-95ee-2220b6d31079 for /dev/sda1
* Running debootstrap for release bookworm (amd64) using http://mirror.hetzner.de/debian/packages
* Executing: debootstrap --arch amd64 bookworm /mnt/debootstrap.9433 http://mirror.hetzner.de/debian/packages
[...]
I can not recall the mount: (hint) your fstab has been modified line, but apart from that, the fix works.