Compare commits

...

10 Commits

Author SHA1 Message Date
longpanda
9eb334d99a 1.0.21 release 2020-09-12 22:31:21 +08:00
longpanda
260a3269b7 Merge branch 'master' of https://github.com/ventoy/Ventoy
# Conflicts:
#	INSTALL/ventoy/ventoy.cpio
2020-09-12 02:49:39 +08:00
longpanda
a287bf8907 vhd boot
live cd
fix bug
2020-09-12 02:46:44 +08:00
longpanda
48a1b80be0 update 2020-09-03 16:45:18 +08:00
longpanda
b9ef72fbe9 Fix issue #456 2020-09-03 16:43:21 +08:00
longpanda
390507fff7 Fix issue #456 2020-09-03 16:40:26 +08:00
longpanda
a29bdfbc3c LiveCD 2020-09-03 07:46:36 +08:00
longpanda
21735f92d6 Merge branch 'master' of https://github.com/ventoy/Ventoy 2020-09-02 19:29:43 +08:00
longpanda
9a8d4d0227 update 2020-09-02 19:29:19 +08:00
longpanda
6ebe77792c Update README.md 2020-08-30 21:59:09 +08:00
79 changed files with 1795 additions and 60 deletions

View File

@@ -378,6 +378,36 @@ EFI_STATUS EFIAPI ventoy_delete_variable(VOID)
return Status;
}
#if (VENTOY_DEVICE_WARN != 0)
STATIC VOID ventoy_warn_invalid_device(VOID)
{
STATIC BOOLEAN flag = FALSE;
if (flag)
{
return;
}
flag = TRUE;
gST->ConOut->ClearScreen(gST->ConOut);
gST->ConOut->OutputString(gST->ConOut, VTOY_WARNING L"\r\n");
gST->ConOut->OutputString(gST->ConOut, VTOY_WARNING L"\r\n");
gST->ConOut->OutputString(gST->ConOut, VTOY_WARNING L"\r\n\r\n\r\n");
gST->ConOut->OutputString(gST->ConOut, L"This is NOT a standard Ventoy device and is NOT officially supported.\r\n\r\n");
gST->ConOut->OutputString(gST->ConOut, L"You should follow the official instructions in https://www.ventoy.net\r\n");
gST->ConOut->OutputString(gST->ConOut, L"\r\n\r\nWill continue to boot after 15 seconds ...... ");
sleep(15);
}
#else
STATIC VOID ventoy_warn_invalid_device(VOID)
{
}
#endif
STATIC EFI_STATUS EFIAPI ventoy_load_image
(
IN EFI_HANDLE ImageHandle,
@@ -420,6 +450,7 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk(IN EFI_HANDLE ImageHandle)
UINTN i = 0;
UINTN Count = 0;
UINT64 DiskSize = 0;
MBR_HEAD *pMBR = NULL;
UINT8 *pBuffer = NULL;
EFI_HANDLE *Handles;
EFI_STATUS Status = EFI_SUCCESS;
@@ -463,6 +494,18 @@ STATIC EFI_STATUS EFIAPI ventoy_find_iso_disk(IN EFI_HANDLE ImageHandle)
if (CompareMem(g_chain->os_param.vtoy_disk_guid, pBuffer + 0x180, 16) == 0)
{
pMBR = (MBR_HEAD *)pBuffer;
if (pMBR->PartTbl[0].FsFlag != 0xEE)
{
if (pMBR->PartTbl[0].StartSectorId != 2048 ||
pMBR->PartTbl[1].SectorCount != 65536 ||
pMBR->PartTbl[1].StartSectorId != pMBR->PartTbl[0].StartSectorId + pMBR->PartTbl[0].SectorCount)
{
debug("Failed to check disk part table");
ventoy_warn_invalid_device();
}
}
gBlockData.RawBlockIoHandle = Handles[i];
gBlockData.pRawBlockIo = pBlockIo;
gBS->OpenProtocol(Handles[i], &gEfiDevicePathProtocolGuid,
@@ -582,6 +625,7 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
UINT32 old_cnt = 0;
UINTN size = 0;
UINT8 chksum = 0;
const char *pEnv = NULL;
CHAR16 *pPos = NULL;
CHAR16 *pCmdLine = NULL;
EFI_STATUS Status = EFI_SUCCESS;
@@ -649,9 +693,19 @@ STATIC EFI_STATUS EFIAPI ventoy_parse_cmdline(IN EFI_HANDLE ImageHandle)
}
pGrubParam = (ventoy_grub_param *)StrHexToUintn(pPos + StrLen(L"env_param="));
grub_env_get = pGrubParam->grub_env_get;
grub_env_set = pGrubParam->grub_env_set;
grub_env_get = pGrubParam->grub_env_get;
pEnv = grub_env_get("VTOY_CHKDEV_RESULT_STRING");
if (!pEnv)
{
return EFI_INVALID_PARAMETER;
}
if (pEnv[0] != '0' || pEnv[1] != 0)
{
ventoy_warn_invalid_device();
}
g_file_replace_list = &pGrubParam->file_replace;
old_cnt = g_file_replace_list->old_file_cnt;
debug("file replace: magic:0x%x virtid:%u name count:%u <%a> <%a> <%a> <%a>",
@@ -963,7 +1017,11 @@ EFI_STATUS EFIAPI VentoyEfiMain
gST->ConOut->ClearScreen(gST->ConOut);
ventoy_clear_input();
ventoy_parse_cmdline(ImageHandle);
Status = ventoy_parse_cmdline(ImageHandle);
if (EFI_ERROR(Status))
{
return Status;
}
if (gMemdiskMode)
{
@@ -1000,22 +1058,24 @@ EFI_STATUS EFIAPI VentoyEfiMain
else
{
ventoy_save_variable();
ventoy_find_iso_disk(ImageHandle);
if (gLoadIsoEfi)
Status = ventoy_find_iso_disk(ImageHandle);
if (!EFI_ERROR(Status))
{
ventoy_find_iso_disk_fs(ImageHandle);
ventoy_load_isoefi_driver(ImageHandle);
if (gLoadIsoEfi)
{
ventoy_find_iso_disk_fs(ImageHandle);
ventoy_load_isoefi_driver(ImageHandle);
}
ventoy_debug_pause();
ventoy_install_blockio(ImageHandle, g_chain->virt_img_size_in_bytes);
ventoy_debug_pause();
Status = ventoy_boot(ImageHandle);
}
ventoy_debug_pause();
ventoy_install_blockio(ImageHandle, g_chain->virt_img_size_in_bytes);
ventoy_debug_pause();
Status = ventoy_boot(ImageHandle);
ventoy_clean_env();
}

View File

@@ -185,6 +185,9 @@ typedef struct ventoy_virt_chunk
#error Unknown Processor Type
#endif
#define VENTOY_DEVICE_WARN 0
#define VTOY_WARNING L"!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"
typedef struct ventoy_sector_flag
{
UINT8 flag; // 0:init 1:mem 2:remap
@@ -275,6 +278,32 @@ typedef struct ventoy_iso9660_override
UINT32 size_be;
}ventoy_iso9660_override;
typedef struct PART_TABLE
{
UINT8 Active; // 0x00 0x80
UINT8 StartHead;
UINT16 StartSector : 6;
UINT16 StartCylinder : 10;
UINT8 FsFlag;
UINT8 EndHead;
UINT16 EndSector : 6;
UINT16 EndCylinder : 10;
UINT32 StartSectorId;
UINT32 SectorCount;
}PART_TABLE;
typedef struct MBR_HEAD
{
UINT8 BootCode[446];
PART_TABLE PartTbl[4];
UINT8 Byte55;
UINT8 ByteAA;
}MBR_HEAD;
#pragma pack()

View File

@@ -1591,6 +1591,7 @@ module = {
common = ventoy/ventoy_linux.c;
common = ventoy/ventoy_unix.c;
common = ventoy/ventoy_windows.c;
common = ventoy/ventoy_vhd.c;
common = ventoy/ventoy_plugin.c;
common = ventoy/ventoy_json.c;
common = ventoy/lzx.c;

View File

@@ -999,6 +999,9 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
grub_menu_execute_entry (e, 0);
if (autobooted)
break;
if (2 == e->argc && e->args && e->args[1] && grub_strncmp(e->args[1], "VTOY_RUN_RET", 12) == 0)
break;
}
return GRUB_ERR_NONE;

View File

@@ -39,7 +39,9 @@
#include <grub/efi/efi.h>
#endif
#include <grub/time.h>
#include <grub/video.h>
#include <grub/relocator.h>
#include <grub/charset.h>
#include <grub/ventoy.h>
#include "ventoy_def.h"
@@ -87,6 +89,10 @@ int g_wimboot_enable = 0;
ventoy_img_chunk_list g_wimiso_chunk_list;
char *g_wimiso_path = NULL;
int g_vhdboot_enable = 0;
ventoy_gpt_info *g_ventoy_part_info = NULL;
static char *g_tree_script_buf = NULL;
static int g_tree_script_pos = 0;
@@ -96,14 +102,18 @@ static int g_list_script_pos = 0;
static char *g_part_list_buf = NULL;
static int g_part_list_pos = 0;
static int g_video_mode_max = 0;
static int g_video_mode_num = 0;
static ventoy_video_mode *g_video_mode_list = NULL;
static const char *g_menu_class[] =
{
"vtoyiso", "vtoywim", "vtoyefi", "vtoyimg"
"vtoyiso", "vtoywim", "vtoyefi", "vtoyimg", "vtoyvhd"
};
static const char *g_menu_prefix[] =
{
"iso", "wim", "efi", "img"
"iso", "wim", "efi", "img", "vhd"
};
void ventoy_debug(const char *fmt, ...)
@@ -115,6 +125,23 @@ void ventoy_debug(const char *fmt, ...)
va_end (args);
}
void ventoy_debug_dump_guid(const char *prefix, grub_uint8_t *guid)
{
int i;
if (!g_ventoy_debug)
{
return;
}
debug("%s", prefix);
for (i = 0; i < 16; i++)
{
grub_printf("%02x ", guid[i]);
}
grub_printf("\n");
}
int ventoy_is_efi_os(void)
{
if (g_efi_os > 1)
@@ -195,6 +222,120 @@ static grub_err_t ventoy_fs_close(grub_file_t file)
return 0;
}
static int ventoy_video_hook(const struct grub_video_mode_info *info, void *hook_arg)
{
int i;
(void)hook_arg;
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT)
{
return 0;
}
for (i = 0; i < g_video_mode_num; i++)
{
if (g_video_mode_list[i].width == info->width &&
g_video_mode_list[i].height == info->height &&
g_video_mode_list[i].bpp == info->bpp)
{
return 0;
}
}
g_video_mode_list[g_video_mode_num].width = info->width;
g_video_mode_list[g_video_mode_num].height = info->height;
g_video_mode_list[g_video_mode_num].bpp = info->bpp;
g_video_mode_num++;
if (g_video_mode_num == g_video_mode_max)
{
g_video_mode_max *= 2;
g_video_mode_list = grub_realloc(g_video_mode_list, g_video_mode_max * sizeof(ventoy_video_mode));
}
return 0;
}
static int ventoy_video_mode_cmp(ventoy_video_mode *v1, ventoy_video_mode *v2)
{
if (v1->bpp == v2->bpp)
{
if (v1->width == v2->width)
{
if (v1->height == v2->height)
{
return 0;
}
else
{
return (v1->height < v2->height) ? -1 : 1;
}
}
else
{
return (v1->width < v2->width) ? -1 : 1;
}
}
else
{
return (v1->bpp < v2->bpp) ? -1 : 1;
}
}
static int ventoy_enum_video_mode(void)
{
int i, j;
grub_video_adapter_t adapter;
grub_video_driver_id_t id;
ventoy_video_mode mode;
g_video_mode_num = 0;
g_video_mode_max = 1024;
g_video_mode_list = grub_malloc(sizeof(ventoy_video_mode) * g_video_mode_max);
if (!g_video_mode_list)
{
return 0;
}
#ifdef GRUB_MACHINE_PCBIOS
grub_dl_load ("vbe");
#endif
id = grub_video_get_driver_id ();
FOR_VIDEO_ADAPTERS (adapter)
{
if (!adapter->iterate ||
(adapter->id != id && (id != GRUB_VIDEO_DRIVER_NONE ||
adapter->init() != GRUB_ERR_NONE)))
{
continue;
}
adapter->iterate(ventoy_video_hook, NULL);
if (adapter->id != id)
{
adapter->fini();
}
}
/* sort video mode */
for (i = 0; i < g_video_mode_num; i++)
for (j = i + 1; j < g_video_mode_num; j++)
{
if (ventoy_video_mode_cmp(g_video_mode_list + i, g_video_mode_list + j) < 0)
{
grub_memcpy(&mode, g_video_mode_list + i, sizeof(ventoy_video_mode));
grub_memcpy(g_video_mode_list + i, g_video_mode_list + j, sizeof(ventoy_video_mode));
grub_memcpy(g_video_mode_list + j, &mode, sizeof(ventoy_video_mode));
}
}
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static grub_file_t ventoy_wrapper_open(grub_file_t rawFile, enum grub_file_type type)
{
int len;
@@ -1031,6 +1172,11 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
{
type = img_type_wim;
}
else if (g_vhdboot_enable && (0 == grub_strcasecmp(filename + len - 4, ".vhd") ||
0 == grub_strcasecmp(filename + len - 5, ".vhdx")))
{
type = img_type_vhd;
}
#ifdef GRUB_MACHINE_EFI
else if (0 == grub_strcasecmp(filename + len - 4, ".efi"))
{
@@ -1039,9 +1185,13 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
#endif
else if (0 == grub_strcasecmp(filename + len - 4, ".img"))
{
if (len == 18 && grub_strncmp(filename, "ventoy_wimboot", 14) == 0)
if (len == 18 && grub_strncmp(filename, "ventoy_", 7) == 0)
{
return 0;
if (grub_strncmp(filename + 7, "wimboot", 7) == 0 ||
grub_strncmp(filename + 7, "vhdboot", 7) == 0)
{
return 0;
}
}
type = img_type_img;
}
@@ -1122,6 +1272,14 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
}
img->menu_prefix = g_menu_prefix[type];
if (img_type_iso == type)
{
if (ventoy_plugin_check_memdisk(img->path))
{
img->menu_prefix = "miso";
}
}
debug("Add %s%s to list %d\n", node->dir, filename, g_ventoy_img_count);
}
}
@@ -1333,6 +1491,93 @@ static int ventoy_dynamic_tree_menu(img_iterator_node *node)
return 0;
}
int ventoy_check_device_result(int ret)
{
char buf[32];
grub_snprintf(buf, sizeof(buf), "%d", ret);
ventoy_set_env("VTOY_CHKDEV_RESULT_STRING", buf);
if (ret)
{
grub_printf(VTOY_WARNING"\n");
grub_printf(VTOY_WARNING"\n");
grub_printf(VTOY_WARNING"\n\n\n");
grub_printf("This is NOT a standard Ventoy device and is NOT officially supported.\n\n");
grub_printf("Recommend to follow the instructions in https://www.ventoy.net to use Ventoy.\n");
grub_printf("\n\nWill continue to boot after 10 seconds ...... ");
grub_refresh();
grub_sleep(10);
}
return ret;
}
int ventoy_check_device(grub_device_t dev)
{
grub_file_t file;
grub_uint64_t offset;
char devname[64];
grub_fs_t fs;
grub_device_t dev2;
char *label = NULL;
struct grub_partition *partition;
if (dev->disk == NULL || dev->disk->partition == NULL)
{
return ventoy_check_device_result(1);
}
partition = dev->disk->partition;
if (partition->number != 0 || partition->start != 2048)
{
return ventoy_check_device_result(2);
}
offset = partition->start + partition->len;
/* We must have partition 2 */
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "(%s,2)/ventoy/ventoy.cpio", dev->disk->name);
if (!file)
{
return ventoy_check_device_result(3);
}
partition = file->device->disk->partition;
if ((partition->number != 1) || (partition->len != 65536) || (offset != partition->start))
{
grub_file_close(file);
return ventoy_check_device_result(4);
}
grub_file_close(file);
grub_snprintf(devname, sizeof(devname), "%s,2", dev->disk->name);
dev2 = grub_device_open(devname);
if (!dev2)
{
return ventoy_check_device_result(5);
}
fs = grub_fs_probe(dev2);
if (!fs)
{
grub_device_close(dev2);
return ventoy_check_device_result(6);
}
fs->fs_label(dev2, &label);
if ((!label) || grub_strncmp("VTOYEFI", label, 7))
{
grub_device_close(dev2);
return ventoy_check_device_result(7);
}
grub_device_close(dev2);
return ventoy_check_device_result(0);
}
static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char **args)
{
int len;
@@ -1379,6 +1624,9 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
goto fail;
}
/* make sure that we are running in a correct Ventoy device */
ventoy_check_device(dev);
g_enum_fs = fs = grub_fs_probe(dev);
if (!fs)
{
@@ -1392,6 +1640,8 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
goto fail;
}
ventoy_set_env("vtoy_iso_fs", fs->name);
strdata = ventoy_get_env("VTOY_DEFAULT_MENU_MODE");
if (strdata && strdata[0] == '1')
{
@@ -2829,6 +3079,67 @@ end:
return rc;
}
static grub_err_t ventoy_cmd_load_part_table(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_disk_t disk;
(void)argc;
(void)ctxt;
g_ventoy_part_info = grub_zalloc(sizeof(ventoy_gpt_info));
if (!g_ventoy_part_info)
{
return 1;
}
disk = grub_disk_open(args[0]);
if (!disk)
{
debug("Failed to open disk %s\n", args[0]);
return 1;
}
grub_disk_read(disk, 0, 0, sizeof(ventoy_gpt_info), g_ventoy_part_info);
grub_disk_close(disk);
return 0;
}
static grub_err_t ventoy_cmd_part_exist(grub_extcmd_context_t ctxt, int argc, char **args)
{
int id;
grub_uint8_t zeroguid[16] = {0};
(void)argc;
(void)ctxt;
id = (int)grub_strtoul(args[0], NULL, 10);
grub_errno = 0;
if (grub_memcmp(g_ventoy_part_info->Head.Signature, "EFI PART", 8) == 0)
{
if (id >= 1 && id <= 128)
{
if (grub_memcmp(g_ventoy_part_info->PartTbl[id - 1].PartGuid, zeroguid, 16))
{
return 0;
}
}
}
else
{
if (id >= 1 && id <= 4)
{
if (g_ventoy_part_info->MBR.PartTbl[id - 1].FsFlag)
{
return 0;
}
}
}
return 1;
}
static grub_err_t ventoy_cmd_get_fs_label(grub_extcmd_context_t ctxt, int argc, char **args)
{
int rc = 1;
@@ -2986,6 +3297,85 @@ static grub_err_t ventoy_cmd_basename(grub_extcmd_context_t ctxt, int argc, char
return 0;
}
static grub_err_t ventoy_cmd_enum_video_mode(grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_video_mode_info info;
char buf[32];
(void)ctxt;
(void)argc;
(void)args;
if (!g_video_mode_list)
{
ventoy_enum_video_mode();
}
if (grub_video_get_info(&info) == GRUB_ERR_NONE)
{
grub_snprintf(buf, sizeof(buf), "Resolution (%ux%u)", info.width, info.height);
}
else
{
grub_snprintf(buf, sizeof(buf), "Resolution (0x0)");
}
grub_env_set("VTOY_CUR_VIDEO_MODE", buf);
grub_snprintf(buf, sizeof(buf), "%d", g_video_mode_num);
grub_env_set("VTOY_VIDEO_MODE_NUM", buf);
VENTOY_CMD_RETURN(0);
}
static grub_err_t vt_cmd_update_cur_video_mode(grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_video_mode_info info;
char buf[32];
(void)ctxt;
(void)argc;
(void)args;
if (grub_video_get_info(&info) == GRUB_ERR_NONE)
{
grub_snprintf(buf, sizeof(buf), "%ux%ux%u", info.width, info.height, info.bpp);
}
else
{
grub_snprintf(buf, sizeof(buf), "0x0x0");
}
grub_env_set(args[0], buf);
VENTOY_CMD_RETURN(0);
}
static grub_err_t ventoy_cmd_get_video_mode(grub_extcmd_context_t ctxt, int argc, char **args)
{
int id;
char buf[32];
(void)ctxt;
(void)argc;
if (!g_video_mode_list)
{
return 0;
}
id = (int)grub_strtoul(args[0], NULL, 10);
if (id < g_video_mode_num)
{
grub_snprintf(buf, sizeof(buf), "%ux%ux%u",
g_video_mode_list[id].width, g_video_mode_list[id].height, g_video_mode_list[id].bpp);
}
grub_env_set(args[1], buf);
VENTOY_CMD_RETURN(0);
}
grub_uint64_t ventoy_grub_get_file_size(const char *fmt, ...)
{
grub_uint64_t size = 0;
@@ -3125,6 +3515,8 @@ static cmd_para ventoy_cmds[] =
{ "vt_img_sector", ventoy_cmd_img_sector, 0, NULL, "{imageName}", "", NULL },
{ "vt_dump_img_sector", ventoy_cmd_dump_img_sector, 0, NULL, "", "", NULL },
{ "vt_load_wimboot", ventoy_cmd_load_wimboot, 0, NULL, "", "", NULL },
{ "vt_load_vhdboot", ventoy_cmd_load_vhdboot, 0, NULL, "", "", NULL },
{ "vt_patch_vhdboot", ventoy_cmd_patch_vhdboot, 0, NULL, "", "", NULL },
{ "vt_cpio_busybox64", ventoy_cmd_cpio_busybox_64, 0, NULL, "", "", NULL },
{ "vt_load_cpio", ventoy_cmd_load_cpio, 0, NULL, "", "", NULL },
@@ -3133,10 +3525,14 @@ static cmd_para ventoy_cmds[] =
{ "vt_pop_last_entry", ventoy_cmd_pop_last_entry, 0, NULL, "", "", NULL },
{ "vt_get_lib_module_ver", ventoy_cmd_lib_module_ver, 0, NULL, "", "", NULL },
{ "vt_load_part_table", ventoy_cmd_load_part_table, 0, NULL, "", "", NULL },
{ "vt_check_part_exist", ventoy_cmd_part_exist, 0, NULL, "", "", NULL },
{ "vt_get_fs_label", ventoy_cmd_get_fs_label, 0, NULL, "", "", NULL },
{ "vt_fs_enum_1st_file", ventoy_cmd_fs_enum_1st_file, 0, NULL, "", "", NULL },
{ "vt_file_basename", ventoy_cmd_basename, 0, NULL, "", "", NULL },
{ "vt_file_basename", ventoy_cmd_basename, 0, NULL, "", "", NULL },
{ "vt_enum_video_mode", ventoy_cmd_enum_video_mode, 0, NULL, "", "", NULL },
{ "vt_get_video_mode", ventoy_cmd_get_video_mode, 0, NULL, "", "", NULL },
{ "vt_update_cur_video_mode", vt_cmd_update_cur_video_mode, 0, NULL, "", "", NULL },
{ "vt_find_first_bootable_hd", ventoy_cmd_find_bootable_hdd, 0, NULL, "", "", NULL },

View File

@@ -29,6 +29,7 @@
#define VTOY_SIZE_1GB 1073741824
#define VTOY_SIZE_512KB (512 * 1024)
#define VTOY_SIZE_1KB 1024
#define JSON_SUCCESS 0
#define JSON_FAILED 1
@@ -48,6 +49,8 @@
#define ventoy_get_env(key) ventoy_env_op1(get, key)
#define ventoy_set_env(key, val) ventoy_env_op2(set, key, val)
#define VTOY_WARNING "!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!"
typedef struct ventoy_initrd_ctx
{
const char *path_prefix;
@@ -99,6 +102,18 @@ typedef int (*grub_char_check_func)(int c);
#define ventoy_is_decimal(str) ventoy_string_check(str, grub_isdigit)
#pragma pack(1)
typedef struct ventoy_patch_vhd
{
grub_uint8_t part_offset_or_guid[16];
grub_uint32_t reserved1;
grub_uint32_t part_type;
grub_uint8_t disk_signature_or_guid[16];
grub_uint8_t reserved2[16];
grub_uint8_t vhd_file_path[1];
}ventoy_patch_vhd;
#pragma pack()
// El Torito Boot Record Volume Descriptor
#pragma pack(1)
typedef struct eltorito_descriptor
@@ -141,6 +156,7 @@ typedef struct ventoy_iso9660_vd
#define img_type_wim 1
#define img_type_efi 2
#define img_type_img 3
#define img_type_vhd 4
typedef struct img_info
{
@@ -604,8 +620,53 @@ typedef struct ventoy_mbr_head
grub_uint8_t Byte55;
grub_uint8_t ByteAA;
}ventoy_mbr_head;
typedef struct ventoy_gpt_head
{
char Signature[8]; /* EFI PART */
grub_uint8_t Version[4];
grub_uint32_t Length;
grub_uint32_t Crc;
grub_uint8_t Reserved1[4];
grub_uint64_t EfiStartLBA;
grub_uint64_t EfiBackupLBA;
grub_uint64_t PartAreaStartLBA;
grub_uint64_t PartAreaEndLBA;
grub_uint8_t DiskGuid[16];
grub_uint64_t PartTblStartLBA;
grub_uint32_t PartTblTotNum;
grub_uint32_t PartTblEntryLen;
grub_uint32_t PartTblCrc;
grub_uint8_t Reserved2[420];
}ventoy_gpt_head;
typedef struct ventoy_gpt_part_tbl
{
grub_uint8_t PartType[16];
grub_uint8_t PartGuid[16];
grub_uint64_t StartLBA;
grub_uint64_t LastLBA;
grub_uint64_t Attr;
grub_uint16_t Name[36];
}ventoy_gpt_part_tbl;
typedef struct ventoy_gpt_info
{
ventoy_mbr_head MBR;
ventoy_gpt_head Head;
ventoy_gpt_part_tbl PartTbl[128];
}ventoy_gpt_info;
#pragma pack()
typedef struct ventoy_video_mode
{
grub_uint32_t width;
grub_uint32_t height;
grub_uint32_t bpp;
}ventoy_video_mode;
typedef struct file_fullpath
{
char path[256];
@@ -672,6 +733,14 @@ typedef struct injection_config
struct injection_config *next;
}injection_config;
typedef struct auto_memdisk
{
int pathlen;
char isopath[256];
struct auto_memdisk *next;
}auto_memdisk;
extern int g_ventoy_menu_esc;
extern int g_ventoy_suppress_esc;
extern int g_ventoy_last_entry;
@@ -680,6 +749,8 @@ extern int g_ventoy_iso_raw;
extern int g_ventoy_iso_uefi_drv;
extern int g_ventoy_case_insensitive;
extern grub_uint8_t g_ventoy_chain_type;
extern int g_vhdboot_enable;
extern ventoy_gpt_info *g_ventoy_part_info;
#define ventoy_unix_fill_virt(new_data, new_len) \
@@ -711,6 +782,7 @@ int ventoy_plugin_get_persistent_chunklist(const char *isopath, int index, vento
const char * ventoy_plugin_get_injection(const char *isopath);
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath);
const char * ventoy_plugin_get_menu_class(int type, const char *name);
int ventoy_plugin_check_memdisk(const char *isopath);
int ventoy_get_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist, grub_disk_addr_t start);
void ventoy_plugin_dump_persistence(void);
@@ -726,6 +798,11 @@ grub_err_t ventoy_cmd_unix_replace_conf(grub_extcmd_context_t ctxt, int argc, ch
grub_err_t ventoy_cmd_unix_replace_ko(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);
int ventoy_check_device(grub_device_t dev);
void ventoy_debug_dump_guid(const char *prefix, grub_uint8_t *guid);
grub_err_t ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args);
#endif /* __VENTOY_DEF_H__ */

View File

@@ -45,6 +45,7 @@ static persistence_config *g_persistence_head = NULL;
static menu_alias *g_menu_alias_head = NULL;
static menu_class *g_menu_class_head = NULL;
static injection_config *g_injection_head = NULL;
static auto_memdisk *g_auto_memdisk_head = NULL;
static int ventoy_plugin_control_check(VTOY_JSON *json, const char *isodisk)
{
@@ -1010,6 +1011,83 @@ static int ventoy_plugin_menuclass_check(VTOY_JSON *json, const char *isodisk)
return 0;
}
static int ventoy_plugin_auto_memdisk_entry(VTOY_JSON *json, const char *isodisk)
{
VTOY_JSON *pNode = NULL;
auto_memdisk *node = NULL;
auto_memdisk *next = NULL;
(void)isodisk;
if (json->enDataType != JSON_TYPE_ARRAY)
{
debug("Not array %d\n", json->enDataType);
return 0;
}
if (g_auto_memdisk_head)
{
for (node = g_auto_memdisk_head; node; node = next)
{
next = node->next;
grub_free(node);
}
g_auto_memdisk_head = NULL;
}
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
{
if (pNode->enDataType == JSON_TYPE_STRING)
{
node = grub_zalloc(sizeof(auto_memdisk));
if (node)
{
node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", pNode->unData.pcStrVal);
if (g_auto_memdisk_head)
{
node->next = g_auto_memdisk_head;
}
g_auto_memdisk_head = node;
}
}
}
return 0;
}
static int ventoy_plugin_auto_memdisk_check(VTOY_JSON *json, const char *isodisk)
{
VTOY_JSON *pNode = NULL;
if (json->enDataType != JSON_TYPE_ARRAY)
{
grub_printf("Not array %d\n", json->enDataType);
return 1;
}
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
{
if (pNode->enDataType == JSON_TYPE_STRING)
{
grub_printf("<%s> ", pNode->unData.pcStrVal);
if (ventoy_check_file_exist("%s%s", isodisk, pNode->unData.pcStrVal))
{
grub_printf(" [OK]\n");
}
else
{
grub_printf(" [NOT EXIST]\n");
}
}
}
return 0;
}
static plugin_entry g_plugin_entries[] =
{
{ "control", ventoy_plugin_control_entry, ventoy_plugin_control_check },
@@ -1019,6 +1097,7 @@ static plugin_entry g_plugin_entries[] =
{ "menu_alias", ventoy_plugin_menualias_entry, ventoy_plugin_menualias_check },
{ "menu_class", ventoy_plugin_menuclass_entry, ventoy_plugin_menuclass_check },
{ "injection", ventoy_plugin_injection_entry, ventoy_plugin_injection_check },
{ "auto_memdisk", ventoy_plugin_auto_memdisk_entry, ventoy_plugin_auto_memdisk_check },
};
static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
@@ -1163,9 +1242,15 @@ void ventoy_plugin_dump_persistence(void)
install_template * ventoy_plugin_find_install_template(const char *isopath)
{
int len;
install_template *node = NULL;
int len = (int)grub_strlen(isopath);
if (!g_install_template_head)
{
return NULL;
}
len = (int)grub_strlen(isopath);
for (node = g_install_template_head; node; node = node->next)
{
if (node->pathlen == len && grub_strcmp(node->isopath, isopath) == 0)
@@ -1197,9 +1282,15 @@ char * ventoy_plugin_get_cur_install_template(const char *isopath)
persistence_config * ventoy_plugin_find_persistent(const char *isopath)
{
int len;
persistence_config *node = NULL;
int len = (int)grub_strlen(isopath);
if (!g_persistence_head)
{
return NULL;
}
len = (int)grub_strlen(isopath);
for (node = g_persistence_head; node; node = node->next)
{
if ((len == node->pathlen) && (grub_strcmp(node->isopath, isopath) == 0))
@@ -1272,9 +1363,15 @@ end:
const char * ventoy_plugin_get_injection(const char *isopath)
{
int len;
injection_config *node = NULL;
int len = (int)grub_strlen(isopath);
if (!g_injection_head)
{
return NULL;
}
len = (int)grub_strlen(isopath);
for (node = g_injection_head; node; node = node->next)
{
if (node->pathlen == len && grub_strcmp(node->isopath, isopath) == 0)
@@ -1288,9 +1385,15 @@ const char * ventoy_plugin_get_injection(const char *isopath)
const char * ventoy_plugin_get_menu_alias(int type, const char *isopath)
{
int len;
menu_alias *node = NULL;
int len = (int)grub_strlen(isopath);
if (!g_menu_alias_head)
{
return NULL;
}
len = (int)grub_strlen(isopath);
for (node = g_menu_alias_head; node; node = node->next)
{
if (node->type == type && node->pathlen &&
@@ -1305,9 +1408,16 @@ const char * ventoy_plugin_get_menu_alias(int type, const char *isopath)
const char * ventoy_plugin_get_menu_class(int type, const char *name)
{
int len;
menu_class *node = NULL;
int len = (int)grub_strlen(name);
if (!g_menu_class_head)
{
return NULL;
}
len = (int)grub_strlen(name);
if (vtoy_class_image_file == type)
{
for (node = g_menu_class_head; node; node = node->next)
@@ -1332,6 +1442,28 @@ const char * ventoy_plugin_get_menu_class(int type, const char *name)
return NULL;
}
int ventoy_plugin_check_memdisk(const char *isopath)
{
int len;
auto_memdisk *node = NULL;
if (!g_auto_memdisk_head)
{
return 0;
}
len = (int)grub_strlen(isopath);
for (node = g_auto_memdisk_head; node; node = node->next)
{
if (node->pathlen == len && grub_strncmp(isopath, node->isopath, len) == 0)
{
return 1;
}
}
return 0;
}
grub_err_t ventoy_cmd_plugin_check_json(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i = 0;

View File

@@ -0,0 +1,275 @@
/******************************************************************************
* ventoy_vhd.c
*
* Copyright (c) 2020, longpanda <admin@ventoy.net>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/disk.h>
#include <grub/device.h>
#include <grub/term.h>
#include <grub/partition.h>
#include <grub/file.h>
#include <grub/normal.h>
#include <grub/extcmd.h>
#include <grub/datetime.h>
#include <grub/i18n.h>
#include <grub/net.h>
#include <grub/time.h>
#include <grub/crypto.h>
#include <grub/charset.h>
#ifdef GRUB_MACHINE_EFI
#include <grub/efi/efi.h>
#endif
#include <grub/ventoy.h>
#include "ventoy_def.h"
GRUB_MOD_LICENSE ("GPLv3+");
static int g_vhdboot_bcd_offset = 0;
static int g_vhdboot_bcd_len = 0;
static int g_vhdboot_isolen = 0;
static char *g_vhdboot_totbuf = NULL;
static char *g_vhdboot_isobuf = NULL;
static int ventoy_vhd_find_bcd(int *bcdoffset, int *bcdlen)
{
grub_uint32_t offset;
grub_file_t file;
char cmdbuf[128];
grub_snprintf(cmdbuf, sizeof(cmdbuf), "loopback vhdiso mem:0x%lx:size:%d", (ulong)g_vhdboot_isobuf, g_vhdboot_isolen);
grub_script_execute_sourcecode(cmdbuf);
file = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s", "(vhdiso)/boot/bcd");
if (!file)
{
grub_printf("Failed to open bcd file in the image file\n");
return 1;
}
grub_file_read(file, &offset, 4);
offset = (grub_uint32_t)grub_iso9660_get_last_read_pos(file);
*bcdoffset = (int)offset;
*bcdlen = (int)file->size;
debug("vhdiso bcd file offset:%d len:%d\n", *bcdoffset, *bcdlen);
grub_file_close(file);
grub_script_execute_sourcecode("loopback -d vhdiso");
return 0;
}
static int ventoy_vhd_patch_path(char *vhdpath, ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2)
{
int i;
int cnt = 0;
char *pos;
grub_size_t pathlen;
const char *plat;
grub_uint16_t *unicode_path;
const grub_uint8_t winloadexe[] =
{
0x77, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x61, 0x00, 0x64, 0x00, 0x2E, 0x00,
0x65, 0x00, 0x78, 0x00, 0x65, 0x00
};
pathlen = sizeof(grub_uint16_t) * (grub_strlen(vhdpath) + 1);
debug("unicode path for <%s> len:%d\n", vhdpath, (int)pathlen);
unicode_path = grub_zalloc(pathlen);
if (!unicode_path)
{
return 0;
}
plat = grub_env_get("grub_platform");
if (plat && (plat[0] == 'e')) /* UEFI */
{
pos = g_vhdboot_isobuf + g_vhdboot_bcd_offset;
/* winload.exe ==> winload.efi */
for (i = 0; i + (int)sizeof(winloadexe) < g_vhdboot_bcd_len; i++)
{
if (*((grub_uint32_t *)(pos + i)) == 0x00690077 &&
grub_memcmp(pos + i, winloadexe, sizeof(winloadexe)) == 0)
{
pos[i + sizeof(winloadexe) - 4] = 0x66;
pos[i + sizeof(winloadexe) - 2] = 0x69;
cnt++;
}
}
debug("winload patch %d times\n", cnt);
}
for (pos = vhdpath; *pos; pos++)
{
if (*pos == '/')
{
*pos = '\\';
}
}
grub_utf8_to_utf16(unicode_path, pathlen, (grub_uint8_t *)vhdpath, -1, NULL);
grub_memcpy(patch1->vhd_file_path, unicode_path, pathlen);
grub_memcpy(patch2->vhd_file_path, unicode_path, pathlen);
return 0;
}
static int ventoy_vhd_patch_disk(ventoy_patch_vhd *patch1, ventoy_patch_vhd *patch2)
{
char efipart[16] = {0};
grub_memcpy(efipart, g_ventoy_part_info->Head.Signature, sizeof(g_ventoy_part_info->Head.Signature));
debug("part1 type: 0x%x <%s>\n", g_ventoy_part_info->MBR.PartTbl[0].FsFlag, efipart);
if (grub_strncmp(efipart, "EFI PART", 8) == 0)
{
ventoy_debug_dump_guid("GPT disk GUID: ", g_ventoy_part_info->Head.DiskGuid);
ventoy_debug_dump_guid("GPT part GUID: ", g_ventoy_part_info->PartTbl[0].PartGuid);
grub_memcpy(patch1->disk_signature_or_guid, g_ventoy_part_info->Head.DiskGuid, 16);
grub_memcpy(patch1->part_offset_or_guid, g_ventoy_part_info->PartTbl[0].PartGuid, 16);
grub_memcpy(patch2->disk_signature_or_guid, g_ventoy_part_info->Head.DiskGuid, 16);
grub_memcpy(patch2->part_offset_or_guid, g_ventoy_part_info->PartTbl[0].PartGuid, 16);
patch1->part_type = patch2->part_type = 0;
}
else
{
debug("MBR disk signature: %02x%02x%02x%02x\n",
g_ventoy_part_info->MBR.BootCode[0x1b8 + 0], g_ventoy_part_info->MBR.BootCode[0x1b8 + 1],
g_ventoy_part_info->MBR.BootCode[0x1b8 + 2], g_ventoy_part_info->MBR.BootCode[0x1b8 + 3]);
grub_memcpy(patch1->disk_signature_or_guid, g_ventoy_part_info->MBR.BootCode + 0x1b8, 4);
grub_memcpy(patch2->disk_signature_or_guid, g_ventoy_part_info->MBR.BootCode + 0x1b8, 4);
}
return 0;
}
grub_err_t ventoy_cmd_patch_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args)
{
int rc;
ventoy_patch_vhd *patch1;
ventoy_patch_vhd *patch2;
char envbuf[64];
(void)ctxt;
(void)argc;
grub_env_unset("vtoy_vhd_buf_addr");
debug("patch vhd <%s>\n", args[0]);
if ((!g_vhdboot_enable) || (!g_vhdboot_totbuf))
{
debug("vhd boot not ready %d %p\n", g_vhdboot_enable, g_vhdboot_totbuf);
return 0;
}
rc = ventoy_vhd_find_bcd(&g_vhdboot_bcd_offset, &g_vhdboot_bcd_len);
if (rc)
{
debug("failed to get bcd location %d\n", rc);
return 0;
}
patch1 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + g_vhdboot_bcd_offset + 0x495a);
patch2 = (ventoy_patch_vhd *)(g_vhdboot_isobuf + g_vhdboot_bcd_offset + 0x50aa);
ventoy_vhd_patch_disk(patch1, patch2);
ventoy_vhd_patch_path(args[0], patch1, patch2);
/* set buffer and size */
#ifdef GRUB_MACHINE_EFI
grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (ulong)g_vhdboot_totbuf);
grub_env_set("vtoy_vhd_buf_addr", envbuf);
grub_snprintf(envbuf, sizeof(envbuf), "%d", (int)(g_vhdboot_isolen + sizeof(ventoy_chain_head)));
grub_env_set("vtoy_vhd_buf_size", envbuf);
#else
grub_snprintf(envbuf, sizeof(envbuf), "0x%lx", (ulong)g_vhdboot_isobuf);
grub_env_set("vtoy_vhd_buf_addr", envbuf);
grub_snprintf(envbuf, sizeof(envbuf), "%d", g_vhdboot_isolen);
grub_env_set("vtoy_vhd_buf_size", envbuf);
#endif
return 0;
}
grub_err_t ventoy_cmd_load_vhdboot(grub_extcmd_context_t ctxt, int argc, char **args)
{
int buflen;
grub_file_t file;
(void)ctxt;
(void)argc;
g_vhdboot_enable = 0;
grub_check_free(g_vhdboot_totbuf);
file = grub_file_open(args[0], VENTOY_FILE_TYPE);
if (!file)
{
return 0;
}
debug("load vhd boot: <%s> <%lu>\n", args[0], (ulong)file->size);
if (file->size < VTOY_SIZE_1KB * 32)
{
grub_file_close(file);
return 0;
}
g_vhdboot_isolen = (int)file->size;
buflen = (int)(file->size + sizeof(ventoy_chain_head));
#ifdef GRUB_MACHINE_EFI
g_vhdboot_totbuf = (char *)grub_efi_allocate_iso_buf(buflen);
#else
g_vhdboot_totbuf = (char *)grub_malloc(buflen);
#endif
if (!g_vhdboot_totbuf)
{
grub_file_close(file);
return 0;
}
g_vhdboot_isobuf = g_vhdboot_totbuf + sizeof(ventoy_chain_head);
grub_file_read(file, g_vhdboot_isobuf, file->size);
grub_file_close(file);
g_vhdboot_enable = 1;
return 0;
}

View File

@@ -20,9 +20,15 @@ all_modules_uefi="blocklist ventoy test newc search at_keyboard usb_keyboard gc
if [ "$1" = "uefi" ]; then
all_modules="$net_modules_uefi $all_modules_uefi "
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/EFI/BOOT/grubx64_real.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi 'fat' 'part_msdos'
#grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/x86_64-efi" -c "$VT_DIR/LiveCD/GRUB/embed.cfg" --prefix '/EFI/boot' --output "$VT_DIR/LiveCD/GRUB/bootx64.efi" --format 'x86_64-efi' --compression 'auto' $all_modules_uefi 'fat' 'part_msdos'
else
all_modules="$net_modules_legacy $all_modules_legacy "
grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc" --prefix '(,2)/grub' --output "$VT_DIR/INSTALL/grub/i386-pc/core.img" --format 'i386-pc' --compression 'auto' $all_modules_legacy 'fat' 'part_msdos' 'biosdisk'
#grub-mkimage -v --directory "$VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc" -c "$VT_DIR/LiveCD/GRUB/embed.cfg" --prefix '/EFI/boot' --output "$VT_DIR/LiveCD/GRUB/cdrom.img" --format 'i386-pc-eltorito' --compression 'auto' $all_modules_legacy 'biosdisk' 'iso9660' 'fat' 'part_msdos'
#rm -f $VT_DIR/LiveCD/GRUB/boot_hybrid.img
#cp -a $VT_DIR/GRUB2/INSTALL/lib/grub/i386-pc/boot_hybrid.img $VT_DIR/LiveCD/GRUB/boot_hybrid.img
fi
grub-mknetdir --modules="$all_modules" --net-directory=$VT_DIR/GRUB2/PXE --subdir=grub2 --locales=en@quot || exit 1

View File

@@ -35,14 +35,32 @@ fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
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})
vtlog "blkdev_num=$blkdev_num vtDM=$vtDM ..."
while [ -n "Y" ]; do
if [ -b /dev/$vtDM ]; then
break
else
sleep 0.3
fi
done
if [ -n "$1" ]; then
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})
vtlog "ln -s /dev/$vtDM $1"
ln -s /dev/$vtDM "$1"
else
vtLABEL=$($BUSYBOX_PATH/blkid /dev/$vtDM | $SED 's/.*LABEL="\([^"]*\)".*/\1/')
vtlog "vtLABEL is $vtLABEL"
if [ -z "$vtLABEL" ]; then
vtLABEL=$($SED "s/.*label=\([^ ]*\)/\1/" /proc/cmdline)
vtlog "vtLABEL is $vtLABEL from cmdline"
fi
ln -s /dev/$vtDM "/dev/disk/by-label/$vtLABEL"
fi
# OK finish
set_ventoy_hook_finish

View File

@@ -24,9 +24,12 @@ if $GREP -q '^"$mount_handler"' /init; then
vthookfile=/hooks/archiso
if [ -e /hook/miso ]; then
if [ -e /hooks/miso ]; then
vthookfile=/hooks/miso
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$misodevice\"" -i /init
elif [ -e /hooks/artix ]; then
vthookfile=/hooks/artix
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$artixdevice\"" -i /init
else
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$archisodevice\"" -i /init
fi

View File

@@ -78,10 +78,10 @@ DISTRO=$(ventoy_get_debian_distro)
echo "##### distribution = $DISTRO ######" >> $VTLOG
. $VTOY_PATH/hook/debian/${DISTRO}-hook.sh
if [ -f /bin/env2debconf ]; then
$SED "1a /bin/sh $VTOY_PATH/hook/debian/ventoy_env2debconf.sh" -i /bin/env2debconf
$SED "s#in *\$(set)#in \$(cat /ventoy/envset)#" -i /bin/env2debconf
fi

View File

@@ -0,0 +1,33 @@
#!/bin/sh
#************************************************************************************
# Copyright (c) 2020, longpanda <admin@ventoy.net>
#
# 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 <http://www.gnu.org/licenses/>.
#
#************************************************************************************
PATH=$PATH:/ventoy/busybox
set > /ventoy/tmpenvset
for i in $(cat /proc/cmdline); do
if echo $i | grep -q "="; then
vtKey=${i%=*}
if ! grep -q "^$vtKey" /ventoy/tmpenvset; then
echo $i >> /ventoy/envset
fi
fi
done
cat /ventoy/tmpenvset >> /ventoy/envset

View File

@@ -349,7 +349,7 @@ 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
if [ -d /ventoy_rdroot ]; then

View File

@@ -23,6 +23,9 @@ while [ -n "$1" ]; do
elif [ "$1" = "-l" ]; then
shift
label=$1
elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
print_usage
exit 0
else
print_usage
exit 1

Binary file not shown.

Binary file not shown.

View File

@@ -1,11 +1,15 @@
#!/bin/sh
if [ -f ./ventoy/version ]; then
curver=$(cat ./ventoy/version)
fi
echo ''
echo '***********************************************************'
echo '* Ventoy2Disk Script *'
echo '* longpanda admin@ventoy.net *'
echo '***********************************************************'
echo '**********************************************'
echo " Ventoy: $curver"
echo " longpanda admin@ventoy.net"
echo " https://www.ventoy.net"
echo '**********************************************'
echo ''
OLDDIR=$PWD

View File

@@ -1,3 +1,5 @@
submenu 'Check plugin json configuration (ventoy.json)' --class=debug_json {
menuentry 'Check global control plugin configuration' --class=debug_control {
set pager=1
@@ -60,6 +62,15 @@ submenu 'Check plugin json configuration (ventoy.json)' --class=debug_json {
set pager=1
vt_check_plugin_json $vt_plugin_path injection $vtoy_iso_part
echo -e "\npress ENTER to exit ..."
read vtInputKey
unset pager
}
menuentry 'Check auto memdisk plugin configuration' --class=debug_automemdisk {
set pager=1
vt_check_plugin_json $vt_plugin_path auto_memdisk $vtoy_iso_part
echo -e "\npress ENTER to exit ..."
read vtInputKey
unset pager
@@ -71,6 +82,33 @@ submenu 'Check plugin json configuration (ventoy.json)' --class=debug_json {
}
submenu "Resolution Configuration" --class=debug_resolution {
menuentry 'Return to previous menu [Esc]' --class=vtoyret VTOY_RET {
echo 'Return ...'
}
vt_update_cur_video_mode VT_CUR_MODE
set vdid=0
while [ $vdid -lt $VTOY_VIDEO_MODE_NUM ]; do
vt_get_video_mode $vdid vtCurMode
unset vtActive
if [ "$vtCurMode" = "$VT_CUR_MODE" ]; then
set vtActive="[*]"
fi
menuentry "$vtCurMode $vtActive" --class=debug_videomode VTOY_RUN_RET {
terminal_output console
set gfxmode=$1
terminal_output gfxterm
}
vt_incr vdid 1
done
}
if [ "$grub_platform" != "pc" ]; then
submenu 'Ventoy UEFI Utilities' --class=debug_util {
menuentry 'Fixup Windows BlinitializeLibrary Failure' {

View File

@@ -48,7 +48,8 @@ function ventoy_power {
configfile $prefix/power.cfg
}
function ventoy_diagnosis {
function ventoy_diagnosis {
vt_enum_video_mode
configfile $prefix/debug.cfg
}
@@ -505,6 +506,10 @@ function uefi_linux_menu_func {
elif [ -f (loop)/hyperbola/boot/x86_64/hyperiso.img ]; then
vt_add_replace_file 0 "EFI\\hyperiso\\hyperiso.img"
fi
elif [ -d (loop)/EFI/BOOT/entries ]; then
if [ -f (loop)/parabola/boot/x86_64/parabolaiso.img ]; then
vt_add_replace_file 0 "EFI\\parabolaiso\\parabolaiso.img"
fi
elif [ -e (loop)/syslinux/alt0/full.cz ]; then
vt_add_replace_file 0 "EFI\\BOOT\\full.cz"
set FirstTryBootFile='@EFI@BOOT@grubx64.efi'
@@ -642,6 +647,8 @@ function legacy_windows_menu_func {
if [ -n "$vtoy_chain_mem_addr" ]; then
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} ibft mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
terminal_output gfxterm
boot
else
echo "chain empty failed"
@@ -813,7 +820,7 @@ function ventoy_iso_busybox_ver {
#special process for deepin-live iso
if [ "$vt_chosen_size" = "403701760" ]; then
if vt_str_begin $vt_chosen_path "/deepin-live"; then
if vt_str_str $vt_chosen_path "/deepin-live"; then
set ventoy_busybox_ver=64
fi
elif vt_str_begin $vt_volume_id "PHOTON_"; then
@@ -855,6 +862,21 @@ function iso_common_menuentry {
fi
}
function miso_common_menuentry {
vt_chosen_img_path vt_chosen_path vt_chosen_size
echo "memdisk mode boot for $vt_chosen_path"
echo ""
ventoy_debug_pause
if [ "$grub_platform" = "pc" ]; then
legacy_iso_memdisk $vtoy_iso_part $vt_chosen_path
else
uefi_iso_memdisk $vtoy_iso_part $vt_chosen_path
fi
}
function common_unsupport_menuentry {
echo -e "\n The name of the iso file could NOT contain space or non-ascii characters. \n"
echo -e " 文件名中不能有中文或空格 \n"
@@ -862,6 +884,10 @@ function common_unsupport_menuentry {
read vtInputKey
}
function miso_unsupport_menuentry {
common_unsupport_menuentry
}
function iso_unsupport_menuentry {
common_unsupport_menuentry
}
@@ -875,6 +901,8 @@ function wim_common_menuentry {
if [ -n "$vtoy_chain_mem_addr" ]; then
if [ "$grub_platform" = "pc" ]; then
linux16 $vtoy_path/ipxe.krn ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
terminal_output gfxterm
else
ventoy_cli_console
chainloader ${vtoy_path}/ventoy_x64.efi env_param=${env_param} isoefi=${LoadIsoEfiDriver} ${vtdebug_flag} mem:${vtoy_chain_mem_addr}:size:${vtoy_chain_mem_size}
@@ -917,6 +945,48 @@ function efi_unsupport_menuentry {
common_unsupport_menuentry
}
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
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}
set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
terminal_output gfxterm
boot
else
ventoy_cli_console
chainloader ${vtoy_path}/ventoy_x64.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 "Failed to boot vhd file"
ventoy_pause
fi
}
function vhd_unsupport_menuentry {
common_unsupport_menuentry
}
#
#============================================================#
# IMG file boot process #
@@ -1185,7 +1255,7 @@ function img_unsupport_menuentry {
#############################################################
#############################################################
set VENTOY_VERSION="1.0.20"
set VENTOY_VERSION="1.0.21"
# Default menu display mode, you can change it as you want.
# 0: List mode
@@ -1212,9 +1282,10 @@ vt_device $root vtoy_dev
if [ "$vtoy_dev" = "tftp" ]; then
set vtoy_path=($root)
for vtid in 0 1 2 3; do
if [ -d (hd$vtid,2)/ventoy ]; then
if [ -f (hd$vtid,2)/ventoy/ventoy.cpio ]; then
set vtoy_iso_part=(hd$vtid,1)
set vtoy_efi_part=(hd$vtid,2)
set vtoydev=hd$vtid
break
fi
done
@@ -1233,12 +1304,15 @@ else
set vtoy_path=($root)/ventoy
fi
set vtoydev=$vtoy_dev
set vtoy_iso_part=($vtoy_dev,1)
set vtoy_efi_part=($vtoy_dev,2)
loadfont unicode
set vt_plugin_path=$vtoy_iso_part
fi
#Load Partition Table
vt_load_part_table $vtoydev
#Load Plugin
if [ -f $vtoy_iso_part/ventoy/ventoy.json ]; then
@@ -1257,20 +1331,28 @@ elif [ -f $vtoy_efi_part/ventoy/ventoy_wimboot.img ]; then
vt_load_wimboot $vtoy_efi_part/ventoy/ventoy_wimboot.img
fi
if [ -f $vtoy_iso_part/ventoy/ventoy_vhdboot.img ]; then
vt_load_vhdboot $vtoy_iso_part/ventoy/ventoy_vhdboot.img
elif [ -f $vtoy_efi_part/ventoy/ventoy_vhdboot.img ]; then
vt_load_vhdboot $vtoy_efi_part/ventoy/ventoy_vhdboot.img
fi
if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
set VTOY_F3_CMD="vt_dynamic_menu 1 1"
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Debug F6:ExMenu"
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:TreeView F4:Localboot F5:Tools F6:ExMenu"
else
set VTOY_F3_CMD="vt_dynamic_menu 1 0"
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Debug F6:ExMenu"
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView F4:Localboot F5:Tools F6:ExMenu"
fi
if [ -n "$vtoy_gfxmode" ]; then
set gfxmode=$vtoy_gfxmode
set gfxpayload=keep
else
set gfxmode=1920x1080,1366x768,1024x768
set gfxmode=1920x1080,1366x768,1024x768,800x600,auto
set gfxpayload=keep
fi
if [ "$vtoy_display_mode" = "CLI" ]; then
@@ -1299,10 +1381,11 @@ fi
#export necessary variable
export theme
export gfxmode
export vtoy_dev
export vtoydev
export vtoy_iso_part
export vtoy_efi_part
export VENTOY_VERSION
export VTOY_CUR_VIDEO_MODE

Binary file not shown.

View File

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

View File

@@ -1,10 +1,33 @@
if [ "$grub_platform" = "pc" ]; then
menuentry 'Search and boot Windows' --class=boot_windows {
if search -n -s -f /bootmgr; then
ntldr /bootmgr
elif search -n -s -f /NTLDR; then
ntldr /NTLDR
menuentry 'Search and boot Windows' --class=boot_windows {
set partid=3
while [ $partid -le 128 ]; do
if vt_check_part_exist $partid; then
for bt in bootmgr BOOTMGR Bootmgr BootMGR; do
if [ -f ($vtoydev,$partid)/$bt ]; then
set root=($vtoydev,$partid)
ntldr /$bt
boot
fi
done
else
break
fi
vt_incr partid 1
done
if search -n -s -f /Boot/BCD; then
for bt in bootmgr BOOTMGR Bootmgr BootMGR; do
if [ -f /$bt ]; then
ntldr /$bt
break
fi
done
elif search -n -s -f /NTDETECT.COM; then
drivemap -s hd0 $root
ntldr /ntldr
else
echo "Windows NOT found ..."
fi
@@ -39,6 +62,22 @@ if [ "$grub_platform" = "pc" ]; then
else
menuentry 'Search and boot Windows' --class=boot_windows {
set partid=3
while [ $partid -le 128 ]; do
if vt_check_part_exist $partid; then
if [ -f ($vtoydev,$partid)/EFI/Microsoft/Boot/bootmgfw.efi ]; then
set root=($vtoydev,$partid)
terminal_output console
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
boot
fi
else
break
fi
vt_incr partid 1
done
if search -n -s -f /EFI/Microsoft/Boot/bootmgfw.efi; then
terminal_output console
chainloader /EFI/Microsoft/Boot/bootmgfw.efi

View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -127,6 +127,12 @@ zip -r ventoy-${curver}-windows.zip $tmpdir/
rm -rf $tmpdir
cd ../LiveCD
sh livecd.sh
cd $CurDir
mv ../LiveCD/ventoy*.iso ./
if [ -e ventoy-${curver}-windows.zip ] && [ -e ventoy-${curver}-linux.tar.gz ]; then
echo -e "\n ============= SUCCESS =================\n"
else

Binary file not shown.

View File

@@ -0,0 +1,4 @@
tinycore follows the GPL-v2 License (see gpl-2.0.txt)
Ventoy does not modify its source code, only its binraries are used.

BIN
LiveCD/GRUB/boot_hybrid.img Normal file

Binary file not shown.

BIN
LiveCD/GRUB/bootx64.efi Normal file

Binary file not shown.

BIN
LiveCD/GRUB/cdrom.img Normal file

Binary file not shown.

5
LiveCD/GRUB/embed.cfg Normal file
View File

@@ -0,0 +1,5 @@
search -f /EFI/VentoyLiveCD -s root
configfile ($root)/EFI/boot/grub.cfg

View File

@@ -0,0 +1,3 @@
VentoyLiveCD
https://www.ventoy.net

View File

@@ -0,0 +1,17 @@
set timeout=3
set default=LiveCD
clear
menuentry 'Ventoy xxx LiveCD' --id=LiveCD {
linux /EFI/boot/vmlinuz quiet loglevel=0 superuser rdinit=/ventoy/init.sh
initrd /EFI/ventoy/ventoy.gz /EFI/boot/core.gz /EFI/boot/modules.gz newc:ventoy.tar.gz:/EFI/ventoy/ventoy-xxx-linux.tar.gz
boot
}
menuentry 'Ventoy xxx LiveCD (Debug Mode)' {
linux /EFI/boot/vmlinuz loglevel=10 multivt superuser rdinit=/ventoy/init.sh
initrd /EFI/ventoy/ventoy.gz /EFI/boot/core.gz /EFI/boot/modules.gz newc:ventoy.tar.gz:/EFI/ventoy/ventoy-xxx-linux.tar.gz
boot
}

34
LiveCD/README.txt Normal file
View File

@@ -0,0 +1,34 @@
Ventoy LiveCD is Tinycore distro + Ventoy linux install package.
vmlinuz and core.gz are downloaded from:
http://www.tinycorelinux.net/11.x/x86/release/distribution_files/
MD5SUM:
0fd08c73e84b26aabbd0d12006d64855 core.gz
a9c2e2abbf464517e681234fb4687aa1 vmlinuz
VTOY/ventoy/tcz/*/tcz are downloaded from:
http://distro.ibiblio.org/tinycorelinux/11.x/x86/tcz/
MD5SUM:
b6153a469d1d56e1e6895c6812a344cd dosfstools.tcz
29a4585d38b34ad58f8a7cb2d09e065f glib2.tcz
6812067a60165aee3cbcc07a75b6b1f4 libffi.tcz
5120e0c9ee65f936dea8cb6a0a0a1ddd liblvm2.tcz
92909db8fb3c4333a2a4a325ffbf4b50 ncursesw.tcz
e2bb47c9da2abab62fa794d69aba97c0 parted.tcz
0e6dfbebe816062a81aff6d3e5e7719b readline.tcz
3cf996373ab01be269ea0efaf17ce0cd udev-lib.tcz
VTOY/ventoy/drivers/*.ko
build kernel
http://www.tinycorelinux.net/11.x/x86/release/src/kernel/
config-5.4.3-tinycore
linux-5.4.3-patched.txz
disable a wireless lan driver to avoid compile error

View File

@@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned long long UINT64;
int GetHumanReadableGBSize(UINT64 SizeBytes)
{
int i;
int Pow2 = 1;
double Delta;
double GB = SizeBytes * 1.0 / 1000 / 1000 / 1000;
for (i = 0; i < 12; i++)
{
if (Pow2 > GB)
{
Delta = (Pow2 - GB) / Pow2;
}
else
{
Delta = (GB - Pow2) / Pow2;
}
if (Delta < 0.05)
{
return Pow2;
}
Pow2 <<= 1;
}
return (int)GB;
}
int main(int argc, char **argv)
{
UINT64 value = strtoul(argv[1], NULL, 10);
printf("%d", GetHumanReadableGBSize(value * 512));
return 0;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,12 @@
#!/bin/sh
cat /ventoy/modlist | while read line; do
if [ -e /ventoy/drivers/${line}.ko ]; then
insmod /ventoy/drivers/${line}.ko
fi
done
sleep 5
echo "sh /ventoy/profile.sh" >> /root/.profile
exec /init

View File

@@ -0,0 +1,27 @@
scsi_transport_sas
mptbase
mptscsih
mptsas
yurex
ezusb
parport
uss720
usb4604
usb3503
sisusbvga
usb251xb
pi3usb30532
usb-otg-fsm
usb-conn-gpio
ulpi
ums-realtek
xhci-hcd
xhci-pci
xhci-plat-hcd
usbip-core
usbip-host
vhci-hcd
cdc-wdm
cdc-acm
usblp
megaraid_sas

View File

@@ -0,0 +1,22 @@
#!/bin/sh
cd /
tar -xf ventoy.tar.gz
cd /ventoy
mkdir mnt
for i in $(ls tcz/*.tcz); do
mount $i mnt
cp -a mnt/* /
umount mnt
done
ldconfig /usr/local/lib /usr/lib /lib
#workaround for swapon
rm -f /sbin/swapon
echo '#!/bin/sh' > /sbin/swapon
chmod +x /sbin/swapon
sh /ventoy/ventoy.sh

Binary file not shown.

View File

@@ -0,0 +1,298 @@
#!/bin/sh
info() {
echo -e "\033[32m$*\033[0m"
}
warn() {
echo -e "\033[33m$*\033[0m"
}
err() {
echo -e "\033[31m$*\033[0m"
}
get_disk_size() {
sec=$(cat /sys/block/$1/size)
/ventoy/disksize $sec
}
enum_disk() {
id=1
rm -f /device.list
ls /sys/block/ | grep 'd[a-z]' | while read dev; do
if ! [ -b /dev/$dev ]; then
continue
fi
size=$(get_disk_size $dev)
model=$(parted -s /dev/$dev p 2>/dev/null | grep Model | sed 's/Model: \(.*\)/\1/')
printf " <%d> %-4s %3s GB %s\r\n" $id "$dev" "$size" "$model" >> /device.list
id=$(expr $id + 1)
done
}
select_disk() {
echo "" > /dev/console
echo "" > /dev/console
if [ -f /device.list ]; then
lines=$(cat /device.list | wc -l)
cat /device.list > /dev/console
else
echo -e "\033[31m !!! NO device detected !!!\033[0m" > /dev/console
lines=0
fi
echo "" > /dev/console
echo " <a> Refresh device list <b> Reboot <c> Enter shell" > /dev/console
echo "" > /dev/console
while true; do
if [ $lines -gt 0 ]; then
read -p "Please select the disk to operator [1-$lines] " Answer
else
read -p "Please choose your operation [a-c] " Answer
fi
if [ "$Answer" = "shell" ]; then
echo 8888; return
elif [ "$Answer" = "c" ] || [ "$Answer" = "C" ]; then
echo 8888; return
fi
if [ "$Answer" = "a" ] || [ "$Answer" = "A" ]; then
echo 0; return
elif [ "$Answer" = "b" ] || [ "$Answer" = "B" ]; then
read -p "Do you really want to reboot? (y/n) " Ask
if [ "$Ask" = "y" ] || [ "$Ask" = "Y" ]; then
reboot
else
continue
fi
fi
if [ -n "$Answer" ]; then
if echo $Answer | grep -q "^[1-9][0-9]*$"; then
if [ $Answer -gt 0 ] && [ $Answer -le $lines ]; then
echo $Answer
return
fi
fi
fi
done
}
get_dev_ventoy_ver() {
if ! [ -b /dev/${1}2 ]; then
echo "NO"; return
fi
mount -t vfat -o ro /dev/${1}2 /ventoy/mnt >/dev/null 2>/dev/null
if [ -e /ventoy/mnt/ventoy ] && [ -f /ventoy/mnt/grub/grub.cfg ]; then
if grep -q 'set.*VENTOY_VERSION=' /ventoy/mnt/grub/grub.cfg; then
grep 'set.*VENTOY_VERSION=' /ventoy/mnt/grub/grub.cfg | awk -F'"' '{print $2}'
else
echo 'NO'
fi
umount /ventoy/mnt
return
fi
echo "NO"
}
ventoy_configuration() {
while true; do
if [ -f /preserve.txt ]; then
SPACE=$(cat /preserve.txt)
else
SPACE=0
fi
if [ -f /secureboot.txt ]; then
SECURE=$(cat /secureboot.txt)
else
SECURE=Disable
fi
if [ -f /partstyle.txt ]; then
STYLE=$(cat /partstyle.txt)
else
STYLE=MBR
fi
echo ""
echo -e " <1> Preserve space (only for install) \033[32m[${SPACE}MB]\033[0m"
echo -e " <2> Secure boot support \033[32m[$SECURE]\033[0m"
echo -e " <3> Partition style (only for install) \033[32m[$STYLE]\033[0m"
echo " <0> Back to previous menu"
echo ""
while true; do
read -p "Please choose your operation: " Answer
if echo $Answer | grep -q "^[0-3]$"; then
break
fi
done
if [ "$Answer" = "0" ]; then
break
elif [ "$Answer" = "1" ]; then
while true; do
read -p "Please input the preserve space in MB: " Answer
if echo $Answer | grep -q "^[1-9][0-9]*$"; then
echo $Answer > /preserve.txt
break
fi
done
elif [ "$Answer" = "2" ]; then
if [ "$SECURE" = "Disable" ]; then
echo "Enable" > /secureboot.txt
else
echo "Disable" > /secureboot.txt
fi
else
if [ "$STYLE" = "GPT" ]; then
echo "MBR" > /partstyle.txt
else
echo "GPT" > /partstyle.txt
fi
fi
done
}
cd /
VTPATH=$(ls -1 | grep ventoy-)
VTVER=${VTPATH#*-}
cd $VTPATH
clear
echo ""
info "**************************************************"
vline=$(printf "* Ventoy LiveCD %6s *\r\n" "$VTVER")
info "$vline"
info "**************************************************"
echo ""
info "Scaning devices ......"
sleep 5
enum_disk
while true; do
sel=$(select_disk)
if [ $sel -eq 8888 ]; then
break
elif [ $sel -eq 0 ]; then
enum_disk
continue
fi
DEV=$(sed -n "${sel}p" /device.list | awk '{print $2}')
DevVtVer=$(get_dev_ventoy_ver $DEV)
if [ "$DevVtVer" = "NO" ]; then
while true; do
echo ""
echo " <1> Install Ventoy to $DEV"
echo " <2> Set Configuration"
echo " <0> Back to previous menu"
echo ""
while true; do
read -p "Please choose your operation: " Answer
if echo $Answer | grep -q "^[0-2]$"; then
break;
fi
done
if [ "$Answer" = "0" ]; then
break
elif [ "$Answer" = "2" ]; then
ventoy_configuration
else
opt=""
if [ -f /preserve.txt ]; then
opt="$opt -r $(cat /preserve.txt)"
fi
if [ -f /secureboot.txt ] && grep -q "Enable" /secureboot.txt; then
opt="$opt -s"
fi
if [ -f /partstyle.txt ] && grep -q "GPT" /partstyle.txt; then
opt="$opt -g"
fi
info "Ventoy2Disk.sh $opt -i /dev/$DEV"
sh Ventoy2Disk.sh $opt -i /dev/$DEV
sync
break
fi
done
else
info "Ventoy $DevVtVer detected in the device $DEV"
while true; do
echo ""
echo " <1> Update Ventoy in $DEV from $DevVtVer ==> $VTVER"
echo " <2> Re-install Ventoy to $DEV"
echo " <3> Set Configuration"
echo " <0> Back to previous menu"
echo ""
while true; do
read -p "Please choose your operation: " Answer
if echo $Answer | grep -q "^[0-3]$"; then
break;
fi
done
if [ "$Answer" = "0" ]; then
break
elif [ "$Answer" = "1" ]; then
opt=""
if [ -f /secureboot.txt ] && grep -q "Enable" /secureboot.txt; then
opt="$opt -s"
fi
info "Ventoy2Disk.sh $opt -u /dev/$DEV"
sh Ventoy2Disk.sh $opt -u /dev/$DEV
sync
break
elif [ "$Answer" = "2" ]; then
opt=""
if [ -f /preserve.txt ]; then
opt="$opt -r $(cat /preserve.txt)"
fi
if [ -f /secureboot.txt ] && grep -q "Enable" /secureboot.txt; then
opt="$opt -s"
fi
if [ -f /partstyle.txt ] && grep -q "GPT" /partstyle.txt; then
opt="$opt -g"
fi
info "Ventoy2Disk.sh $opt -I /dev/$DEV"
sh Ventoy2Disk.sh $opt -I /dev/$DEV
sync
break
else
ventoy_configuration
fi
done
fi
done

60
LiveCD/livecd.sh Normal file
View File

@@ -0,0 +1,60 @@
#!/bin/bash
VENTOY_PATH=$PWD/../
if ! [ -f $VENTOY_PATH/INSTALL/grub/grub.cfg ]; then
echo "no grub.cfg detected"
exit 1
fi
version=$(grep 'set.*VENTOY_VERSION=' $VENTOY_PATH/INSTALL/grub/grub.cfg | awk -F'"' '{print $2}')
if ! [ -e $VENTOY_PATH/INSTALL/ventoy-${version}-linux.tar.gz ]; then
echo "no ventoy-${version}-linux.tar.gz detected"
exit 1
fi
rm -rf ISO_TMP
cp -a ISO ISO_TMP
cp -a VTOY VTOY_TMP && cd VTOY_TMP
gcc -O2 -m32 ./ventoy/disksize.c -o ./ventoy/disksize
rm -f ./ventoy/disksize.c
find . | cpio -o -H newc | gzip -9 > ../ISO_TMP/EFI/ventoy/ventoy.gz
cd .. && rm -rf VTOY_TMP
cp -a $VENTOY_PATH/INSTALL/ventoy-${version}-linux.tar.gz ISO_TMP/EFI/ventoy/
cp -a GRUB/cdrom.img ISO_TMP/EFI/boot/
cp -a GRUB/bootx64.efi ISO_TMP/EFI/boot/
rm -rf efimnt
rm -f efi.img
mkdir -p efimnt
dd if=/dev/zero of=efi.img bs=1M count=2
mkfs.vfat efi.img
mount efi.img efimnt
mkdir -p efimnt/EFI/boot
cp -a GRUB/bootx64.efi efimnt/EFI/boot/
umount efimnt
sync
cp -a efi.img ISO_TMP/EFI/boot/
rm -rf efimnt
rm -f efi.img
cd ISO_TMP
sed "s/xxx/$version/g" -i EFI/boot/grub.cfg
rm -f ../ventoy-${version}-livecd.iso
xorriso -as mkisofs -allow-lowercase --sort-weight 0 / --sort-weight 1 /EFI -v -R -J -V 'VentoyLiveCD' -P 'VENTOY COMPATIBLE' -p 'https://www.ventoy.net' -sysid 'Ventoy' -A 'VentoyLiveCD' -b EFI/boot/cdrom.img --grub2-boot-info --grub2-mbr ../GRUB/boot_hybrid.img -c EFI/boot/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e EFI/boot/efi.img -no-emul-boot -append_partition 2 0xEF EFI/boot/efi.img -o ../ventoy-${version}-livecd.iso .
cd ../
rm -rf ISO_TMP

View File

@@ -15,7 +15,7 @@ With ventoy, you don't need to format the disk over and over, you just need to c
You can copy many iso files at a time and ventoy will give you a boot menu to select them. <br/>
Both Legacy BIOS and 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...), 470+ ISO files are tested. <br/>
Most type of OS supported(Windows/WinPE/Linux/Unix/Vmware/Xen...), 550+ ISO files are tested. <br/>
A "Ventoy Compatible" concept is introduced by ventoy, which can help to support any ISO file.
</h4>
@@ -34,7 +34,7 @@ A "Ventoy Compatible" concept is introduced by ventoy, which can help to support
* File injection supported (1.0.16+)
* ISO files larger than 4GB supported
* Native boot menu style for Legacy & UEFI
* Most type of OS supported(Windows/WinPE/Linux/Unix/Vmware/Xen...), 470+ iso files tested
* Most type of OS supported(Windows/WinPE/Linux/Unix/Vmware/Xen...), 550+ iso files tested
* Not only boot but also complete installation process
* ISO files can be listed in List mode/TreeView mode
* "Ventoy Compatible" concept

View File

@@ -180,7 +180,11 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes, MBR_HEAD *pMBR, UIN
if (MBR.PartTbl[0].Active != 0x80 && MBR.PartTbl[1].Active != 0x80)
{
Log("Part1 and Part2 are both NOT active 0x%x 0x%x", MBR.PartTbl[0].Active, MBR.PartTbl[1].Active);
return FALSE;
if (MBR.PartTbl[2].Active != 0x80 && MBR.PartTbl[3].Active != 0x80)
{
Log("Part3 and Part4 are both NOT active 0x%x 0x%x", MBR.PartTbl[2].Active, MBR.PartTbl[3].Active);
return FALSE;
}
}
*Part2StartSector = MBR.PartTbl[1].StartSectorId;