Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,12 @@ linux_mount_boot () {

mountboot="$bootpart $mounted"
}

is_efi_stub() {
_file=$1
if [ -f "$_file" ] && [ "MZ" = "$(head --bytes=2 "$_file")" ]; then
return 0
else
return 1
fi
}
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
os-prober (1.82+deepin3) unstable; urgency=medium

* Fix incorrect system version information retrieved from mounted disks.

-- xinpeng.wang <wangxinpeng@uniontech.com> Fri, 31 Oct 2025 11:42:56 +0800

os-prober (1.82+deepin2) unstable; urgency=medium

* feat: add sw64 support.
Expand Down
1 change: 1 addition & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
0001-feat-linux-boot-probes-detect-old-world-kernels-and-.patch
uniontech-fix-error-version-for-mounted.patch
32 changes: 32 additions & 0 deletions debian/patches/uniontech-fix-error-version-for-mounted.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Index: deepin-os-prober/os-prober
===================================================================
--- deepin-os-prober.orig/os-prober 2025-10-31 11:28:54.138808288 +0800
+++ deepin-os-prober/os-prober 2025-10-31 11:42:38.873689779 +0800
@@ -161,6 +161,27 @@
else
mpoint=$(grep "^$mapped " "$OS_PROBER_TMP/mounted-map" | head -n1 | cut -d " " -f 2)
mpoint="$(unescape_mount "$mpoint")"
+
+ # This resolves the issue of incorrect system version information retrieved from mounted disks.
+ # The problem stems from symbolic links within mounted partitions pointing to the local root
+ # directory, leading to incorrect version readings. Treating these disks as unmounted and
+ # remounting them using `grub-mount` resolves the issue, resulting in the correct version
+ # information.
+ if [ -n "$OS_PROBER_NEWNS" ] && { [ "${mpoint#/mnt/}" != "$mpoint" ] || [ "${mpoint#/media/}" != "$mpoint" ]; }; then
+ debug "using unmounted detection for newns partition: $partition at $mpoint"
+
+ for test in /usr/lib/os-probes/*; do
+ if [ -f "$test" ] && [ -x "$test" ]; then
+ debug "running $test on $partition (newns safe mode)"
+ if "$test" "$partition"; then
+ debug "os detected by $test"
+ break
+ fi
+ fi
+ done
+ continue
+ fi
+
if [ "$mpoint" != "/target/boot" ] && [ "$mpoint" != "/target" ] && [ "$mpoint" != "/" ]; then
type=$(grep "^$mapped " "$OS_PROBER_TMP/mounted-map" | head -n1 | cut -d " " -f 3)
for test in /usr/lib/os-probes/mounted/*; do
11 changes: 10 additions & 1 deletion linux-boot-probes/mounted/common/40grub2
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ mpoint="$3"
type="$4"

found_item=0
is_loong64=0

# The current system from which os-prober is run is a LoongArch system.
# Marked by 00_flag-loong64.
if [ -e "$OS_PROBER_TMP/is_loong64" ]; then
is_loong64=1
fi

entry_result () {
if [ "$ignore_item" = 0 ] && \
[ -n "$kernel" ] && \
[ -e "$mpoint/$kernel" ]; then
[ -e "$mpoint/$kernel" ] && ( \
[ "$is_loong64" = 0 ] || is_efi_stub "$mpoint/$kernel" \
); then
result "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
found_item=1
fi
Expand Down
17 changes: 17 additions & 0 deletions linux-boot-probes/mounted/common/90fallback
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
. /usr/share/os-prober/common.sh
set -e

is_loong64=0

# The current system from which os-prober is run is a LoongArch system.
# Marked by 00_flag-loong64.
if [ -e "$OS_PROBER_TMP/is_loong64" ]; then
is_loong64=1
fi

partition="$1"
bootpart="$2"
mpoint="$3"
Expand All @@ -22,6 +30,15 @@ for kernpat in /vmlinuz /vmlinux /boot/vmlinuz /boot/vmlinux "/boot/vmlinuz*" \
for kernfile in $(eval ls -vr "$mpoint$kernpat" 2>/dev/null); do
kernbasefile=$(echo "$kernfile" | sed "s!^$mpoint!!")
if [ -f "$kernfile" ] && [ ! -L "$kernfile" ]; then
# Detect if the kernel image is non-PE (non-EFI-stub).
# Non-EFI-stub kernels can be assumed to be old-world
# ones, which needs to be booted from an old-world
# GRUB2 bootloader (new-world GRUB2 can't yet boot
# old-world kernels.
if [ "$is_loong64" = "1" ] && ! is_efi_stub "$kernfile"; then
touch "$OS_PROBER_TMP/loong64_have_non_pe_kernel"
continue
fi
initrdname=$(echo "$kernfile" | sed "s/vmlinu[zx]/initrd\*/")
# Yellow Dog Linux appends .img to it.
initrdname1="${initrdname}.img"
Expand Down
12 changes: 12 additions & 0 deletions linux-boot-probes/mounted/loong64/00_flag-loong64
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

. /usr/share/os-prober/common.sh

# Mark the current system as a LoongArch (loong64) one.
#
# We use this marker to run special routines for detecting old-world kernels
# and systems to make it possible for users to boot those systems from new-
# world GRUB2 bootloaders.
touch "$OS_PROBER_TMP/is_loong64"

exit 1
55 changes: 55 additions & 0 deletions linux-boot-probes/mounted/loong64/95old-world-grub2
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh
# Locate old-world GRUB2 boot files for chainloading.

. /usr/share/os-prober/common.sh

set -e

partition="$1"
bootpart="$2"
mpoint="$3"
type="$4"


exitcode=1
# In mounted/common/90fallback, we used is_efi_stub to detect non-PE
# (non-EFI-stub) kernel images to see if the kernel belongs to an old-world
# system.
#
# With LoongArch, the old-world firmware expects to boot from an ELF-formatted
# kernel image (vmlinu{x,z}), whereas new-world firmware expects PE-formatted
# EFI stub kernels (vmlinu{x,z}.efi). However, for our purpose, new-world
# GRUB2 bootloaders are not *yet* able to directly boot old-world kernels, so
# we take advantage of this format difference to detect old-world systems and
# simply chainload their bootloaders.
if [ -e "$OS_PROBER_TMP/loong64_have_non_pe_kernel" ]; then
# Usually, $boot_mount/$grub_prefix/$grub_arch/core.efi contains an
# EFI GRUB boot image equivalent to that installed in the ESP.
#
# We use this image for chainloading from a new-world bootloader.
for kernpat in \
"/grub*/loongarch64-efi/core.efi" \
"/boot/grub*/loongarch64-efi/core.efi"; do
if echo "$kernpat" | grep -q boot/; then
kernbootpart="$bootpart"
else
kernbootpart="$partition"
fi
for kernfile in $(eval ls -vr "$mpoint$kernpat" 2>/dev/null); do
kernbasefile=$(echo "$kernfile" | sed "s!^$mpoint!!")
if [ -f "$kernfile" ] && [ ! -L "$kernfile" ]; then
kernrelfile=$kernbasefile
if [ "$kernbootpart" != "$partition" ]; then
kernrelfile="${kernrelfile#/boot}"
fi
result "$partition:$kernbootpart::$kernbasefile::; chainloader $kernrelfile"
exitcode=0
break;
fi
done
if [ "$exitcode" = "0" ]; then
break;
fi
done
fi
exit "$exitcode"
21 changes: 21 additions & 0 deletions os-prober
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,27 @@ for partition in $(partitions); do
else
mpoint=$(grep "^$mapped " "$OS_PROBER_TMP/mounted-map" | head -n1 | cut -d " " -f 2)
mpoint="$(unescape_mount "$mpoint")"

# This resolves the issue of incorrect system version information retrieved from mounted disks.
# The problem stems from symbolic links within mounted partitions pointing to the local root
# directory, leading to incorrect version readings. Treating these disks as unmounted and
# remounting them using `grub-mount` resolves the issue, resulting in the correct version
# information.
if [ -n "$OS_PROBER_NEWNS" ] && { [ "${mpoint#/mnt/}" != "$mpoint" ] || [ "${mpoint#/media/}" != "$mpoint" ]; }; then
debug "using unmounted detection for newns partition: $partition at $mpoint"

for test in /usr/lib/os-probes/*; do
if [ -f "$test" ] && [ -x "$test" ]; then
debug "running $test on $partition (newns safe mode)"
if "$test" "$partition"; then
debug "os detected by $test"
break
fi
fi
done
continue
fi

if [ "$mpoint" != "/target/boot" ] && [ "$mpoint" != "/target" ] && [ "$mpoint" != "/" ]; then
type=$(grep "^$mapped " "$OS_PROBER_TMP/mounted-map" | head -n1 | cut -d " " -f 3)
for test in /usr/lib/os-probes/mounted/*; do
Expand Down
Loading
Loading