export C_INCLUDE_PATH=$LIBFUSE_DIR/include
rm -f $name
-gcc -O2 -D_FILE_OFFSET_BITS=64 vtoy_fuse_iso.c -o $name $LIBFUSE_DIR/lib/libfuse.a -lpthread -ldl $opt
+gcc -static -O2 -D_FILE_OFFSET_BITS=64 vtoy_fuse_iso.c -o $name $LIBFUSE_DIR/lib/libfuse.a -lpthread -ldl $opt
if [ -e $name ]; then
echo -e "\n############### SUCCESS $name ##################\n"
{ "vt_linux_clear_initrd", ventoy_cmd_clear_initrd_list, 0, NULL, "", "", NULL },
{ "vt_linux_dump_initrd", ventoy_cmd_dump_initrd_list, 0, NULL, "", "", NULL },
{ "vt_linux_initrd_count", ventoy_cmd_initrd_count, 0, NULL, "", "", NULL },
+ { "vt_linux_valid_initrd_count", ventoy_cmd_valid_initrd_count, 0, NULL, "", "", NULL },
{ "vt_linux_locate_initrd", ventoy_cmd_linux_locate_initrd, 0, NULL, "", "", NULL },
{ "vt_linux_chain_data", ventoy_cmd_linux_chain_data, 0, NULL, "", "", NULL },
grub_err_t ventoy_cmd_linux_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
+grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
int ventoy_cpio_newc_fill_head(void *buf, int filesize, void *filedata, const char *name);
grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...);
grub_strncpy(img->name, args[0], sizeof(img->name));
if (ventoy_find_initrd_by_name(g_initrd_img_list, img->name))
{
+ debug("%s is already exist\n", args[0]);
grub_free(img);
}
else
(void)argc;
(void)args;
+ if (argc == 1)
+ {
+ grub_snprintf(buf, sizeof(buf), "%d", g_initrd_img_count);
+ grub_env_set(args[0], buf);
+ }
+
+ VENTOY_CMD_RETURN(GRUB_ERR_NONE);
+}
+
+grub_err_t ventoy_cmd_valid_initrd_count(grub_extcmd_context_t ctxt, int argc, char **args)
+{
+ char buf[32] = {0};
+
+ (void)ctxt;
+ (void)argc;
+ (void)args;
+
if (argc == 1)
{
grub_snprintf(buf, sizeof(buf), "%d", g_valid_initrd_count);
static grub_err_t ventoy_linux_locate_initrd(int filt, int *filtcnt)
{
int data;
+ int filtbysize = 1;
int sizefilt = 0;
grub_file_t file;
initrd_info *node;
debug("ventoy_linux_locate_initrd %d\n", filt);
g_valid_initrd_count = 0;
+
+ if (grub_env_get("INITRD_NO_SIZE_FILT"))
+ {
+ filtbysize = 0;
+ }
for (node = g_initrd_img_list; node; node = node->next)
{
debug("file <%s> size:%d\n", node->name, (int)file->size);
/* initrd file too small */
- if (filt > 0 && file->size <= g_ventoy_cpio_size + 2048)
+ if (filtbysize
+ && (NULL == grub_strstr(node->name, "minirt.gz"))
+ && (NULL == grub_strstr(node->name, "initrd.xz"))
+ )
{
- debug("file size too small %d\n", (int)g_ventoy_cpio_size);
- grub_file_close(file);
- sizefilt++;
- continue;
+ if (filt > 0 && file->size <= g_ventoy_cpio_size + 2048)
+ {
+ debug("file size too small %d\n", (int)g_ventoy_cpio_size);
+ grub_file_close(file);
+ sizefilt++;
+ continue;
+ }
}
if (grub_strcmp(file->fs->name, "iso9660") == 0)
fi
}
+
+wait_for_usb_disk_ready
+
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
DISTRO='default'
-if [ -e /etc/initrd-release ]; then
+if [ -d /KNOPPIX ]; then
+ DISTRO='knoppix'
+elif [ -e /etc/initrd-release ]; then
if $EGREP -q "ID=.*antix|ID=.*mx" /etc/initrd-release; then
DISTRO='antix'
fi
fi
+if [ -e /init ]; then
+ if $GREP -q PUPPYSFS /init; then
+ if $GREP -q VEKETSFS /init; then
+ DISTRO='veket'
+ else
+ DISTRO='puppy'
+ fi
+ fi
+fi
+
+if [ -e /etc/os-release ]; then
+ if $GREP -q 'Tails' /etc/os-release; then
+ DISTRO='tails'
+ fi
+fi
+
+if [ "$DISTRO"="default" ]; then
+ if $GREP -q 'slax/' /proc/cmdline; then
+ DISTRO='slax'
+ fi
+fi
+
+
echo "##### distribution = $DISTRO ######" >> $VTLOG
. $VTOY_PATH/hook/debian/${DISTRO}-hook.sh
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace"
else
- $SED "/mdev *-s/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
+ if $GREP -q kaspersky /proc/version; then
+ $SED "/sysresccd_stage1_normal[^(]*$/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
+ else
+ $SED "/mdev *-s/a\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/gentoo/disk_hook.sh" -i /init
+ fi
fi
SLEEP=$BUSYBOX_PATH/sleep
HEAD=$BUSYBOX_PATH/head
VTOY_DM_PATH=/dev/mapper/ventoy
-VTOY_DEBUG_LEVEL=$($BUSYBOX_PATH/hexdump -n 1 -s 430 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
+VTOY_DEBUG_LEVEL=$($BUSYBOX_PATH/hexdump -n 1 -s 450 -e '1/1 "%02x"' $VTOY_PATH/ventoy_os_param)
if [ "$VTOY_DEBUG_LEVEL" = "01" ]; then
if [ -e /dev/console ]; then
# Step 1 : parse kernel debug parameter #
# #
####################################################################
-mkdir /proc; mount -t proc proc /proc
+[ -d /proc ] || mkdir /proc; mount -t proc proc /proc
vtcmdline=$(cat /proc/cmdline)
vtkerver=$(cat /proc/version)
umount /proc; rm -rf /proc
if [ "${vtx:0:4}" = "${vtmagic:0:4}" ]; then
echo "vtx=$vtx" >> $VTLOG
if [ $vtskip -eq 0 ]; then
- ${vtx:5} $vtfile | (cpio -idm 2>>$VTLOG; cat > $vttmp)
+ ${vtx:5} $vtfile | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
else
- dd if=$vtfile skip=$vtskip iflag=skip_bytes status=none | ${vtx:5} | (cpio -idm 2>>$VTLOG; cat > $vttmp)
+ dd if=$vtfile skip=$vtskip iflag=skip_bytes status=none | ${vtx:5} | (cpio -idmu 2>>$VTLOG; cat > $vttmp)
fi
break
fi
# This export is for busybox cpio command
export EXTRACT_UNSAFE_SYMLINKS=1
-for vtfile in $(ls /initrd*); do
- #decompress first initrd
- vtmagic=$(hexdump -n 2 -e '2/1 "%02X"' $vtfile)
-
- if ventoy_is_initrd_ramdisk; then
- ventoy_unpack_initrd $vtfile $vtmagic ${vtfile}_tmp
- mv ${vtfile}_tmp $vtfile
- break
+# special process
+need_xzminidec() {
+ testmagic=$(hexdump -n 2 -e '2/1 "%02X"' /initrd001)
+ if [ "FD37" = "${testmagic:0:4}" ]; then
+ if echo $vtkerver | grep -q 'kaspersky'; then
+ true
+ elif echo $vtkerver | grep -q 'kiosk.*Gentoo'; then
+ true
+ else
+ false
+ fi
else
- ventoy_unpack_initramfs $vtfile 0 $vtmagic ${vtfile}_tmp
+ false
fi
+}
- #only for cpio,cpio,...,initrd sequence, initrd,cpio or initrd,initrd sequence is not supported
- while [ -e ${vtfile}_tmp ] && [ $(stat -c '%s' ${vtfile}_tmp) -gt 512 ]; do
- mv ${vtfile}_tmp $vtfile
- vtdump=$(hexdump -n 512 -e '512/1 "%02X"' $vtfile)
- vtmagic=$(echo $vtdump | sed 's/^\(00\)*//')
- let vtoffset="(${#vtdump}-${#vtmagic})/2"
-
- if [ -z "$vtmagic" ]; then
- echo "terminate with all zero data file" >> $VTLOG
+if need_xzminidec; then
+ echo "use xzminidec" >> $VTLOG
+ cat /initrd001 | xzminidec | cpio -idmu 2>>$VTLOG
+ rm -f /initrd001
+else
+ for vtfile in $(ls /initrd*); do
+ #decompress first initrd
+ vtmagic=$(hexdump -n 2 -e '2/1 "%02X"' $vtfile)
+
+ if ventoy_is_initrd_ramdisk; then
+ ventoy_unpack_initrd $vtfile $vtmagic ${vtfile}_tmp
+ mv ${vtfile}_tmp $vtfile
break
+ else
+ ventoy_unpack_initramfs $vtfile 0 $vtmagic ${vtfile}_tmp
fi
+
+ #only for cpio,cpio,...,initrd sequence, initrd,cpio or initrd,initrd sequence is not supported
+ while [ -e ${vtfile}_tmp ] && [ $(stat -c '%s' ${vtfile}_tmp) -gt 512 ]; do
+ mv ${vtfile}_tmp $vtfile
+ vtdump=$(hexdump -n 512 -e '512/1 "%02X"' $vtfile)
+ vtmagic=$(echo $vtdump | sed 's/^\(00\)*//')
+ let vtoffset="(${#vtdump}-${#vtmagic})/2"
+
+ if [ -z "$vtmagic" ]; then
+ echo "terminate with all zero data file" >> $VTLOG
+ break
+ fi
+
+ ventoy_unpack_initramfs $vtfile $vtoffset ${vtmagic:0:4} ${vtfile}_tmp
+ done
- ventoy_unpack_initramfs $vtfile $vtoffset ${vtmagic:0:4} ${vtfile}_tmp
+ rm -f $vtfile ${vtfile}_tmp
done
-
- rm -f $vtfile ${vtfile}_tmp
-done
-
+fi
#break here for debug
if [ "$VTOY_BREAK_LEVEL" = "02" ] || [ "$VTOY_BREAK_LEVEL" = "12" ]; then
echo 'slackware'; return
fi
+ if [ -e /init ]; then
+ if $GREP -i -q zeroshell /init; then
+ echo 'zeroshell'; return
+ fi
+ fi
+
echo "default"
}
fi
}
-function locate_initrd {
+function locate_initrd {
vt_linux_locate_initrd
if [ -n "${vtdebug_flag}" ]; then
if [ -e (loop)/casper/initrd-oem ]; then
vt_linux_specify_initrd_file /casper/initrd-oem
fi
+ elif [ -e (loop)/boot/grub/initrd.xz ]; then
+ vt_linux_specify_initrd_file /boot/grub/initrd.xz
+ elif [ -e (loop)/initrd.gz ]; then
+ vt_linux_specify_initrd_file /initrd.gz
+ elif [ -e (loop)/slax/boot/initrfs.img ]; then
+ vt_linux_specify_initrd_file /slax/boot/initrfs.img
+ elif [ -e (loop)/pmagic/initrd.img ]; then
+ vt_linux_specify_initrd_file /pmagic/initrd.img
+ elif [ -e (loop)/boot/initrd.xz ]; then
+ vt_linux_specify_initrd_file /boot/initrd.xz
fi
}
vt_linux_clear_initrd
- for file in "boot/grub/grub.cfg" "EFI/BOOT/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
- if [ -e (loop)/$file ]; then
- vt_linux_parse_initrd_grub file (loop)/$file
- fi
- done
-
- vt_linux_initrd_count initrd_count
+ if [ -d (loop)/pmagic ]; then
+ vt_linux_specify_initrd_file /pmagic/initrd.img
+ else
+ for file in "boot/grub/grub.cfg" "EFI/BOOT/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "EFI/BOOT/BOOTX64.conf"; do
+ if [ -e (loop)/$file ]; then
+ vt_linux_parse_initrd_grub file (loop)/$file
+ fi
+ done
+ fi
# special process for special distros
- if vt_cmp $initrd_count eq 0; then
- if [ -d (loop)/loader/entries ]; then
- set LoadIsoEfiDriver=on
- vt_linux_parse_initrd_grub dir (loop)/loader/entries/
- elif [ -d (loop)/boot/grub ]; then
- vt_linux_parse_initrd_grub dir (loop)/boot/grub/
- fi
+ if [ -d (loop)/loader/entries ]; then
+ set LoadIsoEfiDriver=on
+ vt_linux_parse_initrd_grub dir (loop)/loader/entries/
+ elif [ -d (loop)/boot/grub ]; then
+ vt_linux_parse_initrd_grub dir (loop)/boot/grub/
fi
- vt_linux_initrd_count initrd_count
- if vt_cmp $initrd_count eq 0; then
- distro_specify_initrd_file
- fi
+ distro_specify_initrd_file
locate_initrd
fi
vt_load_cpio $vtoy_path/ventoy.cpio
vt_linux_clear_initrd
-
- for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
- if [ -d (loop)/$dir ]; then
- vt_linux_parse_initrd_isolinux (loop)/$dir/
- fi
- done
- vt_linux_initrd_count initrd_count
+ if [ -d (loop)/pmagic ]; then
+ vt_linux_specify_initrd_file /pmagic/initrd.img
+ else
+ for dir in "isolinux" "boot/isolinux" "boot/x86_64/loader" "syslinux" "boot/syslinux"; do
+ if [ -d (loop)/$dir ]; then
+ vt_linux_parse_initrd_isolinux (loop)/$dir/
+ fi
+ done
+ fi
# special process for special distros
- if vt_cmp $initrd_count eq 0; then
- #archlinux
- if [ -d (loop)/arch/boot/syslinux ]; then
- vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
- vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
-
- #manjaro
- elif [ -d (loop)/manjaro ]; then
- if [ -e (loop)/boot/grub/kernels.cfg ]; then
- vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
- fi
- elif [ -e (loop)/boot/grub/grub.cfg ]; then
- vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
+ #archlinux
+ if [ -d (loop)/arch/boot/syslinux ]; then
+ vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/
+ vt_linux_parse_initrd_isolinux (loop)/arch/boot/syslinux/ /arch/boot/syslinux/
+
+ #manjaro
+ elif [ -d (loop)/manjaro ]; then
+ if [ -e (loop)/boot/grub/kernels.cfg ]; then
+ vt_linux_parse_initrd_grub file (loop)/boot/grub/kernels.cfg
fi
+ elif [ -e (loop)/boot/grub/grub.cfg ]; then
+ vt_linux_parse_initrd_grub file (loop)/boot/grub/grub.cfg
fi
- vt_linux_initrd_count initrd_count
- if vt_cmp $initrd_count eq 0; then
- distro_specify_initrd_file
- fi
+ distro_specify_initrd_file
locate_initrd
fi
#############################################################
#############################################################
-set VENTOY_VERSION="1.0.04"
+set VENTOY_VERSION="1.0.05"
#disable timeout
unset timeout
if [ "$vtoy_dev" = "tftp" ]; then
set vtoy_path=($root)
for vtid in 0 1 2 3; do
- if [ -d (hd$vtid,2)/grub ]; then
+ if [ -d (hd$vtid,2)/ventoy ]; then
set iso_path=(hd$vtid,1)
break
fi
#include "vtoyjump.h"
#include "fat_filelib.h"
+static ventoy_os_param g_os_param;
static UINT8 g_os_param_reserved[32];
static BOOL g_64bit_system = FALSE;
static ventoy_guid g_ventoy_guid = VENTOY_GUID;
DWORD PeStart;
DWORD FileSize;
BYTE *Buffer = NULL;
- ventoy_os_param os_param;
CHAR ExeFileName[MAX_PATH];
sprintf_s(ExeFileName, sizeof(ExeFileName), "%s", argv[0]);
CheckPeHead(Buffer + PeStart + sizeof(ventoy_os_param)))
{
Log("Find os pararm at %u", PeStart);
- memcpy(&os_param, Buffer + PeStart, sizeof(ventoy_os_param));
- memcpy(g_os_param_reserved, os_param.vtoy_reserved, sizeof(g_os_param_reserved));
+ memcpy(&g_os_param, Buffer + PeStart, sizeof(ventoy_os_param));
+ memcpy(g_os_param_reserved, g_os_param.vtoy_reserved, sizeof(g_os_param_reserved));
if (g_os_param_reserved[0] == 1)
{
}
// convert / to \\
- for (Pos = 0; Pos < sizeof(os_param.vtoy_img_path) && os_param.vtoy_img_path[Pos]; Pos++)
+ for (Pos = 0; Pos < sizeof(g_os_param.vtoy_img_path) && g_os_param.vtoy_img_path[Pos]; Pos++)
{
- if (os_param.vtoy_img_path[Pos] == '/')
+ if (g_os_param.vtoy_img_path[Pos] == '/')
{
- os_param.vtoy_img_path[Pos] = '\\';
+ g_os_param.vtoy_img_path[Pos] = '\\';
}
}
goto End;
}
- rc = VentoyHook(&os_param);
+ rc = VentoyHook(&g_os_param);
End:
GetStartupInfoA(&Si);
- for (i = 0; i < 10; i++)
+ memset(LunchFile, 0, sizeof(LunchFile));
+ rc = VentoyJump(argc, argv, LunchFile);
+
+ if (g_os_param_reserved[0] == 3)
+ {
+ Log("Open log for debug ...");
+ sprintf_s(LunchFile, sizeof(LunchFile), "%s", "notepad.exe ventoy.log");
+ }
+ else
{
- Log("VentoyJump loop %d", i + 1);
+ Si.dwFlags |= STARTF_USESHOWWINDOW;
+ Si.wShowWindow = SW_HIDE;
+ Log("Ventoy jump %s ...", rc == 0 ? "success" : "failed");
+ }
- memset(LunchFile, 0, sizeof(LunchFile));
- rc = VentoyJump(argc, argv, LunchFile);
+ CreateProcessA(NULL, LunchFile, NULL, NULL, FALSE, 0, NULL, NULL, &Si, &Pi);
- if (g_os_param_reserved[0] == 3)
- {
- Log("Open log for debug ...");
- sprintf_s(LunchFile, sizeof(LunchFile), "%s", "notepad.exe ventoy.log");
- break;
- }
- else if (rc == 0)
- {
- Log("Ventoy jump success ...");
- Si.dwFlags |= STARTF_USESHOWWINDOW;
- Si.wShowWindow = SW_HIDE;
- break;
- }
- else
- {
- Log("Ventoy jump fail, now wait ...");
- sprintf_s(LunchFile, sizeof(LunchFile), "%s", "cmd.exe");
- Sleep(3000);
- }
+ while (rc)
+ {
+ Log("Ventoy hook failed, now wait and retry ...");
+ Sleep(1000);
+
+ rc = VentoyHook(&g_os_param);
}
- CreateProcessA(NULL, LunchFile, NULL, NULL, FALSE, 0, NULL, NULL, &Si, &Pi);
WaitForSingleObject(Pi.hProcess, INFINITE);
return 0;