diff options
| author | Clemens Hopfer | 2025-05-30 12:03:40 +0000 |
|---|---|---|
| committer | Robert Marko | 2026-04-03 18:49:12 +0000 |
| commit | ca11c6b7e17b5a8cdf239c0dc8da7bd56d0f84f9 (patch) | |
| tree | dca17a6a81c6ec6b75dafc499ed6a5b05c54a56d | |
| parent | 57fe3e077e3a89af839a3e5ca1cbce754eb1e3e7 (diff) | |
| download | openwrt-ca11c6b7e17b5a8cdf239c0dc8da7bd56d0f84f9.tar.gz | |
base-files: MAJOR/MINOR not sequential, use DISKSEQ instead
Export the unique, monotonic DISKSEQ sequence drive number instead of its
major/minor numbers to identify the boot disk and directly match the partition
in export_partdevice with PARTN.
The MINOR blockdevice numbers are not guaranteed sequential across disks, it
can happen that disks enumerate before their partitions are probed, resulting
in interleaved MINOR numbers breaking the partition offset calculation:
major minor #blocks name
259 0 250059096 nvme0n1
259 2 8192 nvme0n1p1
259 3 491520 nvme0n1p2
259 4 239 nvme0n1p128
259 1 250059096 nvme1n1
259 5 250057728 nvme1n1p1
Signed-off-by: Clemens Hopfer <openwrt@wireloss.net>
Link: https://github.com/openwrt/openwrt/pull/18962
Signed-off-by: Robert Marko <robimarko@gmail.com>
(cherry picked from commit 63d0b5c24388e2603ab1cd482d6e469029cde421)
| -rw-r--r-- | package/base-files/files/lib/upgrade/common.sh | 17 | ||||
| -rw-r--r-- | target/linux/stm32/base-files/lib/upgrade/platform.sh | 3 |
2 files changed, 10 insertions, 10 deletions
diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh index af1182cb16..ba2e364775 100644 --- a/package/base-files/files/lib/upgrade/common.sh +++ b/package/base-files/files/lib/upgrade/common.sh @@ -167,7 +167,7 @@ part_magic_fat() { export_bootdevice() { local cmdline uuid blockdev uevent line class - local MAJOR MINOR DEVNAME DEVTYPE + local MAJOR MINOR DEVNAME DEVTYPE DISKSEQ PARTN local rootpart="$(cmdline_get_var root)" case "$rootpart" in @@ -216,8 +216,7 @@ export_bootdevice() { while read line; do export -n "$line" done < "$uevent" - export BOOTDEV_MAJOR=$MAJOR - export BOOTDEV_MINOR=$MINOR + export BOOTDEV_DISKSEQ=$DISKSEQ return 0 fi @@ -225,16 +224,18 @@ export_bootdevice() { } export_partdevice() { - local var="$1" offset="$2" - local uevent line MAJOR MINOR DEVNAME DEVTYPE + local var="$1" partn="$2" + local uevent line MAJOR MINOR DEVNAME DEVTYPE DISKSEQ PARTN for uevent in /sys/class/block/*/uevent; do while read line; do export -n "$line" done < "$uevent" - if [ "$BOOTDEV_MAJOR" = "$MAJOR" -a $(($BOOTDEV_MINOR + $offset)) = "$MINOR" -a -b "/dev/$DEVNAME" ]; then - export "$var=$DEVNAME" - return 0 + if [ "$BOOTDEV_DISKSEQ" = "$DISKSEQ" -a -b "/dev/$DEVNAME" ]; then + if [ "$PARTN" = "$partn" -a "$DEVTYPE" = "partition" ] || [ "$partn" = "0" -a "$DEVTYPE" = "disk" ]; then + export "$var=$DEVNAME" + return 0 + fi fi done diff --git a/target/linux/stm32/base-files/lib/upgrade/platform.sh b/target/linux/stm32/base-files/lib/upgrade/platform.sh index 4cd88ab6bd..92e5bb5d2b 100644 --- a/target/linux/stm32/base-files/lib/upgrade/platform.sh +++ b/target/linux/stm32/base-files/lib/upgrade/platform.sh @@ -31,8 +31,7 @@ export_bootdevice() { while read line; do export -n "$line" done < "$uevent" - export BOOTDEV_MAJOR=$MAJOR - export BOOTDEV_MINOR=$MINOR + export BOOTDEV_DISKSEQ=$DISKSEQ return 0 fi |