This commit is contained in:
longpanda 2021-01-06 07:50:23 +08:00
parent 6434e453b2
commit f2ed81b004
25 changed files with 289 additions and 20 deletions

View File

@ -1597,6 +1597,7 @@ module = {
common = ventoy/lzx.c;
common = ventoy/xpress.c;
common = ventoy/huffman.c;
common = ventoy/miniz.c;
};
module = {

View File

@ -43,8 +43,10 @@
#include <grub/acpi.h>
#include <grub/charset.h>
#include <grub/crypto.h>
#include <grub/lib/crc.h>
#include <grub/ventoy.h>
#include "ventoy_def.h"
#include "miniz.h"
GRUB_MOD_LICENSE ("GPLv3+");
@ -105,6 +107,7 @@ int g_conf_replace_new_len = 0;
int g_conf_replace_new_len_align = 0;
ventoy_gpt_info *g_ventoy_part_info = NULL;
grub_uint64_t g_ventoy_disk_size = 0;
static char *g_tree_script_buf = NULL;
static int g_tree_script_pos = 0;
@ -3437,6 +3440,22 @@ static grub_err_t ventoy_cmd_pop_last_entry(grub_extcmd_context_t ctxt, int argc
return 0;
}
grub_uint64_t ventoy_get_part1_size(ventoy_gpt_info *gpt)
{
grub_uint64_t sectors;
if (grub_strncmp(gpt->Head.Signature, "EFI PART", 8) == 0)
{
sectors = gpt->PartTbl[0].LastLBA + 1 - gpt->PartTbl[0].StartLBA;
}
else
{
sectors = gpt->MBR.PartTbl[0].SectorCount;
}
return sectors * 512;
}
static int ventoy_lib_module_callback(const char *filename, const struct grub_dirhook_info *info, void *data)
{
const char *pos = filename + 1;
@ -3539,6 +3558,8 @@ static grub_err_t ventoy_cmd_load_part_table(grub_extcmd_context_t ctxt, int arg
return 1;
}
g_ventoy_disk_size = disk->total_sectors * (1U << disk->log_sector_size);
grub_disk_read(disk, 0, 0, sizeof(ventoy_gpt_info), g_ventoy_part_info);
grub_disk_close(disk);
@ -3926,6 +3947,47 @@ int ventoy_is_dir_exist(const char *fmt, ...)
return 0;
}
int ventoy_gzip_compress(void *mem_in, int mem_in_len, void *mem_out, int mem_out_len)
{
mz_stream s;
grub_uint8_t *outbuf;
grub_uint8_t gzHdr[10] =
{
0x1F, 0x8B, /* magic */
8, /* z method */
0, /* flags */
0,0,0,0, /* mtime */
4, /* xfl */
3, /* OS */
};
grub_memset(&s, 0, sizeof(mz_stream));
mz_deflateInit2(&s, 1, MZ_DEFLATED, -MZ_DEFAULT_WINDOW_BITS, 6, MZ_DEFAULT_STRATEGY);
outbuf = (grub_uint8_t *)mem_out;
mem_out_len -= sizeof(gzHdr) + 8;
grub_memcpy(outbuf, gzHdr, sizeof(gzHdr));
outbuf += sizeof(gzHdr);
s.avail_in = mem_in_len;
s.next_in = mem_in;
s.avail_out = mem_out_len;
s.next_out = outbuf;
mz_deflate(&s, MZ_FINISH);
mz_deflateEnd(&s);
outbuf += s.total_out;
*(grub_uint32_t *)outbuf = grub_getcrc32c(0, outbuf, s.total_out);
*(grub_uint32_t *)(outbuf + 4) = (grub_uint32_t)(s.total_out);
return s.total_out + sizeof(gzHdr) + 8;
}
static int ventoy_env_init(void)
{
char buf[64];
@ -4055,6 +4117,8 @@ static cmd_para ventoy_cmds[] =
{ "vt_unix_reset", ventoy_cmd_unix_reset, 0, NULL, "", "", NULL },
{ "vt_unix_replace_conf", ventoy_cmd_unix_replace_conf, 0, NULL, "", "", NULL },
{ "vt_unix_replace_ko", ventoy_cmd_unix_replace_ko, 0, NULL, "", "", NULL },
{ "vt_unix_fill_image_desc", ventoy_cmd_unix_fill_image_desc, 0, NULL, "", "", NULL },
{ "vt_unix_gzip_new_ko", ventoy_cmd_unix_gzip_newko, 0, NULL, "", "", NULL },
{ "vt_unix_chain_data", ventoy_cmd_unix_chain_data, 0, NULL, "", "", NULL },
{ "vt_img_hook_root", ventoy_cmd_img_hook_root, 0, NULL, "", "", NULL },

View File

@ -875,6 +875,7 @@ extern conf_replace *g_conf_replace_node;
extern grub_uint8_t *g_conf_replace_new_buf;
extern int g_conf_replace_new_len;
extern int g_conf_replace_new_len_align;
extern grub_uint64_t g_ventoy_disk_size;
#define ventoy_unix_fill_virt(new_data, new_len) \
{ \
@ -924,6 +925,8 @@ int ventoy_get_disk_guid(const char *filename, grub_uint8_t *guid, grub_uint8_t
grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_gzip_newko(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_unix_freebsd_ver(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_parse_freenas_ver(grub_extcmd_context_t ctxt, int argc, char **args);
int ventoy_check_device_result(int ret);
@ -934,6 +937,8 @@ grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char *
grub_err_t ventoy_cmd_raw_chain_data(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char **args);
int ventoy_check_password(const vtoy_password *pwd, int retry);
int ventoy_gzip_compress(void *mem_in, int mem_in_len, void *mem_out, int mem_out_len);
grub_uint64_t ventoy_get_part1_size(ventoy_gpt_info *gpt);
#endif /* __VENTOY_DEF_H__ */

View File

@ -235,6 +235,21 @@ static int ventoy_freebsd_append_conf(char *buf, const char *isopath)
return pos;
}
static int ventoy_dragonfly_append_conf(char *buf, const char *isopath)
{
int pos = 0;
debug("ventoy_dragonfly_append_conf %s\n", isopath);
vtoy_ssprintf(buf, pos, "tmpfs_load=\"%s\"\n", "YES");
vtoy_ssprintf(buf, pos, "dm_target_linear_load=\"%s\"\n", "YES");
vtoy_ssprintf(buf, pos, "initrd.img_load=\"%s\"\n", "YES");
vtoy_ssprintf(buf, pos, "initrd.img_type=\"%s\"\n", "md_image");
vtoy_ssprintf(buf, pos, "vfs.root.mountfrom=\"%s\"\n", "ufs:md0s0");
return pos;
}
grub_err_t ventoy_cmd_unix_reset(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
@ -431,6 +446,10 @@ grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, ch
{
g_conf_new_len += ventoy_freebsd_append_conf(data + file->size, args[1]);
}
else if (grub_strcmp(args[0], "DragonFly") == 0)
{
g_conf_new_len += ventoy_dragonfly_append_conf(data + file->size, args[1]);
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
@ -474,6 +493,7 @@ grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char
data = grub_malloc(file->size);
if (!data)
{
debug("Failed to alloc memory for new ko %d\n", (int)file->size);
grub_file_close(file);
return 1;
}
@ -487,6 +507,105 @@ grub_err_t ventoy_cmd_unix_replace_ko(grub_extcmd_context_t ctxt, int argc, char
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_unix_fill_image_desc(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
grub_uint8_t *byte;
grub_uint32_t memsize;
ventoy_image_desc *desc;
grub_uint8_t flag[32] = {
0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00,
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
};
(void)ctxt;
(void)argc;
(void)args;
debug("ventoy_cmd_unix_fill_image_desc %p\n", g_mod_new_data);
if (!g_mod_new_data)
{
goto end;
}
byte = (grub_uint8_t *)g_mod_new_data;
for (i = 0; i < g_mod_new_len - 32; i += 16)
{
if (byte[i] == 0xFF && byte[i + 1] == 0xEE)
{
if (grub_memcmp(flag, byte + i, 32) == 0)
{
debug("Find position flag at %d(0x%x)\n", i, i);
break;
}
}
}
if (i >= g_mod_new_len - 32)
{
debug("Failed to find position flag %d\n", i);
goto end;
}
desc = (ventoy_image_desc *)(byte + i);
desc->disk_size = g_ventoy_disk_size;
desc->part1_size = ventoy_get_part1_size(g_ventoy_part_info);
grub_memcpy(desc->disk_uuid, g_ventoy_part_info->MBR.BootCode + 0x180, 16);
grub_memcpy(desc->disk_signature, g_ventoy_part_info->MBR.BootCode + 0x1B8, 4);
desc->img_chunk_count = g_img_chunk_list.cur_chunk;
memsize = g_img_chunk_list.cur_chunk * sizeof(ventoy_img_chunk);
debug("image chunk count:%u memsize:%u\n", desc->img_chunk_count, memsize);
if (memsize >= VTOY_SIZE_1MB * 8)
{
grub_printf("image chunk count:%u memsize:%u too big\n", desc->img_chunk_count, memsize);
goto end;
}
grub_memcpy(desc + 1, g_img_chunk_list.chunk, memsize);
end:
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_unix_gzip_newko(grub_extcmd_context_t ctxt, int argc, char **args)
{
int newlen;
grub_uint8_t *buf;
(void)ctxt;
(void)argc;
(void)args;
debug("ventoy_cmd_unix_gzip_newko %p\n", g_mod_new_data);
if (!g_mod_new_data)
{
goto end;
}
buf = grub_malloc(g_mod_new_len);
if (!buf)
{
goto end;
}
newlen = ventoy_gzip_compress(g_mod_new_data, g_mod_new_len, buf, g_mod_new_len);
grub_free(g_mod_new_data);
debug("gzip org len:%d newlen:%d\n", g_mod_new_len, newlen);
g_mod_new_data = (char *)buf;
g_mod_new_len = newlen;
end:
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
grub_err_t ventoy_cmd_unix_chain_data(grub_extcmd_context_t ctxt, int argc, char **args)
{
int ventoy_compatible = 0;

View File

@ -342,8 +342,10 @@ static int ventoy_raw_trim_head(grub_uint64_t offset)
grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
int altboot = 0;
int offset = -1;
grub_file_t file;
grub_uint8_t data = 0;
vhd_footer_t vhdfoot;
VDIPREHEADER vdihdr;
char type[16] = {0};
@ -427,6 +429,7 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char *
if (grub_memcmp(gpt->PartTbl[i].PartType, "Hah!IdontNeedEFI", 16) == 0)
{
debug("part %d is grub_bios part\n", i);
altboot = 1;
grub_env_set(args[3], "1");
break;
}
@ -436,6 +439,20 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char *
}
}
}
if (!altboot)
{
if (gpt->MBR.BootCode[92] == 0x22)
{
grub_file_seek(file, offset + 17908);
grub_file_read(file, &data, 1);
if (data == 0x23)
{
altboot = 1;
grub_env_set(args[3], "1");
}
}
}
}
else
{
@ -447,6 +464,7 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char *
if (gpt->MBR.PartTbl[i].FsFlag == 0xEF)
{
debug("part %d is esp part in MBR mode\n", i);
altboot = 1;
grub_env_set(args[3], "1");
break;
}

View File

@ -149,8 +149,6 @@ typedef struct ventoy_secure_data
grub_uint8_t magic2[16]; /* VENTOY_GUID */
}ventoy_secure_data;
#pragma pack()
// compile assert check : sizeof(ventoy_os_param) must be 512
@ -188,6 +186,18 @@ typedef struct ventoy_chain_head
grub_uint32_t virt_chunk_num;
}ventoy_chain_head;
typedef struct ventoy_image_desc
{
grub_uint64_t disk_size;
grub_uint64_t part1_size;
grub_uint8_t disk_uuid[16];
grub_uint8_t disk_signature[4];
grub_uint32_t img_chunk_count;
/* ventoy_img_chunk list */
}ventoy_image_desc;
typedef struct ventoy_img_chunk
{
grub_uint32_t img_start_sector; // sector size: 2KB

View File

@ -19,7 +19,13 @@
. $VTOY_PATH/hook/ventoy-os-lib.sh
$SED "/mount.*devtmpfs/a $BUSYBOX_PATH/sh $VTOY_PATH/hook/wifislax/disk_hook.sh" -i /linuxrc
if [ -e /linuxrc ]; then
INITFILE=/linuxrc
elif [ -e /init ]; then
INITFILE=/init
fi
$SED "/mount.*devtmpfs/a $BUSYBOX_PATH/sh $VTOY_PATH/hook/wifislax/disk_hook.sh" -i $INITFILE
#replace original blkid
$BUSYBOX_PATH/rm -f /usr/bin/blkid

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,7 @@
#!/bin/sh
OLDDIR=$(pwd)
if ! [ -f ./tool/ventoy_lib.sh ]; then
if [ -f ${0%Ventoy2Disk.sh}/tool/ventoy_lib.sh ]; then
cd ${0%Ventoy2Disk.sh}
@ -10,8 +12,6 @@ if [ -f ./ventoy/version ]; then
curver=$(cat ./ventoy/version)
fi
OLDDIR=$(pwd)
if uname -a | egrep -q 'aarch64|arm64'; then
export TOOLDIR=aarch64
elif uname -a | egrep -q 'x86_64|amd64'; then
@ -53,9 +53,10 @@ else
for file in $(ls *.xz); do
xzcat $file > ${file%.xz}
[ -f ./${file%.xz} ] && chmod +x ./${file%.xz}
[ -f ./$file ] && rm -f ./$file
done
cd $OLDDIR
cd ../../
chmod +x -R ./tool/$TOOLDIR
fi
@ -67,7 +68,8 @@ else
fi
if [ -n "$OLDDIR" ]; then
cd $OLDDIR
CURDIR=$(pwd)
if [ "$CURDIR" != "$OLDDIR" ]; then
cd "$OLDDIR"
fi
fi

View File

@ -92,7 +92,7 @@ terminal:
div:
crypto:
part_bsd: part_msdos
ventoy: ext2 fshelp font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
ventoy: ext2 fshelp btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
gcry_sha512: crypto
password: crypto normal
fshelp:

View File

@ -92,6 +92,9 @@ function get_os_type {
elif [ -e (loop)/bin/freebsd-version ]; then
set vtoy_os=Unix
set vt_unix_type=FreeBSD
elif vt_str_begin "$vt_system_id" "DragonFly"; then
set vtoy_os=Unix
set vt_unix_type=DragonFly
elif [ -e (loop)/boot/kernel/kernel ]; then
@ -426,6 +429,22 @@ function ventoy_freebsd_proc {
vt_unix_replace_conf FreeBSD "${1}${chosen_path}"
}
function ventoy_dragonfly_proc {
unset vt_unix_mod_path
for file in "/boot/kernel/initrd.img.gz"; do
if [ -e (loop)${file} ]; then
set vt_unix_mod_path=${file}
break
fi
done
vt_unix_replace_ko $vt_unix_mod_path ${vtoy_path}/dragonfly.mfs.xz
vt_unix_fill_image_desc
vt_unix_gzip_new_ko
vt_unix_replace_conf DragonFly "${1}${chosen_path}"
}
function ventoy_unix_comm_proc {
vt_unix_reset
@ -434,11 +453,12 @@ function ventoy_unix_comm_proc {
if [ "$vt_unix_type" = "FreeBSD" ]; then
ventoy_freebsd_proc "$1" "${chosen_path}"
elif [ "$vt_unix_type" = "DragonFly" ]; then
ventoy_dragonfly_proc "$1" "${chosen_path}"
elif [ "$vt_unix_type" = "NetBSD" ]; then
echo "NetBSD not supported"
else
if [ -n "${vtdebug_flag}" ]; then
echo "Unknown unix type"

View File

@ -119,7 +119,7 @@ ehci: cs5536 usb boot
crypto:
part_bsd: part_msdos
cs5536:
ventoy: ext2 fshelp font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
ventoy: ext2 fshelp btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
gcry_sha512: crypto
password: crypto normal
fshelp:

Binary file not shown.

View File

@ -122,7 +122,7 @@ crypto:
part_bsd: part_msdos
cs5536: pci
biosdisk:
ventoy: ext2 fshelp font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660 acpi
ventoy: ext2 fshelp btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660 acpi
lsapm:
gcry_sha512: crypto
password: crypto normal

View File

@ -119,7 +119,7 @@ ehci: cs5536 usb boot
crypto:
part_bsd: part_msdos
cs5536:
ventoy: ext2 fshelp font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
ventoy: ext2 fshelp btrfs font crypto gcry_md5 exfat udf extcmd normal video gcry_sha1 iso9660
gcry_sha512: crypto
password: crypto normal
fshelp:

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,13 @@
https://github.com/wkoszek/mini_gzip
Ventoy modify its source code, these code modified by Ventoy follow the same license as mini_gzip.
=====================================License=================================================
Copyright (c) 2015, Wojciech Adam Koszek wojciech@koszek.com All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -16,7 +16,7 @@ You can copy many image files at a time and ventoy will give you a boot menu to
x86 Legacy BIOS, IA32 UEFI, x86_64 UEFI and ARM64 UEFI are supported in the same way.<br/>
Both MBR and GPT partition style are supported in the same way.<br/>
Most type of OS supported(Windows/WinPE/Linux/Unix/Vmware/Xen...) <br/>
580+ ISO files are tested. 90%+ distros in distrowatch.com supported. <br/>
600+ ISO files are tested. 90%+ distros in distrowatch.com supported. <br/>
</h4>
# Features
@ -34,7 +34,7 @@ Most type of OS supported(Windows/WinPE/Linux/Unix/Vmware/Xen...) <br/>
* FAT32/exFAT/NTFS/UDF/XFS/Ext2(3)(4) supported for main partition
* ISO files larger than 4GB supported
* Native boot menu style for Legacy & UEFI
* Most type of OS supported, 580+ iso files tested
* Most type of OS supported, 600+ iso files tested
* Linux vDisk boot supported
* Not only boot but also complete installation process
* Menu dynamically switchable between List/TreeView mode

View File

@ -484,8 +484,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 || param->vtoy_disk_size == size + 512) &&
memcmp(vtguid, param->vtoy_disk_guid, 16) == 0 &&
if (memcmp(vtguid, param->vtoy_disk_guid, 16) == 0 &&
memcmp(vtsig, param->vtoy_disk_signature, 4) == 0)
{
debug("<%s> is right ventoy disk\n", device);
@ -563,8 +562,20 @@ int vtoydump_main(int argc, char **argv)
rc = vtoy_os_param_from_file(filename, param);
if (rc)
{
debug("ventoy os param not found %d\n", rc);
goto end;
debug("ventoy os param not found %d %d\n", rc, ENOENT);
if (ENOENT == rc)
{
debug("now try with file %s\n", "/ventoy/ventoy_os_param");
rc = vtoy_os_param_from_file("/ventoy/ventoy_os_param", param);
if (rc)
{
goto end;
}
}
else
{
goto end;
}
}
if (verbose)

Binary file not shown.

Binary file not shown.

Binary file not shown.