From 96f3210bd0b3e26ca2731fd576d0be8e94b114ac Mon Sep 17 00:00:00 2001 From: longpanda Date: Thu, 8 Oct 2026 18:45:50 +0800 Subject: [PATCH] Make the ISO partition mountable for CloneZilla. (#3274) --- .../debian/ventoy-clonezilla-cheat.service | 11 +++ .../ventoy/hook/debian/ventoy-uauto-exec.sh | 26 ++++-- .../ventoy/hook/debian/ventoy-uauto-hook.sh | 16 +++- .../hook/default/ventoy-udev-trigger.rc | 9 +++ IMG/cpio/ventoy/hook/ventoy-hook-lib.sh | 81 ++++++++++++------- 5 files changed, 102 insertions(+), 41 deletions(-) create mode 100644 IMG/cpio/ventoy/hook/debian/ventoy-clonezilla-cheat.service create mode 100644 IMG/cpio/ventoy/hook/default/ventoy-udev-trigger.rc diff --git a/IMG/cpio/ventoy/hook/debian/ventoy-clonezilla-cheat.service b/IMG/cpio/ventoy/hook/debian/ventoy-clonezilla-cheat.service new file mode 100644 index 00000000..f1e89874 --- /dev/null +++ b/IMG/cpio/ventoy/hook/debian/ventoy-clonezilla-cheat.service @@ -0,0 +1,11 @@ +[Unit] +Description=Ventoy CloneZilla Device Cheat +After=systemd-udevd.service + +[Service] +Type=oneshot +ExecStart=mv /dev/VTISOPART /dev/bk_VTISOPART +ExecStart=cp -a /dev/DMXXX /dev/VTISOPART + +[Install] +WantedBy=sysinit.target diff --git a/IMG/cpio/ventoy/hook/debian/ventoy-uauto-exec.sh b/IMG/cpio/ventoy/hook/debian/ventoy-uauto-exec.sh index 2f016b3d..4e6cde13 100644 --- a/IMG/cpio/ventoy/hook/debian/ventoy-uauto-exec.sh +++ b/IMG/cpio/ventoy/hook/debian/ventoy-uauto-exec.sh @@ -20,17 +20,29 @@ subiquity_curtin_workaround() { } -if [ -d /root/etc/systemd/system -a -d /root/etc/udev/rules.d ]; then - vtlog "systemd udev check OK" - +vroot=$(ventoy_new_root_dir) +if [ -z "$vroot" ]; then + vtlog "new sysroot not found" +else ventoy_copy_udev_auto_rules - - if ls /root/etc/udev/rules.d | grep -q 'snap.*desktop'; then + if ls $vroot/etc/udev/rules.d | grep -q 'snap.*desktop'; then subiquity_curtin_workaround else vtlog "no snap desktop detected" fi -else - vtlog "systemd or udev not exist" fi +if [ -d $vroot/usr/share/clonezilla ]; then + vtlog "add cheat service for clonezilla" + + vtDM=$($VTOY_PATH/tool/dmsetup info VentoyPart | grep Major | sed "s/.*[^0-9]\([0-9][0-9]*\)$/\1/") + vtRAWDISKNAME=$(head -n1 $VTOY_PATH/ventoy_raw_table | awk '{print $4}') + + cp -a /ventoy/hook/debian/ventoy-clonezilla-cheat.service /ventoy/udevtmp.service + sed "s/DMXXX/dm-${vtDM}/g" -i /ventoy/udevtmp.service + sed "s/VTISOPART/${vtRAWDISKNAME#/dev/}/g" -i /ventoy/udevtmp.service + + ventoy_copy_file /ventoy/udevtmp.service $vroot/etc/systemd/system/ventoy-clonezilla-cheat.service 0644 + echo 'enable ventoy-clonezilla-cheat.service' > $vroot/etc/systemd/system-preset/90-ventoy-clonezilla.preset + ln -sf /etc/systemd/system/ventoy-clonezilla-cheat.service $vroot/etc/systemd/system/sysinit.target.wants/ventoy-clonezilla-cheat.service +fi diff --git a/IMG/cpio/ventoy/hook/debian/ventoy-uauto-hook.sh b/IMG/cpio/ventoy/hook/debian/ventoy-uauto-hook.sh index 8a275836..9e233f0a 100644 --- a/IMG/cpio/ventoy/hook/debian/ventoy-uauto-hook.sh +++ b/IMG/cpio/ventoy/hook/debian/ventoy-uauto-hook.sh @@ -18,10 +18,18 @@ vtoy_udev_auto_hook() { fi - if [ -e /init ] && $GREP -q '^mountroot$' /init; then - vtlog "mountroot distro" - sed "/^mountroot$/a\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/ventoy-uauto-exec.sh" -i /init - return + if [ -e /init ]; then + if $GREP -q '^mountroot$' /init; then + vtlog "mountroot distro" + sed "/^mountroot$/a\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/ventoy-uauto-exec.sh" -i /init + return + fi + + if $GREP -q '^ *exec.*switch_root' /init; then + vtlog "switch_root distro" + sed "/^ *exec.*switch_root/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/ventoy-uauto-exec.sh" -i /init + return + fi fi } diff --git a/IMG/cpio/ventoy/hook/default/ventoy-udev-trigger.rc b/IMG/cpio/ventoy/hook/default/ventoy-udev-trigger.rc new file mode 100644 index 00000000..c2485a7d --- /dev/null +++ b/IMG/cpio/ventoy/hook/default/ventoy-udev-trigger.rc @@ -0,0 +1,9 @@ +#!/bin/sh + +for i in 0 1 2 3 4 5 6 7 8 9; do + [ -b /dev/DMXXX ] && break + sleep 1 +done + +udevadm trigger --subsystem-match=block --sysname-match=DMXXX +udevadm settle diff --git a/IMG/cpio/ventoy/hook/ventoy-hook-lib.sh b/IMG/cpio/ventoy/hook/ventoy-hook-lib.sh index 056fc29f..16439a2f 100644 --- a/IMG/cpio/ventoy/hook/ventoy-hook-lib.sh +++ b/IMG/cpio/ventoy/hook/ventoy-hook-lib.sh @@ -1017,6 +1017,16 @@ ventoy_init_udev_auto_rules() { ventoy_copy_file /ventoy/hook/default/11-ventoy-dm.rules /etc/udev/rules.d/11-ventoy-dm.rules 0644 } +ventoy_new_root_dir() { + for vroot in sysroot newroot new_root root live/aufs pup_new; do + if [ -d $vroot/etc/udev/rules.d ]; then + echo "$vroot" + return + fi + done + echo '' +} + ventoy_copy_udev_auto_rules() { if ! [ -e $VTOY_PATH/ventoy_raw_dm_done ]; then vtlog "ventoy_raw_dm_done not exist, no need for udev auto rule" @@ -1024,38 +1034,49 @@ ventoy_copy_udev_auto_rules() { fi vtlog "==== Copy udev auto rules ====" - for vroot in sysroot newroot new_root root; do - if [ -d $vroot/etc/udev/rules.d ]; then - cp -a /ventoy/hook/default/90-ventoy-auto.rules /ventoy/udevtmp.rules + vroot=$(ventoy_new_root_dir) + if [ -z "$vroot" ]; then + vtlog "no new root found" + return + else + vtlog "new root is $vroot" + fi + + + cp -a /ventoy/hook/default/90-ventoy-auto.rules /ventoy/udevtmp.rules + vtDM=$($VTOY_PATH/tool/dmsetup info VentoyPart | $GREP Major | $SED "s/.*[^0-9]\([0-9][0-9]*\)$/\1/") + $SED "s/DMXXX/dm-${vtDM}/g" -i /ventoy/udevtmp.rules + + vtRAWDISKNAME=$($HEAD -n1 $VTOY_PATH/ventoy_raw_table | $AWK '{print $4}') + $SED "s/yyy/${vtRAWDISKNAME#/dev/}/g" -i /ventoy/udevtmp.rules + + vtlog "VentoyPart is /dev/dm-${vtDM} map to $vtRAWDISKNAME NewRoot is $vroot" + + ventoy_copy_file /ventoy/udevtmp.rules $vroot/etc/udev/rules.d/90-ventoy-auto.rules 0644 + ventoy_copy_file /ventoy/udevtmp.rules $vroot/etc/udev/rules.d/11-ventoy-auto.rules 0644 + + if $GREP -q 'init=.*sysvinit' /proc/cmdline; then + vtlog "copy sysvinit udev trigger script" + cp -a /ventoy/hook/default/ventoy-udev-trigger.rc /ventoy/udevtmp.rc + $SED "s/DMXXX/dm-${vtDM}/g" -i /ventoy/udevtmp.rc + + mkdir -p $vroot/etc/boot.d + ventoy_copy_file /ventoy/udevtmp.rc $vroot/etc/boot.d/S01-ventoy-udev-trigger 0755 + elif [ -d $vroot/etc/systemd/system ]; then + vtlog "copy systemd udev trigger service" - vtDM=$($VTOY_PATH/tool/dmsetup info VentoyPart | $GREP Major | $SED "s/.*[^0-9]\([0-9][0-9]*\)$/\1/") - $SED "s/DMXXX/dm-${vtDM}/g" -i /ventoy/udevtmp.rules + mkdir -p $vroot/etc/systemd/system/sysinit.target.wants + cp -a /ventoy/hook/default/ventoy-udev-trigger.service /ventoy/udevtmp.service + $SED "s/DMXXX/dm-${vtDM}/g" -i /ventoy/udevtmp.service + ventoy_copy_file /ventoy/udevtmp.service $vroot/etc/systemd/system/ventoy-udev-trigger.service 0644 + + mkdir -p $vroot/etc/systemd/system-preset + echo 'enable ventoy-udev-trigger.service' > $vroot/etc/systemd/system-preset/80-ventoy-udev.preset - vtRAWDISKNAME=$($HEAD -n1 $VTOY_PATH/ventoy_raw_table | $AWK '{print $4}') - $SED "s/yyy/${vtRAWDISKNAME#/dev/}/g" -i /ventoy/udevtmp.rules - - vtlog "VentoyPart is /dev/dm-${vtDM} map to $vtRAWDISKNAME" - - ventoy_copy_file /ventoy/udevtmp.rules $vroot/etc/udev/rules.d/90-ventoy-auto.rules 0644 - ventoy_copy_file /ventoy/udevtmp.rules $vroot/etc/udev/rules.d/11-ventoy-auto.rules 0644 - - if [ -d $vroot/etc/systemd/system/sysinit.target.wants ]; then - vtlog "copy udev trigger service" - cp -a /ventoy/hook/default/ventoy-udev-trigger.service /ventoy/udevtmp.service - $SED "s/DMXXX/dm-${vtDM}/g" -i /ventoy/udevtmp.service - ventoy_copy_file /ventoy/udevtmp.service $vroot/etc/systemd/system/ventoy-udev-trigger.service 0644 - - mkdir -p $vroot/etc/systemd/system-preset - echo 'enable ventoy-udev-trigger.service' > $vroot/etc/systemd/system-preset/80-ventoy-udev.preset - - $BUSYBOX_PATH/ln -sf /etc/systemd/system/ventoy-udev-trigger.service $vroot/etc/systemd/system/sysinit.target.wants/ventoy-udev-trigger.service - else - vtlog "sysinit wants dir not exist" - fi - - break - fi - done + $BUSYBOX_PATH/ln -sf /etc/systemd/system/ventoy-udev-trigger.service $vroot/etc/systemd/system/sysinit.target.wants/ventoy-udev-trigger.service + else + vtlog "sysinit wants dir not exist" + fi } ventoy_dracut_pivot_udev_rule() {