Compare commits

...

23 Commits

Author SHA1 Message Date
longpanda
d0edcc0ef0 1.0.09 release 2020-05-09 22:15:14 +08:00
BL4CKH47H4CK3R
c84c072209 Add Russian Language (#78) 2020-05-09 19:33:46 +08:00
longpanda
8204c31df8 add Spanish language 2020-05-09 07:48:46 +08:00
vavanade
f028a6f89c added Czech language (#73) 2020-05-09 07:46:27 +08:00
vboucard
263f5dd3a8 add language french (#66) 2020-05-07 07:47:21 +08:00
longpanda
cf4b82e4db file encoding UTF-16 2020-05-06 21:10:21 +08:00
luzeagithub
fdfa7e22c9 Fixed typo, changed font size (#63)
* Fixed typo, changed font size

* Changed font size back to 16
2020-05-06 21:08:32 +08:00
longpanda
835cb958ed optimize for muli-language ini format 2020-05-05 18:49:18 +08:00
longpanda
ce9c679ab3 file format ucs2-little 2020-05-05 15:49:28 +08:00
luzeagithub
967a259cee Add German language (#57) 2020-05-05 15:46:08 +08:00
longpanda
f25289e379 Add Turkish language 2020-05-05 14:42:04 +08:00
longpanda
0490480467 update languages.ini 2020-05-05 08:47:05 +08:00
Estevão Costa
0a1b6e221c Add Portuguese (Brazil) translation (#55)
Co-authored-by: longpanda <59477474+ventoy@users.noreply.github.com>
2020-05-05 08:41:42 +08:00
B.O.S.S
3fc76d6b63 Add Polish transation (#54) 2020-05-05 08:37:52 +08:00
longpanda
474b9a3fad add languages.ini 2020-05-05 00:03:54 +08:00
longpanda
3ca624f3ee 1.0.09 beta1 release 2020-05-04 23:47:01 +08:00
longpanda
d42bc35915 some missing 2020-05-03 07:58:27 +08:00
luzeagithub
39b5edc345 Rename DON_NOT_RUN_Ventoy2Disk_HERE.txt to DO_NOT_RUN_Ventoy2Disk_HERE.txt (#46) 2020-05-03 07:54:15 +08:00
longpanda
9c183ed416 add tip for installation 2020-05-01 07:55:04 +08:00
longpanda
8e0c630fe5 Merge branch 'master' of https://github.com/ventoy/Ventoy 2020-04-30 22:41:13 +08:00
longpanda
9f57cb3929 1.0.08 release 2020-04-30 22:40:42 +08:00
longpanda
525ef4f516 Update README.md 2020-04-29 09:24:10 +08:00
longpanda
212c9cdbc9 1.0.08beta2 2020-04-27 20:44:36 +08:00
51 changed files with 1718 additions and 206 deletions

View File

@@ -964,6 +964,12 @@ grub_fat_dir (grub_device_t device, const char *path, grub_fs_dir_hook_t hook,
info.dir = !! (ctxt.dir.attr & GRUB_FAT_ATTR_DIRECTORY);
info.case_insensitive = 1;
#ifdef MODE_EXFAT
if (!info.dir)
info.size = ctxt.dir.file_size;
#endif
#ifdef MODE_EXFAT
if (!ctxt.dir.have_stream)
continue;
@@ -1445,4 +1451,3 @@ END:
}
#endif

View File

@@ -34,6 +34,12 @@
#include <grub/dl.h>
#include <grub/env.h>
int g_ventoy_menu_refresh = 0;
int g_ventoy_memdisk_mode = 0;
int g_ventoy_iso_raw = 0;
int g_ventoy_iso_uefi_drv = 0;
int g_ventoy_last_entry = 0;
/* Time to delay after displaying an error message about a default/fallback
entry failing to boot. */
#define DEFAULT_ENTRY_ERROR_DELAY_MS 2500
@@ -577,16 +583,20 @@ print_countdown (struct grub_term_coordinate *pos, int n)
static int
run_menu (grub_menu_t menu, int nested, int *auto_boot)
{
const char *cmdstr;
grub_uint64_t saved_time;
int default_entry, current_entry;
int default_entry,current_entry;
int timeout;
enum timeout_style timeout_style;
default_entry = get_entry_number (menu, "default");
if (g_ventoy_last_entry >= 0 && g_ventoy_last_entry < menu->size) {
default_entry = g_ventoy_last_entry;
}
/* If DEFAULT_ENTRY is not within the menu entries, fall back to
the first entry. */
if (default_entry < 0 || default_entry >= menu->size)
else if (default_entry < 0 || default_entry >= menu->size)
default_entry = 0;
timeout = grub_menu_get_timeout ();
@@ -787,34 +797,76 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
}
goto refresh;
case GRUB_TERM_KEY_F2:
cmdstr = grub_env_get("VTOY_F2_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F3:
cmdstr = grub_env_get("VTOY_F3_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F4:
cmdstr = grub_env_get("VTOY_F4_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F5:
cmdstr = grub_env_get("VTOY_F5_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F6:
cmdstr = grub_env_get("VTOY_F6_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F7:
cmdstr = grub_env_get("VTOY_F7_CMD");
if (cmdstr)
{
menu_fini ();
grub_script_execute_sourcecode(cmdstr);
goto refresh;
}
break;
case GRUB_TERM_KEY_F1:
menu_fini ();
if (grub_env_get("VTOY_MEM_DISK")) {
grub_env_unset("VTOY_MEM_DISK");
}else {
grub_env_set("VTOY_MEM_DISK", grub_env_get("VTOY_MEM_DISK_STR"));
}
grub_env_set("VTOY_MENU_REFRESH", "1");
g_ventoy_memdisk_mode = 1 - g_ventoy_memdisk_mode;
g_ventoy_menu_refresh = 1;
goto refresh;
case GRUB_TERM_KEY_F3:
case (GRUB_TERM_CTRL | 'i'):
menu_fini ();
if (grub_env_get("VTOY_ISO_RAW")) {
grub_env_unset("VTOY_ISO_RAW");
}else {
grub_env_set("VTOY_ISO_RAW", grub_env_get("VTOY_ISO_RAW_STR"));
}
grub_env_set("VTOY_MENU_REFRESH", "1");
g_ventoy_iso_raw = 1 - g_ventoy_iso_raw;
g_ventoy_menu_refresh = 1;
goto refresh;
case GRUB_TERM_KEY_F4:
case (GRUB_TERM_CTRL | 'u'):
menu_fini ();
if (grub_env_get("VTOY_ISO_UEFI_DRV")) {
grub_env_unset("VTOY_ISO_UEFI_DRV");
}else {
grub_env_set("VTOY_ISO_UEFI_DRV", grub_env_get("VTOY_ISO_UEFI_DRV_STR"));
}
grub_env_set("VTOY_MENU_REFRESH", "1");
g_ventoy_iso_uefi_drv = 1 - g_ventoy_iso_uefi_drv;
g_ventoy_menu_refresh = 1;
goto refresh;
default:
@@ -897,6 +949,8 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
if (boot_entry < 0)
break;
g_ventoy_last_entry = boot_entry;
e = grub_menu_get_entry (menu, boot_entry);
if (! e)
continue; /* Menu is empty. */

View File

@@ -52,11 +52,14 @@ int g_valid_initrd_count = 0;
static grub_file_t g_old_file;
char g_img_swap_tmp_buf[1024];
img_info g_img_swap_tmp;
img_info *g_ventoy_img_list = NULL;
int g_ventoy_img_count = 0;
grub_device_t g_enum_dev = NULL;
grub_fs_t g_enum_fs = NULL;
img_iterator_node g_img_iterator_head;
img_iterator_node *g_img_iterator_tail = NULL;
grub_uint8_t g_ventoy_break_level = 0;
grub_uint8_t g_ventoy_debug_level = 0;
@@ -71,6 +74,13 @@ ventoy_guid g_ventoy_guid = VENTOY_GUID;
ventoy_img_chunk_list g_img_chunk_list;
static char *g_tree_script_buf = NULL;
static int g_tree_script_pos = 0;
static char *g_list_script_buf = NULL;
static int g_list_script_pos = 0;
void ventoy_debug(const char *fmt, ...)
{
va_list args;
@@ -530,7 +540,7 @@ static grub_err_t ventoy_cmd_check_compatible(grub_extcmd_context_t ctxt, int ar
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static int ventoy_cmp_img(img_info *img1, img_info *img2)
int ventoy_cmp_img(img_info *img1, img_info *img2)
{
char *s1, *s2;
int c1 = 0;
@@ -560,15 +570,17 @@ static int ventoy_cmp_img(img_info *img1, img_info *img2)
return (c1 - c2);
}
static void ventoy_swap_img(img_info *img1, img_info *img2)
void ventoy_swap_img(img_info *img1, img_info *img2)
{
grub_memcpy(g_img_swap_tmp_buf, img1->name, sizeof(img1->name));
grub_memcpy(img1->name, img2->name, sizeof(img1->name));
grub_memcpy(img2->name, g_img_swap_tmp_buf, sizeof(img1->name));
grub_memcpy(&g_img_swap_tmp, img1, sizeof(img_info));
grub_memcpy(g_img_swap_tmp_buf, img1->path, sizeof(img1->path));
grub_memcpy(img1->path, img2->path, sizeof(img1->path));
grub_memcpy(img2->path, g_img_swap_tmp_buf, sizeof(img1->path));
grub_memcpy(img1, img2, sizeof(img_info));
img1->next = g_img_swap_tmp.next;
img1->prev = g_img_swap_tmp.prev;
g_img_swap_tmp.next = img2->next;
g_img_swap_tmp.prev = img2->prev;
grub_memcpy(img2, &g_img_swap_tmp, sizeof(img_info));
}
static int ventoy_img_name_valid(const char *filename, grub_size_t namelen)
@@ -591,11 +603,27 @@ static int ventoy_img_name_valid(const char *filename, grub_size_t namelen)
return 1;
}
static int ventoy_check_ignore_flag(const char *filename, const struct grub_dirhook_info *info, void *data)
{
if (0 == info->dir)
{
if (filename && filename[0] == '.' && 0 == grub_strncmp(filename, ".ventoyignore", 13))
{
*((int *)data) = 1;
return 0;
}
}
return 0;
}
static int ventoy_colect_img_files(const char *filename, const struct grub_dirhook_info *info, void *data)
{
int ignore = 0;
grub_size_t len;
img_info *img;
img_info *tail;
img_iterator_node *tmp;
img_iterator_node *new_node;
img_iterator_node *node = (img_iterator_node *)data;
@@ -609,14 +637,47 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
return 0;
}
new_node = grub_malloc(sizeof(img_iterator_node));
if (!ventoy_img_name_valid(filename, len))
{
return 0;
}
if (filename[0] == '$' && 0 == grub_strncmp(filename, "$RECYCLE.BIN", 12))
{
return 0;
}
new_node = grub_zalloc(sizeof(img_iterator_node));
if (new_node)
{
new_node->tail = node->tail;
grub_snprintf(new_node->dir, sizeof(new_node->dir), "%s%s/", node->dir, filename);
new_node->dirlen = grub_snprintf(new_node->dir, sizeof(new_node->dir), "%s%s/", node->dir, filename);
new_node->next = g_img_iterator_head.next;
g_img_iterator_head.next = new_node;
g_enum_fs->fs_dir(g_enum_dev, new_node->dir, ventoy_check_ignore_flag, &ignore);
if (ignore)
{
debug("Directory %s ignored...\n", new_node->dir);
grub_free(new_node);
return 0;
}
new_node->tail = node->tail;
new_node->parent = node;
if (!node->firstchild)
{
node->firstchild = new_node;
}
if (g_img_iterator_tail)
{
g_img_iterator_tail->next = new_node;
g_img_iterator_tail = new_node;
}
else
{
g_img_iterator_head.next = new_node;
g_img_iterator_tail = new_node;
}
}
}
else
@@ -646,6 +707,22 @@ static int ventoy_colect_img_files(const char *filename, const struct grub_dirho
{
g_ventoy_img_list = img;
}
img->size = info->size;
img->id = g_ventoy_img_count;
img->parent = node;
if (node && NULL == node->firstiso)
{
node->firstiso = img;
}
node->isocnt++;
tmp = node->parent;
while (tmp)
{
tmp->isocnt++;
tmp = tmp->parent;
}
*((img_info **)(node->tail)) = img;
g_ventoy_img_count++;
@@ -734,6 +811,96 @@ int ventoy_fill_data(grub_uint32_t buflen, char *buffer)
return len;
}
static img_info * ventoy_get_min_iso(img_iterator_node *node)
{
img_info *minimg = NULL;
img_info *img = (img_info *)(node->firstiso);
while (img && (img_iterator_node *)(img->parent) == node)
{
if (img->select == 0 && (NULL == minimg || grub_strcmp(img->name, minimg->name) < 0))
{
minimg = img;
}
img = img->next;
}
if (minimg)
{
minimg->select = 1;
}
return minimg;
}
static img_iterator_node * ventoy_get_min_child(img_iterator_node *node)
{
img_iterator_node *Minchild = NULL;
img_iterator_node *child = node->firstchild;
while (child && child->parent == node)
{
if (child->select == 0 && (NULL == Minchild || grub_strcmp(child->dir, Minchild->dir) < 0))
{
Minchild = child;
}
child = child->next;
}
if (Minchild)
{
Minchild->select = 1;
}
return Minchild;
}
static int ventoy_dynamic_tree_menu(img_iterator_node *node)
{
int offset = 1;
img_info *img;
img_iterator_node *child = NULL;
if (node->isocnt == 0 || node->done == 1)
{
return 0;
}
if (node->parent && node->parent->dirlen < node->dirlen)
{
offset = node->parent->dirlen;
}
if (node != &g_img_iterator_head)
{
node->dir[node->dirlen - 1] = 0;
g_tree_script_pos += grub_snprintf(g_tree_script_buf + g_tree_script_pos, VTOY_MAX_SCRIPT_BUF - g_tree_script_pos,
"submenu \"%-10s [%s]\" {\n", "DIR", node->dir + offset);
}
while ((child = ventoy_get_min_child(node)) != NULL)
{
ventoy_dynamic_tree_menu(child);
}
while ((img = ventoy_get_min_iso(node)) != NULL)
{
g_tree_script_pos += grub_snprintf(g_tree_script_buf + g_tree_script_pos, VTOY_MAX_SCRIPT_BUF - g_tree_script_pos,
"menuentry \"%-10s %s\" --id=\"VID_%d\" {\n"
" common_menuentry \n"
"}\n",
grub_get_human_size(img->size, GRUB_HUMAN_SIZE_SHORT), img->name, img->id);
}
if (node != &g_img_iterator_head)
{
g_tree_script_pos += grub_snprintf(g_tree_script_buf + g_tree_script_pos, VTOY_MAX_SCRIPT_BUF - g_tree_script_pos, "}\n");
}
node->done = 1;
return 0;
}
static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_fs_t fs;
@@ -743,6 +910,7 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
char *device_name = NULL;
char buf[32];
img_iterator_node *node = NULL;
img_iterator_node *tmp = NULL;
(void)ctxt;
@@ -762,13 +930,13 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
goto fail;
}
dev = grub_device_open(device_name);
g_enum_dev = dev = grub_device_open(device_name);
if (!dev)
{
goto fail;
}
fs = grub_fs_probe(dev);
g_enum_fs = fs = grub_fs_probe(dev);
if (!fs)
{
goto fail;
@@ -776,20 +944,29 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
grub_memset(&g_img_iterator_head, 0, sizeof(g_img_iterator_head));
g_img_iterator_head.dirlen = 1;
g_img_iterator_head.tail = &tail;
grub_strcpy(g_img_iterator_head.dir, "/");
grub_strcpy(g_img_iterator_head.dir, "/");
fs->fs_dir(dev, "/", ventoy_colect_img_files, &g_img_iterator_head);
while (g_img_iterator_head.next)
for (node = &g_img_iterator_head; node; node = node->next)
{
node = g_img_iterator_head.next;
g_img_iterator_head.next = node->next;
fs->fs_dir(dev, node->dir, ventoy_colect_img_files, node);
grub_free(node);
fs->fs_dir(dev, node->dir, ventoy_colect_img_files, node);
}
for (node = &g_img_iterator_head; node; node = node->next)
{
ventoy_dynamic_tree_menu(node);
}
/* free node */
node = g_img_iterator_head.next;
while (node)
{
tmp = node->next;
grub_free(node);
node = tmp;
}
/* sort image list by image name */
for (cur = g_ventoy_img_list; cur; cur = cur->next)
{
@@ -802,6 +979,16 @@ static grub_err_t ventoy_cmd_list_img(grub_extcmd_context_t ctxt, int argc, char
}
}
for (cur = g_ventoy_img_list; cur; cur = cur->next)
{
g_list_script_pos += grub_snprintf(g_list_script_buf + g_list_script_pos, VTOY_MAX_SCRIPT_BUF - g_list_script_pos,
"menuentry \"%s\" --id=\"VID_%d\" {\n"
" common_menuentry \n"
"}\n",
cur->name, cur->id);
}
g_list_script_buf[g_list_script_pos] = 0;
grub_snprintf(buf, sizeof(buf), "%d", g_ventoy_img_count);
grub_env_set(args[1], buf);
@@ -876,7 +1063,9 @@ static grub_err_t ventoy_cmd_img_name(grub_extcmd_context_t ctxt, int argc, char
static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int argc, char **args)
{
const char *name = NULL;
int img_id = 0;
char *pos = NULL;
const char *id = NULL;
img_info *cur = g_ventoy_img_list;
(void)ctxt;
@@ -886,13 +1075,22 @@ static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int arg
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s {var}", cmd_raw_name);
}
name = grub_env_get("chosen");
id = grub_env_get("chosen");
pos = grub_strstr(id, "VID_");
if (pos)
{
img_id = (int)grub_strtoul(pos + 4, NULL, 10);
}
else
{
img_id = (int)grub_strtoul(id, NULL, 10);
}
while (cur)
{
if (0 == grub_strcmp(name, cur->name))
if (img_id == cur->id)
{
grub_env_set(args[0], cur->path);
break;
}
cur = cur->next;
@@ -903,6 +1101,8 @@ static grub_err_t ventoy_cmd_chosen_img_path(grub_extcmd_context_t ctxt, int arg
return grub_error(GRUB_ERR_BAD_ARGUMENT, "No such image");
}
grub_env_set(args[0], cur->path);
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
@@ -1138,6 +1338,193 @@ static grub_err_t ventoy_cmd_add_replace_file(grub_extcmd_context_t ctxt, int ar
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
static grub_err_t ventoy_cmd_dump_menu(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
if (argc == 0)
{
grub_printf("List Mode: CurLen:%d MaxLen:%u\n", g_list_script_pos, VTOY_MAX_SCRIPT_BUF);
grub_printf("%s", g_list_script_buf);
}
else
{
grub_printf("Tree Mode: CurLen:%d MaxLen:%u\n", g_tree_script_pos, VTOY_MAX_SCRIPT_BUF);
grub_printf("%s", g_tree_script_buf);
}
return 0;
}
static grub_err_t ventoy_cmd_dump_auto_install(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
ventoy_plugin_dump_auto_install();
return 0;
}
static grub_err_t ventoy_cmd_check_mode(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;
if (argc != 1)
{
return 1;
}
if (args[0][0] == '0')
{
return g_ventoy_memdisk_mode ? 0 : 1;
}
else if (args[0][0] == '1')
{
return g_ventoy_iso_raw ? 0 : 1;
}
else if (args[0][0] == '2')
{
return g_ventoy_iso_uefi_drv ? 0 : 1;
}
return 1;
}
static grub_err_t ventoy_cmd_dynamic_menu(grub_extcmd_context_t ctxt, int argc, char **args)
{
static int configfile_mode = 0;
char memfile[128] = {0};
(void)ctxt;
(void)argc;
(void)args;
/*
* args[0]: 0:normal 1:configfile
* args[1]: 0:list_buf 1:tree_buf
*/
if (argc != 2)
{
debug("Invlaid argc %d\n", argc);
return 0;
}
if (args[0][0] == '0')
{
if (args[1][0] == '0')
{
grub_script_execute_sourcecode(g_list_script_buf);
}
else
{
grub_script_execute_sourcecode(g_tree_script_buf);
}
}
else
{
if (configfile_mode)
{
debug("Now already in F3 mode %d\n", configfile_mode);
return 0;
}
if (args[1][0] == '0')
{
grub_snprintf(memfile, sizeof(memfile), "configfile mem:0x%llx:size:%d",
(ulonglong)(ulong)g_list_script_buf, g_list_script_pos);
}
else
{
g_ventoy_last_entry = -1;
grub_snprintf(memfile, sizeof(memfile), "configfile mem:0x%llx:size:%d",
(ulonglong)(ulong)g_tree_script_buf, g_tree_script_pos);
}
configfile_mode = 1;
grub_script_execute_sourcecode(memfile);
configfile_mode = 0;
}
return 0;
}
static grub_err_t ventoy_cmd_find_bootable_hdd(grub_extcmd_context_t ctxt, int argc, char **args)
{
int id = 0;
int find = 0;
grub_disk_t disk;
const char *isopath = NULL;
char hdname[32];
ventoy_mbr_head mbr;
(void)ctxt;
(void)argc;
if (argc != 1)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s variable\n", cmd_raw_name);
}
isopath = grub_env_get("iso_path");
if (!isopath)
{
debug("isopath is null %p\n", isopath);
return 0;
}
debug("isopath is %s\n", isopath);
for (id = 0; id < 30 && (find == 0); id++)
{
grub_snprintf(hdname, sizeof(hdname), "hd%d,", id);
if (grub_strstr(isopath, hdname))
{
debug("skip %s ...\n", hdname);
continue;
}
grub_snprintf(hdname, sizeof(hdname), "hd%d", id);
disk = grub_disk_open(hdname);
if (!disk)
{
debug("%s not exist\n", hdname);
break;
}
grub_memset(&mbr, 0, sizeof(mbr));
if (0 == grub_disk_read(disk, 0, 0, 512, &mbr))
{
if (mbr.Byte55 == 0x55 && mbr.ByteAA == 0xAA)
{
if (mbr.PartTbl[0].Active == 0x80 || mbr.PartTbl[1].Active == 0x80 ||
mbr.PartTbl[2].Active == 0x80 || mbr.PartTbl[3].Active == 0x80)
{
grub_env_set(args[0], hdname);
find = 1;
}
}
debug("%s is %s\n", hdname, find ? "bootable" : "NOT bootable");
}
else
{
debug("read %s failed\n", hdname);
}
grub_disk_close(disk);
}
return 0;
}
grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...)
{
va_list ap;
@@ -1189,6 +1576,10 @@ static int ventoy_env_init(void)
char buf[64];
grub_env_set("vtdebug_flag", "");
grub_env_export("vtdebug_flag");
g_tree_script_buf = grub_malloc(VTOY_MAX_SCRIPT_BUF);
g_list_script_buf = grub_malloc(VTOY_MAX_SCRIPT_BUF);
ventoy_filt_register(0, ventoy_wrapper_open);
@@ -1219,6 +1610,11 @@ 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_cpio", ventoy_cmd_load_cpio, 0, NULL, "", "", NULL },
{ "vt_find_first_bootable_hd", ventoy_cmd_find_bootable_hdd, 0, NULL, "", "", NULL },
{ "vt_dump_menu", ventoy_cmd_dump_menu, 0, NULL, "", "", NULL },
{ "vt_dynamic_menu", ventoy_cmd_dynamic_menu, 0, NULL, "", "", NULL },
{ "vt_check_mode", ventoy_cmd_check_mode, 0, NULL, "", "", NULL },
{ "vt_dump_auto_install", ventoy_cmd_dump_auto_install, 0, NULL, "", "", NULL },
{ "vt_is_udf", ventoy_cmd_is_udf, 0, NULL, "", "", NULL },
{ "vt_file_size", ventoy_cmd_file_size, 0, NULL, "", "", NULL },

View File

@@ -21,10 +21,13 @@
#ifndef __VENTOY_DEF_H__
#define __VENTOY_DEF_H__
#define VTOY_MAX_SCRIPT_BUF (4 * 1024 * 1024)
#define JSON_SUCCESS 0
#define JSON_FAILED 1
#define JSON_NOT_FOUND 2
#define ulong unsigned long
#define ulonglong unsigned long long
#define vtoy_to_upper(c) (((char)(c) >= 'a' && (char)(c) <= 'z') ? ((char)(c) - 'a' + 'A') : (char)(c))
@@ -115,11 +118,15 @@ typedef struct ventoy_udf_override
#pragma pack()
typedef struct img_info
{
char path[512];
char name[256];
int id;
grub_uint64_t size;
int select;
void *parent;
struct img_info *next;
struct img_info *prev;
@@ -130,8 +137,19 @@ typedef struct img_iterator_node
struct img_iterator_node *next;
img_info **tail;
char dir[400];
int dirlen;
int isocnt;
int done;
int select;
struct img_iterator_node *parent;
struct img_iterator_node *firstchild;
void *firstiso;
}img_iterator_node;
typedef struct initrd_info
{
char name[256];
@@ -400,7 +418,7 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
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);
int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name);
grub_file_t ventoy_grub_file_open(enum grub_file_type type, const char *fmt, ...);
int ventoy_is_file_exist(const char *fmt, ...);
int ventoy_fill_data(grub_uint32_t buflen, char *buffer);
@@ -504,5 +522,54 @@ static inline int ventoy_is_word_end(int c)
return (c == 0 || c == ',' || ventoy_isspace(c));
}
#pragma pack(1)
typedef struct ventoy_part_table
{
grub_uint8_t Active; // 0x00 0x80
grub_uint8_t StartHead;
grub_uint16_t StartSector : 6;
grub_uint16_t StartCylinder : 10;
grub_uint8_t FsFlag;
grub_uint8_t EndHead;
grub_uint16_t EndSector : 6;
grub_uint16_t EndCylinder : 10;
grub_uint32_t StartSectorId;
grub_uint32_t SectorCount;
}ventoy_part_table;
typedef struct ventoy_mbr_head
{
grub_uint8_t BootCode[446];
ventoy_part_table PartTbl[4];
grub_uint8_t Byte55;
grub_uint8_t ByteAA;
}ventoy_mbr_head;
#pragma pack()
typedef struct install_template
{
char isopath[256];
char templatepath[256];
struct install_template *next;
}install_template;
extern int g_ventoy_last_entry;
extern int g_ventoy_memdisk_mode;
extern int g_ventoy_iso_raw;
extern int g_ventoy_iso_uefi_drv;
int ventoy_cmp_img(img_info *img1, img_info *img2);
void ventoy_swap_img(img_info *img1, img_info *img2);
char * ventoy_plugin_get_install_template(const char *isopath);
void ventoy_plugin_dump_auto_install(void);
int ventoy_fill_windows_rtdata(void *buf, char *isopath);
#endif /* __VENTOY_DEF_H__ */

View File

@@ -588,7 +588,7 @@ static void ventoy_cpio_newc_fill_int(grub_uint32_t value, char *buf, int buflen
}
}
int ventoy_cpio_newc_fill_head(void *buf, int filesize, void *filedata, const char *name)
int ventoy_cpio_newc_fill_head(void *buf, int filesize, const void *filedata, const char *name)
{
int namelen = 0;
int headlen = 0;
@@ -852,18 +852,22 @@ grub_err_t ventoy_cmd_linux_locate_initrd(grub_extcmd_context_t ctxt, int argc,
grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args)
{
grub_uint8_t *buf;
char *template_file = NULL;
char *template_buf = NULL;
grub_uint8_t *buf = NULL;
grub_uint32_t mod;
grub_uint32_t headlen;
grub_uint32_t initrd_head_len;
grub_uint32_t padlen;
grub_uint32_t img_chunk_size;
grub_uint32_t template_size = 0;
grub_file_t file;
grub_file_t scriptfile;
(void)ctxt;
(void)argc;
if (argc != 1)
if (argc != 3)
{
return grub_error(GRUB_ERR_BAD_ARGUMENT, "Usage: %s cpiofile\n", cmd_raw_name);
}
@@ -888,7 +892,30 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
g_ventoy_cpio_size = 0;
}
g_ventoy_cpio_buf = grub_malloc(file->size + 4096 + img_chunk_size);
template_file = ventoy_plugin_get_install_template(args[1]);
if (template_file)
{
debug("auto install template: <%s>\n", template_file);
scriptfile = ventoy_grub_file_open(VENTOY_FILE_TYPE, "%s%s", args[2], template_file);
if (scriptfile)
{
debug("auto install script size %d\n", (int)scriptfile->size);
template_size = scriptfile->size;
template_buf = grub_malloc(template_size);
if (template_buf)
{
grub_file_read(scriptfile, template_buf, template_size);
}
grub_file_close(scriptfile);
}
else
{
debug("Failed to open install script %s%s\n", args[2], template_file);
}
}
g_ventoy_cpio_buf = grub_malloc(file->size + 4096 + template_size + img_chunk_size);
if (NULL == g_ventoy_cpio_buf)
{
grub_file_close(file);
@@ -910,6 +937,12 @@ grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **arg
headlen = ventoy_cpio_newc_fill_head(buf, img_chunk_size, g_img_chunk_list.chunk, "ventoy/ventoy_image_map");
buf += headlen + ventoy_align(img_chunk_size, 4);
if (template_buf)
{
headlen = ventoy_cpio_newc_fill_head(buf, template_size, template_buf, "ventoy/autoinstall");
buf += headlen + ventoy_align(template_size, 4);
}
/* step2: insert os param to cpio */
headlen = ventoy_cpio_newc_fill_head(buf, 0, NULL, "ventoy/ventoy_os_param");
padlen = sizeof(ventoy_os_param);

View File

@@ -38,6 +38,8 @@
GRUB_MOD_LICENSE ("GPLv3+");
static install_template *g_install_template_head = NULL;
static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
{
const char *value;
@@ -46,7 +48,15 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
value = vtoy_json_get_string_ex(json->pstChild, "file");
if (value)
{
grub_snprintf(filepath, sizeof(filepath), "%s/ventoy/%s", isodisk, value);
if (value[0] == '/')
{
grub_snprintf(filepath, sizeof(filepath), "%s%s", isodisk, value);
}
else
{
grub_snprintf(filepath, sizeof(filepath), "%s/ventoy/%s", isodisk, value);
}
if (ventoy_is_file_exist(filepath) == 0)
{
debug("Theme file %s does not exist\n", filepath);
@@ -67,9 +77,67 @@ static int ventoy_plugin_theme_entry(VTOY_JSON *json, const char *isodisk)
return 0;
}
static int ventoy_plugin_auto_install_entry(VTOY_JSON *json, const char *isodisk)
{
const char *iso = NULL;
const char *script = NULL;
VTOY_JSON *pNode = NULL;
install_template *node = NULL;
install_template *next = NULL;
(void)isodisk;
if (json->enDataType != JSON_TYPE_ARRAY)
{
debug("Not array %d\n", json->enDataType);
return 0;
}
if (g_install_template_head)
{
for (node = g_install_template_head; node; node = next)
{
next = node->next;
grub_free(node);
}
g_install_template_head = NULL;
}
for (pNode = json->pstChild; pNode; pNode = pNode->pstNext)
{
iso = vtoy_json_get_string_ex(pNode->pstChild, "image");
if (iso && iso[0] == '/')
{
script = vtoy_json_get_string_ex(pNode->pstChild, "template");
if (script && script[0] == '/')
{
node = grub_zalloc(sizeof(install_template));
if (node)
{
grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso);
grub_snprintf(node->templatepath, sizeof(node->templatepath), "%s", script);
if (g_install_template_head)
{
node->next = g_install_template_head;
}
g_install_template_head = node;
}
}
}
}
return 0;
}
static plugin_entry g_plugin_entries[] =
{
{ "theme", ventoy_plugin_theme_entry },
{ "auto_install", ventoy_plugin_auto_install_entry },
};
static int ventoy_parse_plugin_config(VTOY_JSON *json, const char *isodisk)
@@ -149,3 +217,33 @@ grub_err_t ventoy_cmd_load_plugin(grub_extcmd_context_t ctxt, int argc, char **a
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}
void ventoy_plugin_dump_auto_install(void)
{
install_template *node = NULL;
for (node = g_install_template_head; node; node = node->next)
{
grub_printf("IMAGE:<%s>\n", node->isopath);
grub_printf("SCRIPT:<%s>\n\n", node->templatepath);
}
return;
}
char * ventoy_plugin_get_install_template(const char *isopath)
{
install_template *node = NULL;
for (node = g_install_template_head; node; node = node->next)
{
if (grub_strcmp(node->isopath, isopath) == 0)
{
return node->templatepath;
}
}
return NULL;
}

View File

@@ -440,14 +440,14 @@ static int ventoy_cat_exe_file_data(grub_uint32_t exe_len, grub_uint8_t *exe_dat
jump_align = ventoy_align(jump_len, 16);
g_wim_data.jump_exe_len = jump_len;
g_wim_data.bin_raw_len = jump_align + sizeof(ventoy_os_param) + exe_len;
g_wim_data.bin_raw_len = jump_align + sizeof(ventoy_os_param) + sizeof(ventoy_windows_data) + exe_len;
g_wim_data.bin_align_len = ventoy_align(g_wim_data.bin_raw_len, 2048);
g_wim_data.jump_bin_data = grub_malloc(g_wim_data.bin_align_len);
if (g_wim_data.jump_bin_data)
{
grub_memcpy(g_wim_data.jump_bin_data, jump_data, jump_len);
grub_memcpy(g_wim_data.jump_bin_data + jump_align + sizeof(ventoy_os_param), exe_data, exe_len);
grub_memcpy(g_wim_data.jump_bin_data + jump_align + sizeof(ventoy_os_param) + sizeof(ventoy_windows_data), exe_data, exe_len);
}
debug("jump_exe_len:%u bin_raw_len:%u bin_align_len:%u\n",
@@ -456,7 +456,35 @@ static int ventoy_cat_exe_file_data(grub_uint32_t exe_len, grub_uint8_t *exe_dat
return 0;
}
static int ventoy_update_before_chain(ventoy_os_param *param)
int ventoy_fill_windows_rtdata(void *buf, char *isopath)
{
char *pos = NULL;
char *script = NULL;
ventoy_windows_data *data = (ventoy_windows_data *)buf;
grub_memset(data, 0, sizeof(ventoy_windows_data));
pos = grub_strstr(isopath, "/");
if (!pos)
{
return 1;
}
script = ventoy_plugin_get_install_template(pos);
if (script)
{
debug("auto install script <%s>\n", script);
grub_snprintf(data->auto_install_script, sizeof(data->auto_install_script) - 1, "%s", script);
}
else
{
debug("auto install script not found %p\n", pos);
}
return 0;
}
static int ventoy_update_before_chain(ventoy_os_param *param, char *isopath)
{
grub_uint32_t jump_align = 0;
wim_lookup_entry *meta_look = NULL;
@@ -469,6 +497,7 @@ static int ventoy_update_before_chain(ventoy_os_param *param)
if (g_wim_data.jump_bin_data)
{
grub_memcpy(g_wim_data.jump_bin_data + jump_align, param, sizeof(ventoy_os_param));
ventoy_fill_windows_rtdata(g_wim_data.jump_bin_data + jump_align + sizeof(ventoy_os_param), isopath);
}
grub_crypto_hash(GRUB_MD_SHA1, g_wim_data.bin_hash.sha1, g_wim_data.jump_bin_data, g_wim_data.bin_raw_len);
@@ -878,7 +907,7 @@ grub_err_t ventoy_cmd_windows_chain_data(grub_extcmd_context_t ctxt, int argc, c
if (g_wim_data.jump_bin_data && g_wim_data.new_meta_data)
{
ventoy_update_before_chain(&(chain->os_param));
ventoy_update_before_chain(&(chain->os_param), args[0]);
}
/* part 2: chain head */

View File

@@ -104,6 +104,15 @@ typedef struct ventoy_os_param
grub_uint8_t reserved[31];
}ventoy_os_param;
typedef struct ventoy_windows_data
{
char auto_install_script[384];
grub_uint8_t reserved[128];
}ventoy_windows_data;
#pragma pack()
// compile assert check : sizeof(ventoy_os_param) must be 512

View File

@@ -0,0 +1,48 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtlog "######### $0 $* ############"
if is_ventoy_hook_finished; then
exit 0
fi
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
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"
fi
# OK finish
set_ventoy_hook_finish

View File

@@ -19,16 +19,21 @@
. $VTOY_PATH/hook/ventoy-os-lib.sh
# some archlinux initramfs doesn't contain device-mapper udev rules file
ARCH_UDEV_DIR=$(ventoy_get_udev_conf_dir)
if [ -s "$ARCH_UDEV_DIR/13-dm-disk.rules" ]; then
echo 'dm-disk rule exist' >> $VTLOG
if $GREP -q '^"$mount_handler"' /init; then
echo 'use mount_handler ...' >> $VTLOG
$SED "/^\"\$mount_handler\"/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/arch/ventoy-disk.sh \"\$archisodevice\"" -i /init
else
echo 'Copy dm-disk rule file' >> $VTLOG
$CAT $VTOY_PATH/hook/default/13-dm-disk.rules > "$ARCH_UDEV_DIR/13-dm-disk.rules"
# some archlinux initramfs doesn't contain device-mapper udev rules file
ARCH_UDEV_DIR=$(ventoy_get_udev_conf_dir)
if [ -s "$ARCH_UDEV_DIR/13-dm-disk.rules" ]; then
echo 'dm-disk rule exist' >> $VTLOG
else
echo 'Copy dm-disk rule file' >> $VTLOG
$CAT $VTOY_PATH/hook/default/13-dm-disk.rules > "$ARCH_UDEV_DIR/13-dm-disk.rules"
fi
# use default proc
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k"
fi
# use default proc
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k"

View File

@@ -0,0 +1,38 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtlog "####### $0 $* ########"
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2"
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,20 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
$SED "/for .*\$DEVICES/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/berry/ventoy-disk.sh" -i /init

View File

@@ -23,6 +23,12 @@ if [ -e /init ] && $GREP -q '^mountroot$' /init; then
$SED "/^mountroot$/i\\$BUSYBOX_PATH/sh $VTOY_PATH/hook/debian/disk_mount_hook.sh" -i /init
$SED "/^mountroot$/i\\export LIVEMEDIA=/dev/mapper/ventoy" -i /init
$SED "/^mountroot$/i\\export LIVE_MEDIA=/dev/mapper/ventoy" -i /init
if $GREP -q 'live-media=' /proc/cmdline; then
if [ -f /scripts/casper ] && $GREP -q '^ *LIVEMEDIA=' /scripts/casper; then
$SED "s#^ *LIVEMEDIA=.*#LIVEMEDIA=/dev/mapper/ventoy#" -i /scripts/casper
fi
fi
elif [ -e /init ] && $GREP -q '/start-udev$' /init; then
echo "Here use notify ..." >> $VTLOG
@@ -35,3 +41,15 @@ else
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/debian/udev_disk_hook.sh %k"
fi
if [ -f $VTOY_PATH/autoinstall ]; then
echo "Do auto install ..." >> $VTLOG
if $GREP -q "^mount /proc$" /init; then
$SED "/^mount \/proc/a export file=$VTOY_PATH/autoinstall; export auto='true'; export priority='critical'" -i /init
fi
fi

View File

@@ -0,0 +1,26 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE root=live:/dev/mapper/ventoy#" -i /lib/dracut-lib.sh
ventoy_set_inotify_script gobo/ventoy-inotifyd-hook.sh
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/gobo/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/01-ventoy-inotifyd-start.sh

View File

@@ -0,0 +1,47 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished; then
exit 0
fi
vtlog "##### INOTIFYD: $2/$3 is created ..."
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
if is_inotify_ventoy_part $3; then
vtlog "find ventoy partition $3 ..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3 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})
#
# if [ "$vtDM" = "dm-0" ]; then
# vtlog "This is dm-0, OK ..."
# else
# vtlog "####### This is $vtDM ####### this is abnormal ..."
# ventoy_swap_device /dev/dm-0 /dev/$vtDM
# fi
set_ventoy_hook_finish
fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,31 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtHook=$($CAT $VTOY_PATH/inotifyd-hook-script.txt)
vtdisk=$(get_ventoy_disk_name)
if [ "$vtdisk" = "unknown" ]; then
vtlog "... start inotifyd listen $vtHook ..."
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $vtHook /dev:n 2>&- &
else
vtlog "... $vtdisk already exist ..."
$BUSYBOX_PATH/sh $vtHook n /dev "${vtdisk#/dev/}2"
fi

View File

@@ -0,0 +1,42 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
if is_ventoy_hook_finished; then
exit 0
fi
vtlog "##### INOTIFYD: $2/$3 is created ..."
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
if is_inotify_ventoy_part $3; then
vtlog "find ventoy partition ..."
$BUSYBOX_PATH/sh $VTOY_PATH/hook/default/udev_disk_hook.sh $3
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 "This is $vtDM ..."
set_ventoy_hook_finish
fi
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,25 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$BUSYBOX_PATH/mkdir /dev
$BUSYBOX_PATH/mknode -m 0666 /dev/null c 1 3
$BUSYBOX_PATH/nohup $VTOY_PATH/hook/guix/ventoy-waitdev.sh &

View File

@@ -0,0 +1,37 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtlog "####### $0 $* ########"
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
while ! [ -e /dev/null ]; do
echo 'xxxxxxxxxx'
echo 'xxxxxxxxxx' > /dev/console
sleep 1
done
vtlog "... start inotifyd listen $vtHook ..."
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $VTOY_PATH/hook/guix/ventoy-disk.sh /dev:n 2>&- &
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,50 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtlog "####### $0 $* ########"
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
if is_ventoy_hook_finished; then
exit 0
fi
wait_for_usb_disk_ready
vtdiskname=$(get_ventoy_disk_name)
if [ "$vtdiskname" = "unknown" ]; then
vtlog "ventoy disk not found"
PATH=$VTPATH_OLD
exit 0
fi
ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2"
blkdev_num=$(dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
vtlog "link /dev/$vtDM $VTOY_DM_PATH"
ln -s /dev/$vtDM $VTOY_DM_PATH
set_ventoy_hook_finish
PATH=$VTPATH_OLD

View File

@@ -0,0 +1,22 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. $VTOY_PATH/hook/ventoy-os-lib.sh
$SED "/find_media$/i $BUSYBOX_PATH/sh $VTOY_PATH/hook/nutyx/ventoy-disk.sh" -i /init

View File

@@ -22,10 +22,30 @@
#ventoy_systemd_udevd_work_around
#ventoy_add_udev_rule "$VTOY_PATH/hook/default/udev_disk_hook.sh %k noreplace"
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE inst.stage2=hd:/dev/dm-0#" -i /lib/dracut-lib.sh
if [ -f $VTOY_PATH/autoinstall ]; then
VTKS="inst.ks=file:$VTOY_PATH/autoinstall"
else
for vtParam in $($CAT /proc/cmdline); do
if echo $vtParam | $GREP -q 'inst.ks=hd:LABEL='; then
vtRawKs=$(echo $vtParam | $AWK -F: '{print $NF}')
VTKS="inst.ks=hd:/dev/dm-0:$vtRawKs"
break
fi
done
fi
echo "VTKS=$VTKS" >> $VTLOG
if $GREP -q 'root=live' /proc/cmdline; then
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE root=live:/dev/dm-0 $VTKS#" -i /lib/dracut-lib.sh
else
$SED "s#printf\(.*\)\$CMDLINE#printf\1\$CMDLINE inst.stage2=hd:/dev/dm-0 $VTKS#" -i /lib/dracut-lib.sh
fi
ventoy_set_inotify_script rhel7/ventoy-inotifyd-hook.sh
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/default/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/01-ventoy-inotifyd-start.sh
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-inotifyd-start.sh /lib/dracut/hooks/pre-udev/01-ventoy-inotifyd-start.sh
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/rhel7/ventoy-timeout.sh /lib/dracut/hooks/initqueue/timeout/01-ventoy-timeout.sh
# suppress write protected mount warning
if [ -e /usr/sbin/anaconda-diskroot ]; then

View File

@@ -41,6 +41,9 @@ if is_inotify_ventoy_part $3; then
ventoy_swap_device /dev/dm-0 /dev/$vtDM
fi
vtlog "set anaconda-diskroot ..."
/sbin/initqueue --settled --onetime --name anaconda-diskroot anaconda-diskroot /dev/dm-0
set_ventoy_hook_finish
fi

View File

@@ -0,0 +1,31 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtHook=$($CAT $VTOY_PATH/inotifyd-hook-script.txt)
vtdisk=$(get_ventoy_disk_name)
if [ "$vtdisk" = "unknown" ]; then
vtlog "... start inotifyd listen $vtHook ..."
$BUSYBOX_PATH/nohup $VTOY_PATH/tool/inotifyd $vtHook /dev:n 2>&- &
else
vtlog "... $vtdisk already exist ..."
$BUSYBOX_PATH/sh $vtHook n /dev "${vtdisk#/dev/}2"
fi

View File

@@ -0,0 +1,32 @@
#!/ventoy/busybox/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/>.
#
#************************************************************************************
. /ventoy/hook/ventoy-hook-lib.sh
vtlog "##### $0 $* ..."
VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
blkdev_num=$(dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
vtDM=$(ventoy_find_dm_id ${blkdev_num})
vtlog "diskroot $vtDM ..."
/sbin/initqueue --settled --onetime --name anaconda-diskroot anaconda-diskroot /dev/$vtDM
PATH=$VTPATH_OLD

View File

@@ -19,6 +19,17 @@
. $VTOY_PATH/hook/ventoy-os-lib.sh
ventoy_systemd_udevd_work_around
if [ -f $VTOY_PATH/autoinstall ]; then
if [ -f /linuxrc.config ]; then
echo "AutoYaST: file:///ventoy/autoinstall" >> /info-ventoy
$SED "1 iinfo: file:/info-ventoy" -i /linuxrc.config
fi
fi
#echo "Exec: /bin/sh $VTOY_PATH/hook/suse/cdrom-hook.sh" >> /info-ventoy
#echo "install: hd:/?device=/dev/mapper/ventoy" >> /info-ventoy
#$SED "1 iinfo: file:/info-ventoy" -i /linuxrc.config
ventoy_systemd_udevd_work_around
ventoy_add_udev_rule "$VTOY_PATH/hook/suse/udev_disk_hook.sh %k"

View File

@@ -165,6 +165,25 @@ ventoy_get_os_type() {
echo 'arch'; return
fi
if $GREP -q 'berry ' /proc/version; then
echo 'berry'; return
fi
if $GREP -q 'Gobo ' /proc/version; then
echo 'gobo'; return
fi
if $GREP -q 'NuTyX' /proc/version; then
echo 'nutyx'; return
fi
if [ -d /gnu ]; then
vtLineNum=$($FIND /gnu/ -name guix | $BUSYBOX_PATH/wc -l)
if [ $vtLineNum -gt 0 ]; then
echo 'guix'; return
fi
fi
echo "default"
}

View File

@@ -0,0 +1,5 @@
For Ventoy2Disk.exe (Windows) or Ventoy2Disk.sh (Linux).
You should download the install package, decompress it, and run the exe/sh there.
They should NOT be run in the source tree(INSTALL directory).

Binary file not shown.

Binary file not shown.

View File

@@ -26,20 +26,29 @@ echo ''
vtdebug "############# Ventoy2Disk $0 ################"
if [ "$1" = "-i" ]; then
MODE="install"
elif [ "$1" = "-I" ]; then
MODE="install"
FORCE="Y"
elif [ "$1" = "-u" ]; then
MODE="update"
else
print_usage
cd $OLDDIR
exit 1
fi
while [ -n "$1" ]; do
if [ "$1" = "-i" ]; then
MODE="install"
elif [ "$1" = "-I" ]; then
MODE="install"
FORCE="Y"
elif [ "$1" = "-u" ]; then
MODE="update"
elif [ "$1" = "-s" ]; then
SECUREBOOT="YES"
else
if ! [ -b "$1" ]; then
print_usage
cd $OLDDIR
exit 1
fi
DISK=$1
fi
shift
done
if ! [ -b "$2" ]; then
if [ -z "$MODE" ]; then
print_usage
cd $OLDDIR
exit 1
@@ -56,6 +65,15 @@ fi
vtdebug "MODE=$MODE FORCE=$FORCE"
if ! [ -f ./boot/boot.img ]; then
if [ -d ./grub ]; then
vterr "Don't run me here, please download the released install package, and run there."
else
vterr "Please run under the right directory!"
fi
exit 1
fi
#decompress tool
cd tool
chmod +x ./xzcat
@@ -76,8 +94,6 @@ if ! check_tool_work_ok; then
fi
DISK=$2
if ! [ -b "$DISK" ]; then
vterr "Disk $DISK does not exist"
cd $OLDDIR
@@ -92,7 +108,7 @@ if [ -e /sys/class/block/${DISK#/dev/}/start ]; then
fi
grep "^$DISK" /proc/mounts | while read mtline; do
mtpnt=$(echo $mtline | awk '{print $2}')
mtpnt=$(echo $mtline | awk '{print $DISK}')
vtdebug "Trying to umount $mtpnt ..."
umount $mtpnt >/dev/null 2>&1
done
@@ -195,6 +211,7 @@ if [ "$MODE" = "install" ]; then
chmod +x ./tool/vtoy_gen_uuid
vtinfo "writing data to disk ..."
dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=446
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start_sector
@@ -205,7 +222,31 @@ if [ "$MODE" = "install" ]; then
#disk signature
./tool/vtoy_gen_uuid | dd status=none conv=fsync of=${DISK} skip=12 seek=440 bs=1 count=4
vtinfo "sync data ..."
sync
vtinfo "esp partition processing ..."
if [ "$SECUREBOOT" != "YES" ]; then
mkdir ./tmp_mnt
vtdebug "mounting part2 ...."
for tt in 1 2 3; do
if mount ${DISK}2 ./tmp_mnt; then
vtdebug "mounting part2 success"
break
fi
sleep 2
done
rm -f ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
rm -f ./tmp_mnt/EFI/BOOT/grubx64.efi
rm -f ./tmp_mnt/EFI/BOOT/MokManager.efi
mv ./tmp_mnt/EFI/BOOT/grubx64_real.efi ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
umount ./tmp_mnt
rm -rf ./tmp_mnt
fi
echo ""
vtinfo "Install Ventoy to $DISK successfully finished."
@@ -248,6 +289,27 @@ else
./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start
sync
if [ "$SECUREBOOT" != "YES" ]; then
mkdir ./tmp_mnt
vtdebug "mounting part2 ...."
for tt in 1 2 3; do
if mount ${DISK}2 ./tmp_mnt; then
vtdebug "mounting part2 success"
break
fi
sleep 2
done
rm -f ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
rm -f ./tmp_mnt/EFI/BOOT/grubx64.efi
rm -f ./tmp_mnt/EFI/BOOT/MokManager.efi
mv ./tmp_mnt/EFI/BOOT/grubx64_real.efi ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
umount ./tmp_mnt
rm -rf ./tmp_mnt
fi
echo ""
vtinfo "Update Ventoy to $DISK successfully finished."

View File

@@ -16,6 +16,26 @@
#
#************************************************************************************
function ventoy_power {
echo '<1> Reboot'
echo '<2> Halt'
echo '<0> Return to menu'
echo -e '\nPlease enter your choice:'
unset vtOpt
read vtOpt
if [ "$vtOpt" = "1" ]; then
echo -e '\n\nSystem is rebooting ... \n'
sleep 1
reboot
elif [ "$vtOpt" = "2" ]; then
echo -e '\n\nSystem is halting ... \n'
sleep 1
halt
fi
}
function get_os_type {
set vtoy_os=Linux
for file in "efi/microsoft" "sources/boot.wim" "boot/bcd" "bootmgr.efi" "boot/etfsboot.com"; do
@@ -88,6 +108,13 @@ function distro_specify_initrd_file {
function distro_specify_initrd_file_phase2 {
if [ -f (loop)/boot/initrd.img ]; then
vt_linux_specify_initrd_file /boot/initrd.img
elif [ -f (loop)/Setup/initrd.gz ]; then
vt_linux_specify_initrd_file /Setup/initrd.gz
elif [ -f (loop)/isolinux/initramfs ]; then
vt_linux_specify_initrd_file /isolinux/initramfs
elif [ -f (loop)/boot/iniramfs.igz ]; then
vt_linux_specify_initrd_file /boot/iniramfs.igz
fi
}
@@ -119,15 +146,15 @@ function uefi_windows_menu_func {
function uefi_linux_menu_func {
if [ "$ventoy_compatible" = "NO" ]; then
vt_load_cpio ${vtoy_path}/ventoy.cpio
vt_load_cpio ${vtoy_path}/ventoy.cpio $2 $1
vt_linux_clear_initrd
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
for file in "boot/grub/grub.cfg" "EFI/BOOT/grub.cfg" "EFI/boot/grub.cfg" "efi/boot/grub.cfg" "EFI/BOOT/BOOTX64.conf" "/grub/grub.cfg"; do
if [ -e (loop)/$file ]; then
vt_linux_parse_initrd_grub file (loop)/$file
fi
done
@@ -184,7 +211,7 @@ function uefi_iso_menu_func {
if [ -n "$vtisouefi" ]; then
set LoadIsoEfiDriver=on
unset vtisouefi
elif [ -n "$VTOY_ISO_UEFI_DRV" ]; then
elif vt_check_mode 2; then
set LoadIsoEfiDriver=on
else
unset LoadIsoEfiDriver
@@ -212,7 +239,7 @@ function uefi_iso_menu_func {
if [ -n "$vtcompat" ]; then
set ventoy_compatible=YES
unset vtcompat
elif [ -n "$VTOY_ISO_RAW" ]; then
elif vt_check_mode 1; then
set ventoy_compatible=YES
else
vt_check_compatible (loop)
@@ -227,9 +254,9 @@ function uefi_iso_menu_func {
set ventoy_compatible=YES
fi
uefi_windows_menu_func $1
uefi_windows_menu_func $1 ${chosen_path}
else
uefi_linux_menu_func $1
uefi_linux_menu_func $1 ${chosen_path}
fi
terminal_output gfxterm
@@ -247,8 +274,6 @@ function uefi_iso_memdisk {
}
function legacy_windows_menu_func {
vt_windows_reset
@@ -279,8 +304,7 @@ function legacy_windows_menu_func {
function legacy_linux_menu_func {
if [ "$ventoy_compatible" = "NO" ]; then
vt_load_cpio $vtoy_path/ventoy.cpio
vt_load_cpio $vtoy_path/ventoy.cpio $2 $1
vt_linux_clear_initrd
@@ -356,7 +380,7 @@ function legacy_iso_menu_func {
if [ -n "$vtcompat" ]; then
set ventoy_compatible=YES
unset vtcompat
elif [ -n "$VTOY_ISO_RAW" ]; then
elif vt_check_mode 1; then
set ventoy_compatible=YES
else
vt_check_compatible (loop)
@@ -371,9 +395,9 @@ function legacy_iso_menu_func {
set ventoy_compatible=YES
fi
legacy_windows_menu_func $1
legacy_windows_menu_func $1 ${chosen_path}
else
legacy_linux_menu_func $1
legacy_linux_menu_func $1 ${chosen_path}
fi
}
@@ -386,6 +410,22 @@ function legacy_iso_memdisk {
boot
}
function common_menuentry {
if [ "$grub_platform" = "pc" ]; then
if vt_check_mode 0; then
legacy_iso_memdisk $iso_path
else
legacy_iso_menu_func $iso_path
fi
else
if vt_check_mode 0; then
uefi_iso_memdisk $iso_path
else
uefi_iso_menu_func $iso_path
fi
fi
}
#############################################################
#############################################################
@@ -395,7 +435,13 @@ function legacy_iso_memdisk {
#############################################################
#############################################################
set VENTOY_VERSION="1.0.08b1"
set VENTOY_VERSION="1.0.09"
# Default menu display mode, you can change it as you want.
# 0: List mode
# 1: TreeView mode
set VTOY_DEFAULT_MENU_MODE=0
#disable timeout
unset timeout
@@ -404,6 +450,22 @@ set VTOY_MEM_DISK_STR="MEMDISK"
set VTOY_ISO_RAW_STR="ISO RAW"
set VTOY_ISO_UEFI_DRV_STR="UEFI FS"
set VTOY_F2_CMD="ventoy_power"
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"
else
set VTOY_F3_CMD="vt_dynamic_menu 1 0"
set VTOY_HOTKEY_TIP="F1:Memdisk F2:Power F3:ListView"
fi
if [ "$grub_platform" = "pc" ]; then
set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION BIOS www.ventoy.net"
else
set VTOY_TEXT_MENU_VER="Ventoy $VENTOY_VERSION UEFI www.ventoy.net"
fi
vt_device $root vtoy_dev
if [ "$vtoy_dev" = "tftp" ]; then
@@ -443,33 +505,16 @@ terminal_output gfxterm
set ventoy_img_count=0
vt_list_img $iso_path ventoy_img_count
#Dynamic menu for every iso file
if vt_cmp $ventoy_img_count ne 0; then
set imgid=0
while vt_cmp $imgid lt $ventoy_img_count; do
vt_img_name $imgid img_name
menuentry "$img_name" {
if [ "$grub_platform" = "pc" ]; then
if [ -n "$VTOY_MEM_DISK" ]; then
legacy_iso_memdisk $iso_path
else
legacy_iso_menu_func $iso_path
fi
else
if [ -n "$VTOY_MEM_DISK" ]; then
uefi_iso_memdisk $iso_path
else
uefi_iso_menu_func $iso_path
fi
fi
}
vt_incr imgid 1
done
#Main menu
if [ $ventoy_img_count -gt 0 ]; then
if [ $VTOY_DEFAULT_MENU_MODE -eq 0 ]; then
vt_dynamic_menu 0 0
else
vt_dynamic_menu 0 1
fi
else
menuentry "No ISO files found (Press enter to reboot ...)" {
echo -e "\n Rebooting ... "
reboot
}
fi

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 269 KiB

After

Width:  |  Height:  |  Size: 257 KiB

View File

@@ -19,7 +19,7 @@ terminal-box: "terminal_box_*.png"
item_font = "ascii"
item_color = "#ffffff"
item_height = 30
item_icon_space = 1
item_spacing = 1
item_padding = 1
@@ -27,8 +27,7 @@ terminal-box: "terminal_box_*.png"
selected_item_color= "#f2f2f2"
selected_item_pixmap_style = "select_*.png"
#icon_height = 30
#icon_width = 30
item_icon_space = 0
scrollbar = true
scrollbar_width = 10
@@ -49,6 +48,14 @@ terminal-box: "terminal_box_*.png"
highlight_style = "*"
}
+ hbox{
left = 30%
top = 95%
width = 10%
height = 25
+ label {text = "@VTOY_HOTKEY_TIP@" color = "blue" align = "left"}
}
+ hbox{
left = 90%

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
LANGUAGES/languages.ini Normal file

Binary file not shown.

View File

@@ -5,7 +5,7 @@ You can copy many iso files at a time and ventoy will give you a boot menu to se
Both Legacy BIOS and UEFI are supported in the same way. 200+ ISO files are tested.
A "Ventoy Compatible" concept is introduced by ventoy, which can help to support any ISO file.
See http://www.ventoy.net for detail.
See https://www.ventoy.net for detail.
# Features
* 100% open source
@@ -25,4 +25,4 @@ See http://www.ventoy.net for detail.
* Data nondestructive during version upgrade
* No need to update Ventoy when a new distro is released
![avatar](http://www.ventoy.net/static/img/screen/screen_uefi.png)
![avatar](https://www.ventoy.net/static/img/screen/screen_uefi.png)

View File

@@ -22,53 +22,7 @@
#include "Ventoy2Disk.h"
#include "Language.h"
const TCHAR * g_Str_English[STR_ID_MAX] =
{
TEXT("Error"),
TEXT("Warning"),
TEXT("Info"),
TEXT("Please run under the correct directory!"),
TEXT("Device"),
TEXT("Ventoy At Local"),
TEXT("Ventoy In Device"),
TEXT("Status - READY"),
TEXT("Install"),
TEXT("Update"),
TEXT("Upgrade operation is safe, ISO files will be unchanged.\r\nContinue?"),
TEXT("The disk will be formatted and all the data will be lost.\r\nContinue?"),
TEXT("The disk will be formatted and all the data will be lost.\r\nContinue? (Double Check)"),
TEXT("Congratulations!\r\nVentoy has been successfully installed to the device."),
TEXT("An error occurred during the installation. You can replug the USB and try again. Check log.txt for detail."),
TEXT("Congratulations!\r\nVentoy has been successfully updated to the device."),
TEXT("An error occurred during the update. You can replug the USB and try again. Check log.txt for detail."),
TEXT("A thread is running, please wait..."),
};
const TCHAR * g_Str_ChineseSimple[STR_ID_MAX] =
{
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!"),
TEXT("<EFBFBD>"),
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ventoy"),
TEXT("<EFBFBD><EFBFBD><EFBFBD> Ventoy"),
TEXT("״̬ - ׼<><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
TEXT("<EFBFBD><EFBFBD>װ"),
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ȫ<EFBFBD><EFBFBD>, ISO<53>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ᶪʧ\r\n<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
TEXT("<EFBFBD><EFBFBD><EFBFBD>̻ᱻ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6>ᶪʧ!\r\n<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
TEXT("<EFBFBD><EFBFBD><EFBFBD>̻ᱻ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6>ᶪʧ!\r\n<EFBFBD>ٴ<EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
TEXT("<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD>! Ventoy <20>Ѿ<EFBFBD><D1BE>ɹ<EFBFBD><C9B9><EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B1B8>."),
TEXT("<EFBFBD><EFBFBD>װ Ventoy <20><><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>°β<C2B0>һ<EFBFBD><D2BB>U<EFBFBD><55>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>, <20><>ϸ<EFBFBD><CFB8>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> log.txt <20>ļ<EFBFBD>."),
TEXT("<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD>! <20>°汾<C2B0><E6B1BE> Ventoy <20>Ѿ<EFBFBD><D1BE>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><E8B1B8>."),
TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ventoy <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>°β<C2B0>һ<EFBFBD><D2BB>U<EFBFBD><55>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>, <20><>ϸ<EFBFBD><CFB8>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> log.txt <20>ļ<EFBFBD>."),
TEXT("<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>ȴ<EFBFBD>..."),
};
const TCHAR * GetString(enum STR_ID ID)
{
return g_Str_English[ID];
return g_cur_lang_data->MsgString[ID];
};

View File

@@ -21,35 +21,65 @@
#ifndef __LANGUAGE_H__
#define __LANGUAGE_H__
typedef enum STR_ID
{
STR_ERROR = 0,
STR_WARNING,
STR_INFO,
STR_INCORRECT_DIR,
STR_ERROR = 0,
STR_WARNING, // 1
STR_INFO, // 2
STR_INCORRECT_DIR, //3
STR_INCORRECT_TREE_DIR, //4
STR_DEVICE,
STR_LOCAL_VER,
STR_DISK_VER,
STR_STATUS,
STR_INSTALL,
STR_UPDATE,
STR_DEVICE, //5
STR_LOCAL_VER, //6
STR_DISK_VER, //7
STR_STATUS, //8
STR_INSTALL, //9
STR_UPDATE, //10
STR_UPDATE_TIP,
STR_INSTALL_TIP,
STR_INSTALL_TIP2,
STR_UPDATE_TIP, //11
STR_INSTALL_TIP, //12
STR_INSTALL_TIP2,//13
STR_INSTALL_SUCCESS,
STR_INSTALL_FAILED,
STR_UPDATE_SUCCESS,
STR_UPDATE_FAILED,
STR_INSTALL_SUCCESS,//14
STR_INSTALL_FAILED,//15
STR_UPDATE_SUCCESS,//16
STR_UPDATE_FAILED,//17
STR_WAIT_PROCESS,
STR_WAIT_PROCESS,//18
STR_MENU_OPTION,//19
STR_MENU_SECURE_BOOT,//20
STR_ID_MAX
STR_ID_MAX
}STR_ID;
extern BOOL g_SecureBoot;
#define VTOY_MENU_SECURE_BOOT 0xA000
#define VTOY_MENU_LANGUAGE_BEGIN 0xB000
#define VENTOY_LANGUAGE_INI TEXT(".\\ventoy\\languages.ini")
#define VENTOY_CFG_INI TEXT(".\\Ventoy2Disk.ini")
#define VENTOY_CFG_INI_A ".\\Ventoy2Disk.ini"
#define VENTOY_MAX_LANGUAGE 200
#define GET_INI_STRING(Section, Key, Buf) GetPrivateProfileString(Section, Key, TEXT("#"), Buf, sizeof(Buf), VENTOY_LANGUAGE_INI)
typedef struct VENTOY_LANGUAGE
{
WCHAR Name[128];
WCHAR FontFamily[64];
int FontSize;
WCHAR StrId[STR_ID_MAX][64];
WCHAR MsgString[STR_ID_MAX][1024];
}VENTOY_LANGUAGE;
extern VENTOY_LANGUAGE *g_cur_lang_data;
const TCHAR * GetString(enum STR_ID ID);
#define _G(a) GetString(a)

View File

@@ -824,10 +824,137 @@ int GetVentoyVerInPhyDrive(const PHY_DRIVE_INFO *pDriveInfo, CHAR *VerBuf, size_
static unsigned int g_disk_unxz_len = 0;
static BYTE *g_part_img_pos = NULL;
static BYTE *g_part_img_buf[VENTOY_EFI_PART_SIZE / SIZE_1MB];
static int VentoyFatMemRead(uint32 Sector, uint8 *Buffer, uint32 SectorCount)
{
uint32 i;
uint32 offset;
BYTE *MbBuf = NULL;
for (i = 0; i < SectorCount; i++)
{
offset = (Sector + i) * 512;
if (g_part_img_buf[1] == NULL)
{
MbBuf = g_part_img_buf[0] + offset;
memcpy(Buffer + i * 512, MbBuf, 512);
}
else
{
MbBuf = g_part_img_buf[offset / SIZE_1MB];
memcpy(Buffer + i * 512, MbBuf + (offset % SIZE_1MB), 512);
}
}
return 1;
}
static int VentoyFatMemWrite(uint32 Sector, uint8 *Buffer, uint32 SectorCount)
{
uint32 i;
uint32 offset;
BYTE *MbBuf = NULL;
for (i = 0; i < SectorCount; i++)
{
offset = (Sector + i) * 512;
if (g_part_img_buf[1] == NULL)
{
MbBuf = g_part_img_buf[0] + offset;
memcpy(MbBuf, Buffer + i * 512, 512);
}
else
{
MbBuf = g_part_img_buf[offset / SIZE_1MB];
memcpy(MbBuf + (offset % SIZE_1MB), Buffer + i * 512, 512);
}
}
return 1;
}
int VentoyProcSecureBoot(BOOL SecureBoot)
{
int rc = 0;
int size;
char *filebuf = NULL;
void *file = NULL;
Log("VentoyProcSecureBoot %d ...", SecureBoot);
if (SecureBoot)
{
Log("Secure boot is enabled ...");
return 0;
}
fl_init();
if (0 == fl_attach_media(VentoyFatMemRead, VentoyFatMemWrite))
{
file = fl_fopen("/EFI/BOOT/grubx64_real.efi", "rb");
Log("Open ventoy efi file %p ", file);
if (file)
{
fl_fseek(file, 0, SEEK_END);
size = (int)fl_ftell(file);
fl_fseek(file, 0, SEEK_SET);
Log("ventoy efi file size %d ...", size);
filebuf = (char *)malloc(size);
if (filebuf)
{
fl_fread(filebuf, 1, size, file);
}
fl_fclose(file);
Log("Now delete all efi files ...");
fl_remove("/EFI/BOOT/BOOTX64.EFI");
fl_remove("/EFI/BOOT/grubx64.efi");
fl_remove("/EFI/BOOT/grubx64_real.efi");
fl_remove("/EFI/BOOT/MokManager.efi");
file = fl_fopen("/EFI/BOOT/BOOTX64.EFI", "wb");
Log("Open bootx64 efi file %p ", file);
if (file)
{
if (filebuf)
{
fl_fwrite(filebuf, 1, size, file);
}
fl_fflush(file);
fl_fclose(file);
}
if (filebuf)
{
free(filebuf);
}
}
}
else
{
rc = 1;
}
fl_shutdown();
return rc;
}
static int disk_xz_flush(void *src, unsigned int size)
{
unsigned int i;
@@ -919,6 +1046,9 @@ static int FormatPart2Fat(HANDLE hDrive, UINT64 StartSectorId)
if (len == writelen)
{
Log("decompress finished success");
VentoyProcSecureBoot(g_SecureBoot);
for (i = 0; i < VENTOY_EFI_PART_SIZE / SIZE_1MB; i++)
{
dwSize = 0;
@@ -965,6 +1095,9 @@ static int FormatPart2Fat(HANDLE hDrive, UINT64 StartSectorId)
if (g_disk_unxz_len == VENTOY_EFI_PART_SIZE)
{
Log("decompress finished success");
VentoyProcSecureBoot(g_SecureBoot);
for (int i = 0; i < VENTOY_EFI_PART_SIZE / SIZE_1MB; i++)
{
dwSize = 0;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -29,6 +29,7 @@
#include "fat_filelib.h"
static ventoy_os_param g_os_param;
static ventoy_windows_data g_windows_data;
static UINT8 g_os_param_reserved[32];
static BOOL g_64bit_system = FALSE;
static ventoy_guid g_ventoy_guid = VENTOY_GUID;
@@ -703,6 +704,40 @@ static int DeleteVentoyPart2MountPoint(DWORD PhyDrive)
return 1;
}
static int ProcessUnattendedInstallation(const char *script)
{
DWORD dw;
HKEY hKey;
LSTATUS Ret;
CHAR Letter;
CHAR CurDir[MAX_PATH];
Log("Copy unattended XML ...");
GetCurrentDirectory(sizeof(CurDir), CurDir);
Letter = CurDir[0];
if ((Letter >= 'A' && Letter <= 'Z') || (Letter >= 'a' && Letter <= 'z'))
{
Log("Current Drive Letter: %C", Letter);
}
else
{
Letter = 'X';
}
sprintf_s(CurDir, sizeof(CurDir), "%C:\\Autounattend.xml", Letter);
Log("Copy file <%s> --> <%s>", script, CurDir);
CopyFile(script, CurDir, FALSE);
Ret = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "System\\Setup", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw);
if (ERROR_SUCCESS == Ret)
{
Ret = RegSetValueEx(hKey, "UnattendFile", 0, REG_SZ, CurDir, (DWORD)(strlen(CurDir) + 1));
}
return 0;
}
static int VentoyHook(ventoy_os_param *param)
{
int rc;
@@ -755,6 +790,24 @@ static int VentoyHook(ventoy_os_param *param)
// for protect
rc = DeleteVentoyPart2MountPoint(DiskExtent.DiskNumber);
Log("Delete ventoy mountpoint: %s", rc == 0 ? "SUCCESS" : "NO NEED");
if (g_windows_data.auto_install_script[0])
{
sprintf_s(IsoPath, sizeof(IsoPath), "%C:%s", Letter, g_windows_data.auto_install_script);
if (IsPathExist(FALSE, "%s", IsoPath))
{
Log("use auto install script %s...", IsoPath);
ProcessUnattendedInstallation(IsoPath);
}
else
{
Log("auto install script %s not exist", IsoPath);
}
}
else
{
Log("auto install no need");
}
return 0;
}
@@ -815,11 +868,12 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
for (PeStart = 0; PeStart < FileSize; PeStart += 16)
{
if (CheckOsParam((ventoy_os_param *)(Buffer + PeStart)) &&
CheckPeHead(Buffer + PeStart + sizeof(ventoy_os_param)))
CheckPeHead(Buffer + PeStart + sizeof(ventoy_os_param) + sizeof(ventoy_windows_data)))
{
Log("Find os pararm at %u", PeStart);
memcpy(&g_os_param, Buffer + PeStart, sizeof(ventoy_os_param));
memcpy(&g_windows_data, Buffer + PeStart + sizeof(ventoy_os_param), sizeof(ventoy_windows_data));
memcpy(g_os_param_reserved, g_os_param.vtoy_reserved, sizeof(g_os_param_reserved));
if (g_os_param_reserved[0] == 1)
@@ -837,7 +891,7 @@ int VentoyJump(INT argc, CHAR **argv, CHAR *LunchFile)
}
}
PeStart += sizeof(ventoy_os_param);
PeStart += sizeof(ventoy_os_param) + sizeof(ventoy_windows_data);
sprintf_s(LunchFile, MAX_PATH, "ventoy\\%s", GetFileNameInPath(ExeFileName));
SaveBuffer2File(LunchFile, Buffer + PeStart, FileSize - PeStart);
break;

View File

@@ -65,6 +65,12 @@ typedef struct ventoy_os_param
UINT8 reserved[31];
}ventoy_os_param;
typedef struct ventoy_windows_data
{
char auto_install_script[384];
UINT8 reserved[128];
}ventoy_windows_data;
#pragma pack()