Commit 324c9788 authored by longpanda's avatar longpanda
Browse files

Improvement for UEFI boot compatibility.

parent 3c35345e
......@@ -37,6 +37,7 @@
#include <Ventoy.h>
BOOLEAN gDebugPrint = FALSE;
BOOLEAN gBootFallBack = FALSE;
BOOLEAN gDotEfiBoot = FALSE;
BOOLEAN gLoadIsoEfi = FALSE;
BOOLEAN gIsoUdf = FALSE;
......@@ -696,6 +697,11 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
gDebugPrint = TRUE;
}
if (StrStr(pCmdLine, L"fallback"))
{
gBootFallBack = TRUE;
}
if (StrStr(pCmdLine, L"dotefi"))
{
gDotEfiBoot = TRUE;
......@@ -1035,7 +1041,7 @@ EFI_STATUS EFIAPI ventoy_boot(IN EFI_HANDLE ImageHandle)
}
debug("Fs not found, now wait and retry...");
sleep(2);
sleep(1);
}
}
......@@ -1135,7 +1141,7 @@ EFI_STATUS EFIAPI VentoyEfiMain
ventoy_clean_env();
}
if (FALSE == gDotEfiBoot)
if (FALSE == gDotEfiBoot && FALSE == gBootFallBack)
{
if (EFI_NOT_FOUND == Status)
{
......
This diff is collapsed.
......@@ -88,7 +88,6 @@ static int ventoy_linux_argc = 0;
static char **ventoy_linux_args = NULL;
static int ventoy_extra_initrd_num = 0;
static char *ventoy_extra_initrd_list[256];
static grub_err_t
grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]);
......@@ -544,14 +543,10 @@ static int ventoy_bootopt_hook(int argc, char *argv[])
return 0;
}
for (i = 0; i < argc; i++)
/* the 1st parameter is BOOT_IMAGE=xxxx */
if (argc > 0 && 0 == ventoy_boot_opt_filter(argv[0]))
{
if (ventoy_boot_opt_filter(argv[i]))
{
continue;
}
ventoy_linux_args[count++] = grub_strdup(argv[i]);
ventoy_linux_args[count++] = grub_strdup(argv[0]);
}
for (i = 0; i < ventoy_linux_argc; i++)
......@@ -623,6 +618,17 @@ static int ventoy_bootopt_hook(int argc, char *argv[])
}
}
/* We have processed the 1st parameter before, so start from 1 */
for (i = 1; i < argc; i++)
{
if (ventoy_boot_opt_filter(argv[i]))
{
continue;
}
ventoy_linux_args[count++] = grub_strdup(argv[i]);
}
if (ventoy_debug)
{
ventoy_linux_args[count++] = grub_strdup("loglevel=7");
......
......@@ -37,7 +37,6 @@ for i in $vtcmdline; do
fi
done
####################################################################
# #
# Step 2 : Do OS specific hook #
......
......@@ -67,11 +67,6 @@ ventoy_get_os_type() {
echo "kernel version" >> $VTLOG
$CAT /proc/version >> $VTLOG
# deepin-live
if $GREP -q 'deepin' /proc/version; then
echo 'deepin'; return
fi
if $GREP -q 'endless' /proc/version; then
echo 'endless'; return
fi
......@@ -96,6 +91,278 @@ ventoy_get_os_type() {
$SED "s/.*ventoyos=\([a-zA-Z0-9_-]*\).*/\1/" /proc/cmdline; return
fi
if [ -d /twres ]; then
if $GREP -q 'Phoenix' /init; then
echo 'phoenixos'; return
fi
fi
# rhel5/CentOS5 and all other distributions based on them
if $GREP -q 'el5' /proc/version; then
echo 'rhel5'; return
# rhel6/CentOS6 and all other distributions based on them
elif $GREP -q 'el6' /proc/version; then
echo 'rhel6'; return
# rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
elif $GREP -q 'el[78]' /proc/version; then
echo 'rhel7'; return
# Maybe rhel9 rhel1x use the same way? Who knows!
elif $EGREP -q 'el9|el1[0-9]' /proc/version; then
echo 'rhel7'; return
# Fedora : do the same process with rhel7
elif $GREP -q '\.fc[0-9][0-9]\.' /proc/version; then
echo 'rhel7'; return
# Debian :
elif $GREP -q '[Dd]ebian' /proc/version; then
echo 'debian'; return
# Ubuntu : do the same process with debian
elif $GREP -q '[Uu]buntu' /proc/version; then
echo 'debian'; return
# Deepin : do the same process with debian
elif $GREP -q '[Dd]eepin' /proc/version; then
echo 'debian'; return
# SUSE
elif $GREP -q 'SUSE' /proc/version; then
echo 'suse'; return
# ArchLinux
elif $EGREP -q 'archlinux|ARCH' /proc/version; then
echo 'arch'; return
# kiosk
elif $EGREP -q 'kiosk' /proc/version; then
echo 'kiosk'; return
# gentoo
elif $EGREP -q '[Gg]entoo' /proc/version; then
if $GREP -q 'daphile' /proc/version; then
echo 'daphile'; return
fi
echo 'gentoo'; return
# TinyCore
elif $EGREP -q 'tinycore' /proc/version; then
echo 'tinycore'; return
# manjaro
elif $EGREP -q 'manjaro|MANJARO' /proc/version; then
echo 'manjaro'; return
# mageia
elif $EGREP -q 'mageia' /proc/version; then
echo 'mageia'; return
# pclinux OS
elif $GREP -i -q 'PCLinuxOS' /proc/version; then
echo 'pclos'; return
# KaOS
elif $GREP -i -q 'kaos' /proc/version; then
echo 'kaos'; return
# Alpine
elif $GREP -q 'Alpine' /proc/version; then
echo 'alpine'; return
elif $GREP -i -q 'PhoenixOS' /proc/version; then
echo 'phoenixos'; return
# NixOS
elif $GREP -i -q 'NixOS' /proc/version; then
echo 'nixos'; return
fi
if [ -e /lib/debian-installer ]; then
echo 'debian'; return
fi
if [ -e /etc/os-release ]; then
if $GREP -q 'XenServer' /etc/os-release; then
echo 'xen'; return
elif $GREP -q 'SUSE ' /etc/os-release; then
echo 'suse'; return
elif $GREP -q 'uruk' /etc/os-release; then
echo 'debian'; return
elif $GREP -q 'Solus' /etc/os-release; then
echo 'rhel7'; return
fi
fi
if $BUSYBOX_PATH/dmesg | $GREP -q -m1 "Xen:"; then
echo 'xen'; return
fi
if [ -e /etc/HOSTNAME ] && $GREP -i -q 'slackware' /etc/HOSTNAME; then
echo 'slackware'; return
fi
if [ -e /init ]; then
if $GREP -i -q zeroshell /init; then
echo 'zeroshell'; return
fi
fi
if $EGREP -q 'ALT ' /proc/version; then
echo 'alt'; return
fi
if $EGREP -q 'porteus' /proc/version; then
echo 'debian'; return
fi
if $GREP -q 'Clear Linux ' /proc/version; then
echo 'clear'; return
fi
if $GREP -q 'artix' /proc/version; then
echo 'arch'; return
fi
if $GREP -q 'berry ' /proc/version; then
echo 'berry'; return
fi
if $GREP -q 'Gobo ' /proc/version; then
echo 'gobo'; return
fi
if $GREP -q 'NuTyX' /proc/version; then
echo 'nutyx'; return
fi
if [ -d /gnu ]; then
vtLineNum=$($FIND /gnu/ -name guix | $BUSYBOX_PATH/wc -l)
if [ $vtLineNum -gt 0 ]; then
echo 'guix'; return
fi
fi
if $GREP -q 'android.x86' /proc/version; then
echo 'android'; return
fi
if $GREP -q 'adelielinux' /proc/version; then
echo 'adelie'; return
fi
if $GREP -q 'pmagic' /proc/version; then
echo 'pmagic'; return
fi
if $GREP -q 'CDlinux' /proc/cmdline; then
echo 'cdlinux'; return
fi
if $GREP -q 'parabola' /proc/version; then
echo 'parabola'; return
fi
if $GREP -q 'cucumber' /proc/version; then
echo 'cucumber'; return
fi
if $GREP -q 'fatdog' /proc/version; then
echo 'fatdog'; return
fi
if $GREP -q 'KWORT' /proc/version; then
echo 'kwort'; return
fi
if $GREP -q 'iwamoto' /proc/version; then
echo 'vine'; return
fi
if $GREP -q 'hyperbola' /proc/cmdline; then
echo 'hyperbola'; return
fi
if $GREP -q 'CRUX' /proc/version; then
echo 'crux'; return
fi
if [ -f /init ]; then
if $GREP -q 'AryaLinux' /init; then
echo 'aryalinux'; return
elif $GREP -q 'Dragora' /init; then
echo 'dragora'; return
fi
fi
if $GREP -q 'slackware' /proc/version; then
echo 'slackware'; return
fi
if $BUSYBOX_PATH/hostname | $GREP -q 'smoothwall'; then
echo 'smoothwall'; return
fi
if $GREP -q 'photon' /proc/version; then
echo 'photon'; return
fi
if $GREP -q 'ploplinux' /proc/version; then
echo 'ploplinux'; return
fi
if $GREP -q 'lunar' /proc/version; then
echo 'lunar'; return
fi
if $GREP -q 'SMGL-' /proc/version; then
echo 'smgl'; return
fi
if $GREP -q 'rancher' /proc/version; then
echo 'rancher'; return
fi
if [ -e /init ]; then
if $GREP -q -m1 'T2 SDE' /init; then
echo 't2'; return
fi
fi
if $GREP -q 'wifislax' /proc/version; then
echo 'wifislax'; return
fi
if $GREP -q 'pisilinux' /proc/version; then
echo 'pisilinux'; return
fi
if $GREP -q 'blackPanther' /proc/version; then
echo 'blackPanther'; return
fi
if $GREP -q 'primeos' /proc/version; then
echo 'primeos'; return
fi
if $GREP -q 'austrumi' /proc/version; then
echo 'austrumi'; return
fi
if [ -f /DISTRO_SPECS ]; then
if $GREP -q '[Pp]uppy' /DISTRO_SPECS; then
echo 'debian'; return
fi
fi
echo "default"
}
......@@ -103,6 +370,8 @@ VTOS=$(ventoy_get_os_type)
echo "OS=###${VTOS}###" >>$VTLOG
if [ -e "$VTOY_PATH/loop/$VTOS/ventoy-hook.sh" ]; then
$BUSYBOX_PATH/sh "$VTOY_PATH/loop/$VTOS/ventoy-hook.sh"
elif [ -e "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh" ]; then
$BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-hook.sh"
fi
......@@ -133,11 +402,16 @@ if [ "$rmproc" = "Y" ]; then
$BUSYBOX_PATH/rm -rf /proc
fi
if [ -f $VTOY_PATH/ventoy_persistent_map ]; then
export PERSISTENT='YES'
export PERSISTENCE='true'
fi
cd /
unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD
unset VTLOG FIND GREP EGREP CAT AWK SED SLEEP HEAD vtcmdline
for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
if [ -d /ventoy_rdroot ]; then
if [ -e "/ventoy_rdroot$vtinit" ]; then
# switch_root will check /init file, this is a cheat code
......@@ -146,6 +420,9 @@ for vtinit in $user_rdinit /init /sbin/init /linuxrc; do
fi
else
if [ -e "$vtinit" ];then
if [ -f "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh" ]; then
$BUSYBOX_PATH/sh "$VTOY_PATH/hook/$VTOS/ventoy-before-init.sh"
fi
exec "$vtinit"
fi
fi
......
......@@ -77,7 +77,9 @@ gptsync: gptsync
halt: halt
help: minicmd
initrd: linux
initrdefi: linux
linux: linux
linuxefi: linux
list_trusted: pgp
loadfont: font
lsefi: lsefi
......@@ -127,6 +129,10 @@ time: time
true: true
videoinfo: videoinfo
videotest: videotest
vt_img_extra_initrd_append: linux
vt_img_extra_initrd_reset: linux
vt_set_boot_opt: linux
vt_unset_boot_opt: linux
write_byte: memrw
write_dword: memrw
write_word: memrw
......
......@@ -646,8 +646,35 @@ function uefi_linux_menu_func {
if [ -n "$vtoy_chain_mem_addr" ]; then
ventoy_acpi_param ${vtoy_chain_mem_addr} 2048
ventoy_cli_console
chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
chainloader ${vtoy_path}/ventoy_${VTOY_EFI_ARCH}.efi fallback env_param=${env_param} isoefi=${LoadIsoEfiDriver} FirstTry=${FirstTryBootFile} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
boot
# fallback
set vtback_root=$root
vt_push_last_entry
set vtback_theme=$theme
unset theme
vt_trailer_cpio "$vtoy_iso_part" "$vt_chosen_path" noinit
vt_set_boot_opt rdinit=/vtoy/vtoy
set root=(loop)
for cfg in "/boot/grub/grub.cfg" "/EFI/BOOT/grub.cfg" "/EFI/debian/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "/grub/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
if [ -e "$cfg" ]; then
configfile "$cfg"
break
fi
done
vt_unset_boot_opt
set root=$vtback_root
set theme=$vtback_theme
vt_pop_last_entry
ventoy_gui_console
echo "No bootfile found for UEFI!"
echo "Maybe the image does not support $VTOY_EFI_ARCH UEFI"
echo " "
else
echo "chain empty failed"
ventoy_pause
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment