Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dadigang
Ventoy
Commits
6bd0463d
"examples/vscode:/vscode.git/clone" did not exist on "798e17187d5a5fd9a44d2587938ff6a39b205254"
Commit
6bd0463d
authored
Apr 21, 2021
by
longpanda
Browse files
Support openwrt IMG file
parent
1ce568d9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
197 additions
and
19 deletions
+197
-19
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
+96
-5
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
+1
-1
IMG/cpio/ventoy/loop/openwrt/ventoy-disk.sh
IMG/cpio/ventoy/loop/openwrt/ventoy-disk.sh
+3
-0
IMG/cpio/ventoy/loop/openwrt/ventoy-hook.sh
IMG/cpio/ventoy/loop/openwrt/ventoy-hook.sh
+33
-6
INSTALL/grub/grub.cfg
INSTALL/grub/grub.cfg
+63
-7
INSTALL/ventoy_pack.sh
INSTALL/ventoy_pack.sh
+1
-0
No files found.
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy.c
View file @
6bd0463d
...
@@ -2503,6 +2503,7 @@ int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist,
...
@@ -2503,6 +2503,7 @@ int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist,
{
{
grub_uint32_t
i
=
0
;
grub_uint32_t
i
=
0
;
grub_uint64_t
total
=
0
;
grub_uint64_t
total
=
0
;
grub_uint64_t
fileblk
=
0
;
ventoy_img_chunk
*
chunk
=
NULL
;
ventoy_img_chunk
*
chunk
=
NULL
;
for
(
i
=
0
;
i
<
chunklist
->
cur_chunk
;
i
++
)
for
(
i
=
0
;
i
<
chunklist
->
cur_chunk
;
i
++
)
...
@@ -2518,9 +2519,17 @@ int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist,
...
@@ -2518,9 +2519,17 @@ int ventoy_check_block_list(grub_file_t file, ventoy_img_chunk_list *chunklist,
total
+=
chunk
->
disk_end_sector
+
1
-
chunk
->
disk_start_sector
;
total
+=
chunk
->
disk_end_sector
+
1
-
chunk
->
disk_start_sector
;
}
}
if
(
total
!=
((
file
->
size
+
511
)
/
512
))
fileblk
=
(
file
->
size
+
511
)
/
512
;
if
(
total
!=
fileblk
)
{
{
debug
(
"Invalid total: %llu %llu
\n
"
,
(
ulonglong
)
total
,
(
ulonglong
)((
file
->
size
+
511
)
/
512
));
debug
(
"Invalid total: %llu %llu
\n
"
,
(
ulonglong
)
total
,
(
ulonglong
)
fileblk
);
if
((
file
->
size
%
512
)
&&
(
total
+
1
==
fileblk
))
{
debug
(
"maybe img file to be processed.
\n
"
);
return
0
;
}
return
1
;
return
1
;
}
}
...
@@ -3501,6 +3510,84 @@ static grub_err_t ventoy_cmd_check_secureboot_var(grub_extcmd_context_t ctxt, in
...
@@ -3501,6 +3510,84 @@ static grub_err_t ventoy_cmd_check_secureboot_var(grub_extcmd_context_t ctxt, in
}
}
#endif
#endif
static
grub_err_t
ventoy_cmd_img_check_range
(
grub_extcmd_context_t
ctxt
,
int
argc
,
char
**
args
)
{
int
i
;
int
ret
=
1
;
grub_file_t
file
;
grub_uint64_t
FileSectors
=
0
;
ventoy_gpt_info
*
gpt
=
NULL
;
ventoy_part_table
*
pt
=
NULL
;
grub_uint8_t
zeroguid
[
16
]
=
{
0
};
(
void
)
ctxt
;
(
void
)
argc
;
file
=
ventoy_grub_file_open
(
VENTOY_FILE_TYPE
,
"%s"
,
args
[
0
]);
if
(
!
file
)
{
debug
(
"failed to open file %s
\n
"
,
args
[
0
]);
return
1
;
}
if
(
file
->
size
%
512
)
{
debug
(
"unaligned file size: %llu
\n
"
,
(
ulonglong
)
file
->
size
);
goto
out
;
}
gpt
=
grub_zalloc
(
sizeof
(
ventoy_gpt_info
));
if
(
!
gpt
)
{
goto
out
;
}
FileSectors
=
file
->
size
/
512
;
grub_file_read
(
file
,
gpt
,
sizeof
(
ventoy_gpt_info
));
if
(
grub_strncmp
(
gpt
->
Head
.
Signature
,
"EFI PART"
,
8
)
==
0
)
{
debug
(
"This is EFI partition table
\n
"
);
for
(
i
=
0
;
i
<
128
;
i
++
)
{
if
(
grub_memcmp
(
gpt
->
PartTbl
[
i
].
PartGuid
,
zeroguid
,
16
))
{
if
(
FileSectors
<
gpt
->
PartTbl
[
i
].
LastLBA
)
{
debug
(
"out of range: part[%d] LastLBA:%llu FileSectors:%llu
\n
"
,
i
,
(
ulonglong
)
gpt
->
PartTbl
[
i
].
LastLBA
,
(
ulonglong
)
FileSectors
);
goto
out
;
}
}
}
}
else
{
debug
(
"This is MBR partition table
\n
"
);
for
(
i
=
0
;
i
<
4
;
i
++
)
{
pt
=
gpt
->
MBR
.
PartTbl
+
i
;
if
(
FileSectors
<
pt
->
StartSectorId
+
pt
->
SectorCount
)
{
debug
(
"out of range: part[%d] LastLBA:%llu FileSectors:%llu
\n
"
,
i
,
(
ulonglong
)(
pt
->
StartSectorId
+
pt
->
SectorCount
),
(
ulonglong
)
FileSectors
);
goto
out
;
}
}
}
ret
=
0
;
out:
grub_file_close
(
file
);
grub_check_free
(
gpt
);
grub_errno
=
GRUB_ERR_NONE
;
return
ret
;
}
static
grub_err_t
ventoy_cmd_clear_key
(
grub_extcmd_context_t
ctxt
,
int
argc
,
char
**
args
)
static
grub_err_t
ventoy_cmd_clear_key
(
grub_extcmd_context_t
ctxt
,
int
argc
,
char
**
args
)
{
{
int
i
;
int
i
;
...
@@ -3876,6 +3963,8 @@ static grub_err_t ventoy_cmd_get_fs_label(grub_extcmd_context_t ctxt, int argc,
...
@@ -3876,6 +3963,8 @@ static grub_err_t ventoy_cmd_get_fs_label(grub_extcmd_context_t ctxt, int argc,
(
void
)
ctxt
;
(
void
)
ctxt
;
debug
(
"get fs label for %s
\n
"
,
args
[
0
]);
if
(
argc
!=
2
)
if
(
argc
!=
2
)
{
{
debug
(
"ventoy_cmd_get_fs_label, invalid param num %d
\n
"
,
argc
);
debug
(
"ventoy_cmd_get_fs_label, invalid param num %d
\n
"
,
argc
);
...
@@ -3897,19 +3986,20 @@ static grub_err_t ventoy_cmd_get_fs_label(grub_extcmd_context_t ctxt, int argc,
...
@@ -3897,19 +3986,20 @@ static grub_err_t ventoy_cmd_get_fs_label(grub_extcmd_context_t ctxt, int argc,
}
}
fs
=
grub_fs_probe
(
dev
);
fs
=
grub_fs_probe
(
dev
);
if
(
!
fs
)
if
(
NULL
==
fs
||
NULL
==
fs
->
fs_label
)
{
{
debug
(
"grub_fs_probe failed, %s
\n
"
,
device_name
);
debug
(
"grub_fs_probe failed, %s
%p %p
\n
"
,
device_name
,
fs
,
fs
->
fs_label
);
goto
end
;
goto
end
;
}
}
fs
->
fs_label
(
dev
,
&
label
);
fs
->
fs_label
(
dev
,
&
label
);
if
(
label
)
if
(
label
)
{
{
debug
(
"label=<%s>
\n
"
,
label
);
ventoy_set_env
(
args
[
1
],
label
);
ventoy_set_env
(
args
[
1
],
label
);
grub_free
(
label
);
grub_free
(
label
);
}
}
rc
=
0
;
rc
=
0
;
end:
end:
...
@@ -4415,6 +4505,7 @@ static cmd_para ventoy_cmds[] =
...
@@ -4415,6 +4505,7 @@ static cmd_para ventoy_cmds[] =
{
"vt_acpi_param"
,
ventoy_cmd_acpi_param
,
0
,
NULL
,
""
,
""
,
NULL
},
{
"vt_acpi_param"
,
ventoy_cmd_acpi_param
,
0
,
NULL
,
""
,
""
,
NULL
},
{
"vt_check_secureboot_var"
,
ventoy_cmd_check_secureboot_var
,
0
,
NULL
,
""
,
""
,
NULL
},
{
"vt_check_secureboot_var"
,
ventoy_cmd_check_secureboot_var
,
0
,
NULL
,
""
,
""
,
NULL
},
{
"vt_clear_key"
,
ventoy_cmd_clear_key
,
0
,
NULL
,
""
,
""
,
NULL
},
{
"vt_clear_key"
,
ventoy_cmd_clear_key
,
0
,
NULL
,
""
,
""
,
NULL
},
{
"vt_img_check_range"
,
ventoy_cmd_img_check_range
,
0
,
NULL
,
""
,
""
,
NULL
},
};
};
...
...
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
View file @
6bd0463d
...
@@ -284,7 +284,7 @@ extern char g_arch_mode_suffix[64];
...
@@ -284,7 +284,7 @@ extern char g_arch_mode_suffix[64];
extern
int
g_ventoy_debug
;
extern
int
g_ventoy_debug
;
void
ventoy_debug
(
const
char
*
fmt
,
...);
void
ventoy_debug
(
const
char
*
fmt
,
...);
#define debug(fmt, ...) if (g_ventoy_debug) ventoy_debug("[VTOY]: "fmt,
__VA_ARGS__
)
#define debug(fmt,
args
...) if (g_ventoy_debug) ventoy_debug("[VTOY]: "fmt,
##args
)
#define vtoy_ssprintf(buf, pos, fmt, ...) \
#define vtoy_ssprintf(buf, pos, fmt, ...) \
pos += grub_snprintf(buf + pos, VTOY_MAX_SCRIPT_BUF - pos, fmt, __VA_ARGS__)
pos += grub_snprintf(buf + pos, VTOY_MAX_SCRIPT_BUF - pos, fmt, __VA_ARGS__)
...
...
IMG/cpio/ventoy/loop/openwrt/ventoy-disk.sh
View file @
6bd0463d
...
@@ -45,6 +45,9 @@ echo -n $vtDM > /ventoy/vtDM
...
@@ -45,6 +45,9 @@ echo -n $vtDM > /ventoy/vtDM
ventoy_create_dev_ventoy_part
ventoy_create_dev_ventoy_part
mdev
-s
mdev
-s
mkdir
/ventoy_rdroot
mount /dev/ventoy2 /ventoy_rdroot
PATH
=
$VTPATH_OLD
PATH
=
$VTPATH_OLD
set_ventoy_hook_finish
set_ventoy_hook_finish
IMG/cpio/ventoy/loop/openwrt/ventoy-hook.sh
View file @
6bd0463d
...
@@ -19,12 +19,39 @@
...
@@ -19,12 +19,39 @@
.
$VTOY_PATH
/hook/ventoy-os-lib.sh
.
$VTOY_PATH
/hook/ventoy-os-lib.sh
$BUSYBOX_PATH
/mkdir /sys
VTPATH_OLD
=
$PATH
;
PATH
=
$BUSYBOX_PATH
:
$VTOY_PATH
/tool:
$PATH
$BUSYBOX_PATH
/mount
-t
proc proc /proc
$BUSYBOX_PATH
/mount
-t
sysfs sys /sys
$BUSYBOX_PATH
/mdev
-s
wrt_insmod
()
{
kbit
=
$1
kv
=
$(
uname
-r
)
echo
"insmod
$kv
$kbit
"
>>
$VTOY_PATH
/log
[
-f
/ventoy_openwrt/
$kv
/
$kbit
/dax.ko
]
&&
insmod /ventoy_openwrt/
$kv
/
$kbit
/dax.ko
>
/dev/null 2>&1
[
-f
/ventoy_openwrt/
$kv
/
$kbit
/dm-mod.ko
]
&&
insmod /ventoy_openwrt/
$kv
/
$kbit
/dm-mod.ko
>
/dev/null 2>&1
}
#$BUSYBOX_PATH/sh $VTOY_PATH/loop/openwrt/ventoy-disk.sh
exec
$BUSYBOX_PATH
/sh
mkdir
/sys
mount
-t
sysfs sys /sys
mdev
-s
if
[
-f
/ventoy_openwrt.xz
]
;
then
tar
xf /ventoy_openwrt.xz
-C
/
rm
-f
/ventoy_openwrt.xz
fi
if
uname
-m
| egrep
-q
"amd64|x86_64"
;
then
wrt_insmod 64
else
wrt_insmod generic
if
lsmod |
grep
-q
'dm-mod'
;
then
echo
"insmod generic failed"
>>
$VTOY_PATH
/log
else
wrt_insmod legacy
fi
fi
sh
$VTOY_PATH
/loop/openwrt/ventoy-disk.sh
INSTALL/grub/grub.cfg
View file @
6bd0463d
...
@@ -361,7 +361,13 @@ function ventoy_get_truenas_ver {
...
@@ -361,7 +361,13 @@ function ventoy_get_truenas_ver {
}
}
function ventoy_get_midnightbsd_ver {
function ventoy_get_midnightbsd_ver {
set vt_freebsd_ver=11.x
if vt_str_begin "$vt_volume_id" "1_"; then
set vt_freebsd_ver=11.x
elif vt_str_begin "$vt_volume_id" "2_"; then
set vt_freebsd_ver=2.x
elif vt_str_begin "$vt_volume_id" "3_"; then
set vt_freebsd_ver=3.x
fi
}
}
function ventoy_freebsd_proc {
function ventoy_freebsd_proc {
...
@@ -419,6 +425,11 @@ function ventoy_freebsd_proc {
...
@@ -419,6 +425,11 @@ function ventoy_freebsd_proc {
set vt_freebsd_ver=9.x
set vt_freebsd_ver=9.x
fi
fi
if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
set vtFreeBsdDistro=ClonOS
fi
set vt_freebsd_bit=64
set vt_freebsd_bit=64
for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
for file in "/boot/kernel/kernel" "/boot/kernel/kernel.gz"; do
if [ -e (loop)/$file ]; then
if [ -e (loop)/$file ]; then
...
@@ -440,7 +451,7 @@ function ventoy_freebsd_proc {
...
@@ -440,7 +451,7 @@ function ventoy_freebsd_proc {
fi
fi
if [ -n "${vtdebug_flag}" ]; then
if [ -n "${vtdebug_flag}" ]; then
echo "This is FreeB
SD
$vt_freebsd_ver ${vt_freebsd_bit}bit"
echo "This is
$vt
FreeB
sdDistro
$vt_freebsd_ver ${vt_freebsd_bit}bit"
fi
fi
unset vt_unix_mod_path
unset vt_unix_mod_path
...
@@ -451,10 +462,6 @@ function ventoy_freebsd_proc {
...
@@ -451,10 +462,6 @@ function ventoy_freebsd_proc {
fi
fi
done
done
if [ -e (loop)/usr/freebsd-dist/cloninst.sh ]; then
set vtFreeBsdDistro=ClonOS
fi
vt_unix_replace_ko $vt_unix_mod_path (vtunix)/ventoy_unix/$vtFreeBsdDistro/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz
vt_unix_replace_ko $vt_unix_mod_path (vtunix)/ventoy_unix/$vtFreeBsdDistro/geom_ventoy_ko/$vt_freebsd_ver/$vt_freebsd_bit/geom_ventoy.ko.xz
vt_unix_replace_conf FreeBSD "${1}${chosen_path}"
vt_unix_replace_conf FreeBSD "${1}${chosen_path}"
}
}
...
@@ -1520,6 +1527,51 @@ function ventoy_img_batocera {
...
@@ -1520,6 +1527,51 @@ function ventoy_img_batocera {
vt_unset_boot_opt
vt_unset_boot_opt
}
}
function ventoy_img_openwrt {
if [ -e (vtimghd,2)/lib64 ]; then
set ventoy_busybox_ver=64
fi
if [ ! -f ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz ]; then
ventoy_gui_console
echo -e "\n ventoy_openwrt.xz not found. Please refer https://www.ventoy.net/en/doc_openwrt.html.\n"
echo -e " 未找到 ventoy_openwrt.xz 文件。请参考 https://www.ventoy.net/cn/doc_openwrt.html\n"
echo -e "\n press ENTER to exit (请按 回车 键返回) ..."
read vtInputKey
ventoy_cli_console
return
fi
if vt_img_check_range "${vtoy_iso_part}${vt_chosen_path}"; then
ventoy_debug_pause
else
ventoy_gui_console
echo -e "\n IMG file need processed. Please refer https://www.ventoy.net/en/doc_openwrt.html.\n"
echo -e " 此 IMG 文件必须处理之后才能支持。请参考 https://www.ventoy.net/cn/doc_openwrt.html\n"
echo -e "\n press ENTER to exit (请按 回车 键返回) ..."
read vtInputKey
ventoy_cli_console
return
fi
vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
vt_img_extra_initrd_append ${vtoy_iso_part}/ventoy/ventoy_openwrt.xz
#boot image file
vt_set_boot_opt rdinit=/vtoy/vtoy ventoyos=openwrt
vt_img_hook_root
set root=(vtimghd,1)
configfile (vtimghd,1)/boot/grub/grub.cfg
vt_img_unhook_root
vt_unset_boot_opt
}
function ventoy_img_tails {
function ventoy_img_tails {
vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
vt_load_cpio $vtoy_path "${vt_chosen_path}" ${vtoy_iso_part} "busybox=$ventoy_busybox_ver"
vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
vt_trailer_cpio ${vtoy_iso_part} "${vt_chosen_path}" noinit
...
@@ -1580,8 +1632,9 @@ function img_common_menuentry {
...
@@ -1580,8 +1632,9 @@ function img_common_menuentry {
vt_img_extra_initrd_reset
vt_img_extra_initrd_reset
vt_get_fs_label (vtimghd,1) vtImgHd1Label
vt_get_fs_label (vtimghd,1) vtImgHd1Label
if [ -d (vtimghd,2)/lib ]; then
if [ -d (vtimghd,2)/lib ]; then
vt_get_fs_label (vtimghd,2) vtImgHd2Label
vt_get_fs_label (vtimghd,2) vtImgHd2Label
fi
fi
...
@@ -1589,6 +1642,7 @@ function img_common_menuentry {
...
@@ -1589,6 +1642,7 @@ function img_common_menuentry {
vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
vt_1st_line (vtimghd,1)/etc/hostname vtImgHostname
fi
fi
if [ -e (vtimghd,1)/easy.sfs ]; then
if [ -e (vtimghd,1)/easy.sfs ]; then
ventoy_img_easyos
ventoy_img_easyos
elif [ -e (vtimghd,1)/volumio.initrd ]; then
elif [ -e (vtimghd,1)/volumio.initrd ]; then
...
@@ -1609,6 +1663,8 @@ function img_common_menuentry {
...
@@ -1609,6 +1663,8 @@ function img_common_menuentry {
ventoy_img_recalbox
ventoy_img_recalbox
elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
elif [ -f (vtimghd,2)/loader/entries/ubos.conf ]; then
ventoy_img_ubos
ventoy_img_ubos
elif [ -f (vtimghd,2)/etc/openwrt_version ]; then
ventoy_img_openwrt
elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
elif [ -f (vtimghd,1)/efi/boot/mt86.png ]; then
if [ "$grub_platform" = "pc" ]; then
if [ "$grub_platform" = "pc" ]; then
img_unsupport_tip
img_unsupport_tip
...
...
INSTALL/ventoy_pack.sh
View file @
6bd0463d
...
@@ -82,6 +82,7 @@ cp $OPT ./tool/i386/mount.exfat-fuse $tmpmnt/tool/mount.exfat-fuse_i386
...
@@ -82,6 +82,7 @@ cp $OPT ./tool/i386/mount.exfat-fuse $tmpmnt/tool/mount.exfat-fuse_i386
cp
$OPT
./tool/x86_64/mount.exfat-fuse
$tmpmnt
/tool/mount.exfat-fuse_x86_64
cp
$OPT
./tool/x86_64/mount.exfat-fuse
$tmpmnt
/tool/mount.exfat-fuse_x86_64
cp
$OPT
./tool/aarch64/mount.exfat-fuse
$tmpmnt
/tool/mount.exfat-fuse_aarch64
cp
$OPT
./tool/aarch64/mount.exfat-fuse
$tmpmnt
/tool/mount.exfat-fuse_aarch64
rm
-f
$tmpmnt
/grub/i386-pc/
*
.img
rm
-f
$tmpmnt
/grub/i386-pc/
*
.img
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment