This fixes a weird race that I observed when booting from usb, where
mount_subpartitons was called and:
1) rootfs on USB wasn't available so the first find_root_partition found nothing
2) the loop was entered to search for subpartitions
3) after a few iterations, the USB block device showed up along with its
partitions and the for loop was started
4) kpartx -afs created mappings for partitions on the disk (e.g.
/dev/sda), the rootfs was found by find_root_partition but the mappings
were never removed
5) Later when things like e2fsck or mount tried to operate on /dev/sda2,
they would fail with "in use" or "resource busy" errors
The fix for this is two parts:
* Don't try to look for subpartitions on whole disks (e.g /dev/sda),
it tests for this by assuming that partitions have a `partition` thing
under sysfs
* Running find_root_partition on each iteration of the while loop just
in case the real partition showed up so we can bail out of the while
loop entirely. This is janky af, but since we have no idea if we're in
mount_subpartitions because we need to actually search for subpartitions
OR if we're here because of a slow-to-init block device, I'm not sure we
have any other choice.
Signed-off-by: Clayton Craft <craftyguy@postmarketos.org>
Part-of: <https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/7246>