diff --git a/IMG/cpio/ventoy/hook/debian/default-hook.sh b/IMG/cpio/ventoy/hook/debian/default-hook.sh index a8fd7ec6..d7d0eac4 100644 --- a/IMG/cpio/ventoy/hook/debian/default-hook.sh +++ b/IMG/cpio/ventoy/hook/debian/default-hook.sh @@ -17,5 +17,21 @@ # #************************************************************************************ -ventoy_systemd_udevd_work_around -ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k" +if [ -e /init ] && $GREP -q '^mountroot$' /init; then + echo "Here before mountroot ..." >> $VTLOG + + $SED "/^mountroot$/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/disk_mount_hook.sh" -i /init + $SED "/^mountroot$/i\\export LIVEMEDIA=/dev/mapper/ventoy" -i /init + $SED "/^mountroot$/i\\export LIVE_MEDIA=/dev/mapper/ventoy" -i /init + +elif [ -e /init ] && $GREP -q '/start-udev$' /init; then + echo "Here use notify ..." >> $VTLOG + + ventoy_set_inotify_script debian/ventoy-inotifyd-hook.sh + $SED "/start-udev$/i\\mount -n -o mode=0755 -t devtmpfs devtmpfs /dev" -i /init + $SED "/start-udev$/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/ventoy-inotifyd-start.sh" -i /init +else + echo "Here use udev hook ..." >> $VTLOG + ventoy_systemd_udevd_work_around + ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k" +fi diff --git a/IMG/cpio/ventoy/hook/rhel7/ventoy-disk.sh b/IMG/cpio/ventoy/hook/debian/disk_mount_hook.sh similarity index 89% rename from IMG/cpio/ventoy/hook/rhel7/ventoy-disk.sh rename to IMG/cpio/ventoy/hook/debian/disk_mount_hook.sh index ab1d4975..28943562 100644 --- a/IMG/cpio/ventoy/hook/rhel7/ventoy-disk.sh +++ b/IMG/cpio/ventoy/hook/debian/disk_mount_hook.sh @@ -19,10 +19,6 @@ . /ventoy/hook/ventoy-hook-lib.sh -if is_ventoy_hook_finished; then - exit 0 -fi - vtlog "####### $0 $* ########" VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH @@ -36,9 +32,4 @@ if [ "$vtdiskname" = "unknown" ]; then exit 0 fi -ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" - -PATH=$VTPATH_OLD - -set_ventoy_hook_finish - +$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "${vtdiskname#/dev/}2" diff --git a/IMG/cpio/ventoy/hook/debian/udev_disk_hook.sh b/IMG/cpio/ventoy/hook/debian/udev_disk_hook.sh index 7edcbe73..6bc7077d 100644 --- a/IMG/cpio/ventoy/hook/debian/udev_disk_hook.sh +++ b/IMG/cpio/ventoy/hook/debian/udev_disk_hook.sh @@ -86,6 +86,10 @@ if [ -z "$dmsetup_path" ]; then ventoy_os_install_dmsetup "/dev/${1:0:-1}" fi +if ! $GREP -q 'device-mapper' /proc/devices; then + ventoy_os_install_dmsetup "/dev/${1:0:-1}" +fi + ventoy_udev_disk_common_hook $* # @@ -103,7 +107,14 @@ else else vtlog "No boot param, need to mount" $BUSYBOX_PATH/mkdir /cdrom - $BUSYBOX_PATH/mount -t iso9660 $VTOY_DM_PATH /cdrom + + if [ -b $VTOY_DM_PATH ]; then + vtlog "mount $VTOY_DM_PATH ..." + $BUSYBOX_PATH/mount -t iso9660 $VTOY_DM_PATH /cdrom + else + vtlog "mount /dev/$1 ..." + $BUSYBOX_PATH/mount -t iso9660 /dev/$1 /cdrom + fi fi fi diff --git a/IMG/cpio/ventoy/hook/debian/ventoy-hook.sh b/IMG/cpio/ventoy/hook/debian/ventoy-hook.sh index 05b9487b..2bc7a860 100644 --- a/IMG/cpio/ventoy/hook/debian/ventoy-hook.sh +++ b/IMG/cpio/ventoy/hook/debian/ventoy-hook.sh @@ -52,14 +52,6 @@ ventoy_get_debian_distro() { echo 'pve'; return fi - if $GREP -q '[Dd]eepin' /proc/version; then - echo 'deepin'; return - fi - - if $GREP -q '[Uu][Oo][Ss] ' /proc/version; then - echo 'deepin'; return - fi - if [ -d /porteus ]; then echo 'porteus'; return fi diff --git a/IMG/cpio/ventoy/hook/debian/deepin-disk.sh b/IMG/cpio/ventoy/hook/debian/ventoy-inotifyd-hook.sh similarity index 73% rename from IMG/cpio/ventoy/hook/debian/deepin-disk.sh rename to IMG/cpio/ventoy/hook/debian/ventoy-inotifyd-hook.sh index 926e1a50..53916c6a 100644 --- a/IMG/cpio/ventoy/hook/debian/deepin-disk.sh +++ b/IMG/cpio/ventoy/hook/debian/ventoy-inotifyd-hook.sh @@ -19,29 +19,17 @@ . /ventoy/hook/ventoy-hook-lib.sh -vtlog "####### $0 $* ########" +if is_ventoy_hook_finished; then + exit 0 +fi + +vtlog "##### INOTIFYD: $2/$3 is created ..." VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH -vtmountpoint=$1 - -if is_ventoy_hook_finished; then - PATH=$VTPATH_OLD - exit 0 +if is_inotify_ventoy_part $3; then + vtlog "find ventoy partition $3 ..." + $BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/udev_disk_hook.sh "$3" fi -wait_for_usb_disk_ready - -vtdiskname=$(get_ventoy_disk_name) -if [ "$vtdiskname" = "unknown" ]; then - vtlog "ventoy disk not found" - PATH=$VTPATH_OLD - exit 0 -fi - -ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" - -$BUSYBOX_PATH/mount -t iso9660 $VTOY_DM_PATH $vtmountpoint - -# OK finish -set_ventoy_hook_finish +PATH=$VTPATH_OLD diff --git a/IMG/cpio/ventoy/hook/default/ventoy-inotifyd-start.sh b/IMG/cpio/ventoy/hook/default/ventoy-inotifyd-start.sh new file mode 100644 index 00000000..7981b1e6 --- /dev/null +++ b/IMG/cpio/ventoy/hook/default/ventoy-inotifyd-start.sh @@ -0,0 +1,25 @@ +#!/ventoy/busybox/sh +#************************************************************************************ +# Copyright (c) 2020, longpanda +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +#************************************************************************************ + +. /ventoy/hook/ventoy-hook-lib.sh + +vtHook=$($CAT $VTOY_PATH/inotifyd-hook-script.txt) + +vtlog "... start inotifyd listen $vtHook ..." +$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $vtHook /dev:n 2>&- & diff --git a/IMG/cpio/ventoy/hook/manjaro/ventoy-hook.sh b/IMG/cpio/ventoy/hook/manjaro/ventoy-hook.sh index b902f984..ebd828ec 100644 --- a/IMG/cpio/ventoy/hook/manjaro/ventoy-hook.sh +++ b/IMG/cpio/ventoy/hook/manjaro/ventoy-hook.sh @@ -28,6 +28,13 @@ else $CAT $VTOY_PATH/hook/default/13-dm-disk.rules > "$DISTRO_UDEV_DIR/13-dm-disk.rules" fi -ventoy_systemd_udevd_work_around -ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k" +if $GREP -q '^mount_setup$' init; then + echo "Here use notify ..." >> $VTLOG + + ventoy_set_inotify_script manjaro/ventoy-inotifyd-hook.sh + $SED "/^mount_setup$/a\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/ventoy-inotifyd-start.sh" -i /init +else + ventoy_systemd_udevd_work_around + ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k" +fi diff --git a/IMG/cpio/ventoy/hook/manjaro/ventoy-inotifyd-hook.sh b/IMG/cpio/ventoy/hook/manjaro/ventoy-inotifyd-hook.sh new file mode 100644 index 00000000..60cff43a --- /dev/null +++ b/IMG/cpio/ventoy/hook/manjaro/ventoy-inotifyd-hook.sh @@ -0,0 +1,46 @@ +#!/ventoy/busybox/sh +#************************************************************************************ +# Copyright (c) 2020, longpanda +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +#************************************************************************************ + +. /ventoy/hook/ventoy-hook-lib.sh + +if is_ventoy_hook_finished; then + exit 0 +fi + +vtlog "##### INOTIFYD: $2/$3 is created ..." + +VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH + +if is_inotify_ventoy_part $3; then + vtlog "find ventoy partition $3 ..." + $BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh "$3" + + blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/') + vtDM=$(ventoy_find_dm_id ${blkdev_num}) + vtLABEL=$($BUSYBOX_PATH/blkid /dev/$vtDM | $AWK '{print $2}' | $SED 's/.*"\(.*\)".*/\1/') + + vtlog "blkdev_num=$blkdev_num vtDM=$vtDM label $vtLABEL ..." + + if ! [ -d /dev/disk/by-label ]; then + mkdir -p /dev/disk/by-label + fi + $BUSYBOX_PATH/cp -a /dev/$vtDM /dev/disk/by-label/$vtLABEL +fi + +PATH=$VTPATH_OLD diff --git a/IMG/cpio/ventoy/hook/rhel7/ventoy-hook.sh b/IMG/cpio/ventoy/hook/rhel7/ventoy-hook.sh index ca3503df..aa1f7fc6 100644 --- a/IMG/cpio/ventoy/hook/rhel7/ventoy-hook.sh +++ b/IMG/cpio/ventoy/hook/rhel7/ventoy-hook.sh @@ -19,10 +19,13 @@ . $VTOY_PATH/hook/ventoy-os-lib.sh -ventoy_systemd_udevd_work_around -ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace" +#ventoy_systemd_udevd_work_around +#ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace" -#$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-disk.sh /lib/dracut/hooks/initqueue/01-ventoy-disk.sh +$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE inst.stage2=hd:/dev/dm-0#" -i /lib/dracut-lib.sh +ventoy_set_inotify_script rhel7/ventoy-inotifyd-hook.sh + +$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/default/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/01-ventoy-inotifyd-start.sh # suppress write protected mount warning if [ -e /usr/sbin/anaconda-diskroot ]; then diff --git a/IMG/cpio/ventoy/hook/debian/deepin-hook.sh b/IMG/cpio/ventoy/hook/rhel7/ventoy-inotifyd-hook.sh similarity index 55% rename from IMG/cpio/ventoy/hook/debian/deepin-hook.sh rename to IMG/cpio/ventoy/hook/rhel7/ventoy-inotifyd-hook.sh index deec6405..bf81445c 100644 --- a/IMG/cpio/ventoy/hook/debian/deepin-hook.sh +++ b/IMG/cpio/ventoy/hook/rhel7/ventoy-inotifyd-hook.sh @@ -17,31 +17,31 @@ # #************************************************************************************ -drop_initramfs_workaround() { - mainfilelist=$($FIND / -name 9990-main.sh) +. /ventoy/hook/ventoy-hook-lib.sh + +if is_ventoy_hook_finished; then + exit 0 +fi + +vtlog "##### INOTIFYD: $2/$3 is created ..." + +VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH + +if is_inotify_ventoy_part $3; then + vtlog "find ventoy partition ..." + $BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 noreplace - echo "mainfilelist=$mainfilelist" >> $VTLOG - - if [ -z "$mainfilelist" ]; then - return + blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/') + vtDM=$(ventoy_find_dm_id ${blkdev_num}) + + if [ "$vtDM" = "dm-0" ]; then + vtlog "This is dm-0, OK ..." + else + vtlog "####### This is $vtDM ####### this is abnormal ..." + ventoy_swap_device /dev/dm-0 /dev/$vtDM fi - - for vtfile in $mainfilelist; do - vtcnt=$($GREP -c 'panic.*Unable to find a medium' $vtfile) - if [ $vtcnt -ne 1 ]; then - return - fi - done - echo "direct_hook insert ..." >> $VTLOG - - for vtfile in $mainfilelist; do - $SED "s#panic.*Unable to find a medium.*#$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/deepin-disk.sh \$mountpoint; livefs_root=\$mountpoint#" -i $vtfile - done -} - -ventoy_systemd_udevd_work_around -ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k" - -drop_initramfs_workaround + set_ventoy_hook_finish +fi +PATH=$VTPATH_OLD diff --git a/IMG/cpio/ventoy/hook/ventoy-hook-lib.sh b/IMG/cpio/ventoy/hook/ventoy-hook-lib.sh index 62e413b9..f70d5574 100644 --- a/IMG/cpio/ventoy/hook/ventoy-hook-lib.sh +++ b/IMG/cpio/ventoy/hook/ventoy-hook-lib.sh @@ -421,4 +421,37 @@ ventoy_udev_disk_common_hook() { fi } +is_inotify_ventoy_part() { + if echo $1 | grep -q "2$"; then + if ! [ -e /sys/block/$1 ]; then + if [ -e /sys/class/block/$1 ]; then + if [ -e /dev/${1:0:-1} ]; then + $VTOY_PATH/tool/vtoydump -f $VTOY_PATH/ventoy_os_param -c ${1:0:-1} + return + fi + fi + fi + fi + + [ "1" = "0" ] +} + +ventoy_find_dm_id() { + for vt in $($BUSYBOX_PATH/ls /sys/block/); do + if [ "${vt:0:3}" = "dm-" ]; then + vtMajorMinor=$($CAT /sys/block/$vt/dev) + if [ "$vtMajorMinor" = "$1" ]; then + echo ${vt} + return + fi + fi + done + echo 'xx' +} + +ventoy_swap_device() { + mv $1 $VTOY_PATH/swap_tmp_dev + mv $2 $1 + mv $VTOY_PATH/swap_tmp_dev $2 +} diff --git a/IMG/cpio/ventoy/hook/ventoy-os-lib.sh b/IMG/cpio/ventoy/hook/ventoy-os-lib.sh index b5ea3bf7..05533347 100644 --- a/IMG/cpio/ventoy/hook/ventoy-os-lib.sh +++ b/IMG/cpio/ventoy/hook/ventoy-os-lib.sh @@ -101,3 +101,7 @@ ventoy_print_yum_repo() { echo "gpgcheck=0" echo "priority=0" } + +ventoy_set_inotify_script() { + echo $VTOY_PATH/hook/$1 > $VTOY_PATH/inotifyd-hook-script.txt +} diff --git a/INSTALL/Ventoy2Disk.exe b/INSTALL/Ventoy2Disk.exe index 693a9b5f..228eb990 100644 Binary files a/INSTALL/Ventoy2Disk.exe and b/INSTALL/Ventoy2Disk.exe differ diff --git a/INSTALL/grub/grub.cfg b/INSTALL/grub/grub.cfg index d9a59fab..3bf13d13 100644 --- a/INSTALL/grub/grub.cfg +++ b/INSTALL/grub/grub.cfg @@ -395,7 +395,7 @@ function legacy_iso_memdisk { ############################################################# ############################################################# -set VENTOY_VERSION="1.0.07" +set VENTOY_VERSION="1.0.08b1" #disable timeout unset timeout diff --git a/INSTALL/ventoy/ventoy.cpio b/INSTALL/ventoy/ventoy.cpio index da7f43ef..30c34e76 100644 Binary files a/INSTALL/ventoy/ventoy.cpio and b/INSTALL/ventoy/ventoy.cpio differ diff --git a/Ventoy2Disk/Ventoy2Disk/Ventoy2Disk.rc b/Ventoy2Disk/Ventoy2Disk/Ventoy2Disk.rc index d38afb0f..990dcfe3 100644 Binary files a/Ventoy2Disk/Ventoy2Disk/Ventoy2Disk.rc and b/Ventoy2Disk/Ventoy2Disk/Ventoy2Disk.rc differ diff --git a/VtoyTool/vtoydump.c b/VtoyTool/vtoydump.c index ef11ce80..fd557cf9 100644 --- a/VtoyTool/vtoydump.c +++ b/VtoyTool/vtoydump.c @@ -448,7 +448,7 @@ static int vtoy_check_device(ventoy_os_param *param, const char *device) debug("param->vtoy_disk_size=%llu size=%llu\n", (unsigned long long)param->vtoy_disk_size, (unsigned long long)size); - if (param->vtoy_disk_size == size && + if ((param->vtoy_disk_size == size || param->vtoy_disk_size == size + 512) && memcmp(vtguid, param->vtoy_disk_guid, 16) == 0) { debug("<%s> is right ventoy disk\n", device);