+function vhd_common_menuentry {
+
+ if [ "$VTOY_VHD_NO_WARNING" != "1" ]; then
+ if [ "$vtoy_iso_fs" != "ntfs" ]; then
+ echo -e "!!! WARNING !!!\n"
+ echo -e "\nPartition1 ($vtoy_iso_fs) is NOT ntfs, the VHD(x) file may not boot normally \n"
+ echo -e "\nVHD(x) 文件所在分区不是 ntfs 格式, 可能无法正常启动 \n\n"
+ echo -n "press ENTER to continue boot (请按 回车 键继续) ..."
+ read vtInputKey
+ fi
+ fi
+
+ vt_chosen_img_path vt_chosen_path vt_chosen_size
+
+ if vt_check_password "${vt_chosen_path}"; then
+ return
+ fi
+
+ if ventoy_vcfg_proc "${vt_chosen_path}"; then
+ return
+ fi
+
+ vt_patch_vhdboot "$vt_chosen_path"
+
+ ventoy_debug_pause
+
+ if [ -n "$vtoy_vhd_buf_addr" ]; then
+ if [ "$grub_platform" = "pc" ]; then
+ linux16 $vtoy_path/memdisk iso raw
+ initrd16 mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
+ boot
+ else
+ ventoy_cli_console
+ chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi memdisk env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_vhd_buf_addr}:size:${vtoy_vhd_buf_size}
+ boot
+ ventoy_gui_console
+ fi
+ else
+ echo "Please put the right ventoy_vhdboot.img file to the 1st partition"
+ ventoy_pause
+ fi
+}
+
+function vhd_unsupport_menuentry {
+ common_unsupport_menuentry
+}
+
+function vtoyboot_common_func {
+ set AltBootPart=0
+ set vtoysupport=0
+
+ vt_get_vtoy_type "${1}" vtoytype parttype AltBootPart
+
+ if vt_str_begin $vtoytype vhd; then
+ set vtoysupport=1
+ elif [ "$vtoytype" = "raw" ]; then
+ set vtoysupport=1
+ elif [ "$vtoytype" = "vdi" ]; then
+ set vtoysupport=1
+ fi
+
+ if [ $vtoysupport -eq 1 ]; then
+ if [ "$grub_platform" = "pc" ]; then
+ if [ "$parttype" = "gpt" -a $AltBootPart -eq 0 ]; then
+ echo "The OS in the vdisk was created in UEFI mode, but current is Legacy BIOS mode."
+ echo "虚拟磁盘内的系统是在UEFI模式下创建的,而当前系统是Legacy BIOS模式,可能无法正常启动。"
+ ventoy_pause
+ fi
+ else
+ if [ "$parttype" = "mbr" -a $AltBootPart -eq 0 ]; then
+ echo "The OS in the vdisk was created in Legacy BIOS mode, but current is UEFI mode."
+ echo "虚拟磁盘内的系统是在Legacy BIOS模式下创建的,而当前系统是UEFI模式,可能无法正常启动。"
+ ventoy_pause
+ fi
+ fi
+
+ vt_img_sector "${1}"
+ vt_raw_chain_data "${1}"
+
+ ventoy_debug_pause
+
+ if [ -n "$vtoy_chain_mem_addr" ]; then
+ if [ "$grub_platform" = "pc" ]; then
+ vt_acpi_param ${vtoy_chain_mem_addr} 512
+ linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} bios80 sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
+ boot
+ else
+ if vt_check_secureboot_var; then
+ vt_acpi_param ${vtoy_chain_mem_addr} 512
+ fi
+ ventoy_cli_console
+ chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi sector512 env_param=${ventoy_env_param} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
+ boot
+ ventoy_gui_console
+ fi
+ else
+ echo "chain empty failed!"
+ ventoy_pause
+ fi
+ else
+ echo "Unsupported vtoy type $vtoytype"
+ ventoy_pause
+ fi
+}
+
+function vtoy_common_menuentry {
+ vt_chosen_img_path vt_chosen_path vt_chosen_size
+
+ if vt_check_password "${vt_chosen_path}"; then
+ return
+ fi
+
+ if ventoy_vcfg_proc "${vt_chosen_path}"; then
+ return
+ fi
+
+ vtoyboot_common_func "${vtoy_iso_part}${vt_chosen_path}"
+}
+
+function vtoy_unsupport_menuentry {
+ common_unsupport_menuentry
+}
+
+#
+#============================================================#
+# IMG file boot process #
+#============================================================#
+#
+
+
+function ventoy_img_easyos {
+ vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
+ vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
+
+ loopback easysfs (vtimghd,1)/easy.sfs
+ vt_get_lib_module_ver (easysfs) /lib/modules/ vt_module_ver
+
+ if [ -n "$vt_module_ver" ]; then
+ for mod in "kernel/drivers/md/dm-mod.ko" "kernel/drivers/dax/dax.ko"; do
+ vt_img_extra_initrd_append (easysfs)/lib/modules/$vt_module_ver/$mod
+ done
+ fi
+
+ ventoy_debug_pause
+
+ #boot image file
+ vt_set_boot_opt rdinit=/vtoy/vtoy
+ vt_img_hook_root
+
+ syslinux_configfile (vtimghd,1)/syslinux.cfg
+
+ vt_img_unhook_root
+ vt_unset_boot_opt
+ loopback -d easysfs
+}
+
+function ventoy_img_volumio {
+ vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
+ vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
+
+ ventoy_debug_pause
+
+ #boot image file
+ vt_set_boot_opt rdinit=/vtoy/vtoy imgpart=/dev/ventoy2 bootpart=/dev/ventoy1
+ vt_img_hook_root
+
+ syslinux_configfile (vtimghd,1)/syslinux.cfg
+
+ vt_img_unhook_root
+ vt_unset_boot_opt
+}
+
+function ventoy_img_openelec {
+ elec_ver=$1
+
+ vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
+ vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
+
+ loopback vtloopex $vtoy_efi_part/ventoy/vtloopex.cpio
+ vt_img_extra_initrd_append (vtloopex)/$elec_ver/vtloopex.tar.xz
+
+ ventoy_debug_pause
+
+ #boot image file
+ vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=$elec_ver
+ vt_img_hook_root
+
+ set root=(vtimghd,1)
+ syslinux_configfile (vtimghd,1)/syslinux.cfg
+
+ vt_img_unhook_root
+ vt_unset_boot_opt
+ loopback -d vtloopex
+}
+
+
+function ventoy_img_freedombox {
+ vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
+ vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
+
+ vt_get_lib_module_ver (vtimghd,1) /lib/modules/ vt_module_ver
+ if [ -n "$vt_module_ver" ]; then
+ vt_img_extra_initrd_append (vtimghd,1)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko
+ fi
+
+ ventoy_debug_pause
+
+ #boot image file
+ vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=freedombox
+ vt_img_hook_root
+
+ configfile (vtimghd,1)/boot/grub/grub.cfg
+
+ vt_img_unhook_root
+ vt_unset_boot_opt
+}
+
+function ventoy_img_paldo {
+ vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
+ vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
+
+ ventoy_debug_pause
+
+ #boot image file
+ vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=paldo
+ vt_img_hook_root
+
+ vt_fs_enum_1st_file (vtimghd,1) /loader/entries/ vt_paldo_entry_conf
+ vt_file_basename $vt_paldo_entry_conf vtPaldoVer
+
+ echo loading file...
+ linux (vtimghd,1)/linux-${vtPaldoVer} root=/dev/ventoy1 rootfstype=vfat
+ initrd (vtimghd,1)/initramfs-${vtPaldoVer}
+ boot
+
+ vt_img_unhook_root
+ vt_unset_boot_opt
+}
+
+function ventoy_img_ubos {
+ vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
+ vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
+
+ vt_get_lib_module_ver (vtimghd,3) /lib/modules/ vt_module_ver
+ if [ -n "$vt_module_ver" ]; then
+ vt_img_extra_initrd_append (vtimghd,3)/lib/modules/$vt_module_ver/kernel/drivers/md/dm-mod.ko.xz
+ fi
+
+ ventoy_debug_pause
+
+ #boot image file
+ vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=ubos
+ vt_img_hook_root
+
+ echo loading file...
+ linux (vtimghd,2)/vmlinuz-linux root=/dev/ventoy3 rw
+ initrd (vtimghd,2)/initramfs-linux.img
+ boot
+
+ vt_img_unhook_root
+ vt_unset_boot_opt
+}
+
+function ventoy_img_recalbox {
+ vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
+ vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
+
+ ventoy_debug_pause
+
+ #boot image file
+ vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=recalbox
+ vt_img_hook_root
+
+ set root=(vtimghd,1)
+ configfile (vtimghd,1)/boot/grub/grub.cfg
+
+ vt_img_unhook_root
+ vt_unset_boot_opt
+}
+
+function ventoy_img_batocera {
+ vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
+ vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
+
+ ventoy_debug_pause
+
+ #boot image file
+ vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=batocera
+ vt_img_hook_root
+
+ set root=(vtimghd,1)
+ syslinux_configfile (vtimghd,1)/boot/syslinux/syslinux.cfg
+
+ vt_img_unhook_root
+ vt_unset_boot_opt
+}
+
+function ventoy_img_memtest86 {
+ chainloader (vtimghd,1)/efi/boot/BOOTX64.efi
+ boot
+}
+
+function img_unsupport_tip {
+ echo -e "\n This IMG file is NOT supported now. \n"
+ echo -e " 当前不支持启动此 IMG 文件 \n"
+ echo -e "\npress ENTER to exit (请按 回车 键返回) ..."
+ read vtInputKey
+}
+
+function img_common_menuentry {
+ set ventoy_compatible=YES
+ set ventoy_busybox_ver=32
+
+ vt_chosen_img_path vt_chosen_path vt_chosen_size
+
+ if vt_check_password "${vt_chosen_path}"; then
+ return
+ fi
+
+ if ventoy_vcfg_proc "${vt_chosen_path}"; then
+ return
+ fi
+
+ if [ -d (vtimghd)/ ]; then
+ loopback -d vtimghd
+ fi
+
+ loopback vtimghd "${vtoy_iso_part}${vt_chosen_path}"
+ vt_img_sector "${vtoy_iso_part}${vt_chosen_path}"
+
+ vt_img_part_info (vtimghd)
+
+ set vtback_root=$root
+ ventoy_cli_console
+ vt_push_last_entry
+
+ vt_img_extra_initrd_reset
+
+ vt_get_fs_label (vtimghd,1) vtImgHd1Label
+ if [ -d (vtimghd,2)/lib ]; then
+ vt_get_fs_label (vtimghd,2) vtImgHd2Label
+ fi
+
+ if [ -e (vtimghd,1)/etc/hostname ]; then
+ vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
+ fi
+
+ if [ -e (vtimghd,1)/easy.sfs ]; then
+ ventoy_img_easyos
+ elif [ -e (vtimghd,1)/volumio.initrd ]; then
+ ventoy_img_volumio
+ elif vt_str_begin "$vtImgHd1Label" "LAKKA"; then
+ ventoy_img_openelec lakka
+ elif vt_str_begin "$vtImgHd1Label" "LIBREELEC"; then
+ ventoy_img_openelec LibreELEC
+ elif vt_str_begin "$vtImgHd1Label" "paldo-live"; then
+ ventoy_img_paldo
+ elif vt_str_begin "$vtImgHostname" "freedombox"; then
+ ventoy_img_freedombox
+ elif vt_str_begin "$vtImgHd1Label" "BATOCERA"; then
+ ventoy_img_batocera
+ elif [ "$vtImgHd2Label" = "RECALBOX" ]; then
+ ventoy_img_recalbox
+ elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
+ ventoy_img_ubos
+ elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
+ if [ "$grub_platform" = "pc" ]; then
+ img_unsupport_tip
+ else
+ ventoy_img_memtest86
+ fi
+ else
+ vt_linux_chain_data "${vtoy_iso_part}${vt_chosen_path}"
+ ventoy_acpi_param ${vtoy_chain_mem_addr} 512
+ if [ "$grub_platform" = "pc" ]; then
+ linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} sector512 mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
+ boot
+ else
+ chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi sector512 env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
+ boot
+ fi
+ fi
+
+ set root=$vtback_root
+ vt_pop_last_entry
+ ventoy_gui_console
+ set ventoy_compatible=NO
+}
+
+function img_unsupport_menuentry {
+ common_unsupport_menuentry
+}
+