Skip to content

Commit

Permalink
Support Lenovo EasyStartup
Browse files Browse the repository at this point in the history
  • Loading branch information
ventoy committed Aug 23, 2021
1 parent 112c557 commit 05e208e
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 0 deletions.
1 change: 1 addition & 0 deletions GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4970,6 +4970,7 @@ static cmd_para ventoy_cmds[] =
{ "vt_push_pager", ventoy_cmd_push_pager, 0, NULL, "", "", NULL },
{ "vt_pop_pager", ventoy_cmd_pop_pager, 0, NULL, "", "", NULL },
{ "vt_check_json_path_case", ventoy_cmd_chk_json_pathcase, 0, NULL, "", "", NULL },
{ "vt_append_extra_sector", ventoy_cmd_append_ext_sector, 0, NULL, "", "", NULL },
};

int ventoy_register_all_cmd(void)
Expand Down
1 change: 1 addition & 0 deletions GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,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);
grub_err_t ventoy_cmd_append_ext_sector(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_cpio_busybox_64(grub_extcmd_context_t ctxt, int argc, char **args);
grub_err_t ventoy_cmd_trailer_cpio(grub_extcmd_context_t ctxt, int argc, char **args);
Expand Down
52 changes: 52 additions & 0 deletions GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@

GRUB_MOD_LICENSE ("GPLv3+");

#define VTOY_APPEND_EXT_SIZE 4096
static int g_append_ext_sector = 0;

char * ventoy_get_line(char *start)
{
if (start == NULL)
Expand Down Expand Up @@ -658,6 +661,11 @@ static grub_uint32_t ventoy_linux_get_virt_chunk_count(void)
count++;
}

if (g_append_ext_sector > 0)
{
count++;
}

return count;
}

Expand All @@ -671,6 +679,11 @@ static grub_uint32_t ventoy_linux_get_virt_chunk_size(void)
{
size += sizeof(ventoy_virt_chunk) + g_conf_replace_new_len_align;
}

if (g_append_ext_sector > 0)
{
size += sizeof(ventoy_virt_chunk) + VTOY_APPEND_EXT_SIZE;
}

return size;
}
Expand Down Expand Up @@ -727,6 +740,27 @@ static void ventoy_linux_fill_virt_data( grub_uint64_t isosize, ventoy_chain_
cur++;
}

/* Lenovo EasyStartup need an addional sector for boundary check */
if (g_append_ext_sector > 0)
{
cpio_secs = VTOY_APPEND_EXT_SIZE / 2048;

cur->mem_sector_start = sector;
cur->mem_sector_end = cur->mem_sector_start + cpio_secs;
cur->mem_sector_offset = offset;
cur->remap_sector_start = 0;
cur->remap_sector_end = 0;
cur->org_sector_start = 0;

grub_memset(override + offset, 0, VTOY_APPEND_EXT_SIZE);

chain->virt_img_size_in_bytes += VTOY_APPEND_EXT_SIZE;

offset += VTOY_APPEND_EXT_SIZE;
sector += cpio_secs;
cur++;
}

if (g_conf_replace_offset > 0)
{
cpio_secs = g_conf_replace_new_len_align / 2048;
Expand Down Expand Up @@ -1119,6 +1153,24 @@ grub_err_t ventoy_cmd_skip_svd(grub_extcmd_context_t ctxt, int argc, char **args
VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}

grub_err_t ventoy_cmd_append_ext_sector(grub_extcmd_context_t ctxt, int argc, char **args)
{
(void)ctxt;
(void)argc;
(void)args;

if (args[0][0] == '1')
{
g_append_ext_sector = 1;
}
else
{
g_append_ext_sector = 0;
}

VENTOY_CMD_RETURN(GRUB_ERR_NONE);
}

grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args)
{
int i;
Expand Down
83 changes: 83 additions & 0 deletions IMG/cpio/ventoy/hook/easystartup/disk_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2021, longpanda <[email protected]>
#
# 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

VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH

get_rhel_ver() {
if uname -m | grep -q '64'; then
machine='_X64'
fi

if grep -q '6[.]1' /etc/redhat-release; then
echo "RHAS6U1$machine"; return
fi

echo "RHAS6U1$machine"
}

install_dm_mod_ko() {
# dump iso file location
vtoydm -i -f $VTOY_PATH/ventoy_image_map -d ${vtdiskname} > $VTOY_PATH/iso_file_list

sysver=$(get_rhel_ver)
vtlog "sysver=$sysver"

LINE=$(grep "$sysver" -n -m1 $VTOY_PATH/iso_file_list | awk -F: '{print $1}')
vtlog "LINE=$LINE"

LINE=$(sed -n "$LINE,\$p" $VTOY_PATH/iso_file_list | grep -m1 'initrd.img')
vtlog "LINE=$LINE"

sector=$(echo $LINE | $AWK '{print $(NF-1)}')
length=$(echo $LINE | $AWK '{print $NF}')
vtlog "sector=$sector length=$length"

mkdir xxx
vtoydm -e -f $VTOY_PATH/ventoy_image_map -d ${vtdiskname} -s $sector -l $length -o ./xxx.img

cd xxx/
zcat ../xxx.img | cpio -idmu
ko=$(find -name dm-mod.ko*)
vtlog "ko=$ko ..."
insmod $ko

cd ../
rm -f xxx.img
rm -rf xxx
}

vtdiskname=$(get_ventoy_disk_name)
vtlog "vtdiskname=$vtdiskname ..."
if [ "$vtdiskname" = "unknown" ]; then
exit 0
fi

if grep -q 'device-mapper' /proc/devices; then
vtlog "device-mapper module check ko"
else
install_dm_mod_ko
fi

ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"

ln -s /dev/dm-0 /dev/root

PATH=$VTPATH_OLD
23 changes: 23 additions & 0 deletions IMG/cpio/ventoy/hook/easystartup/ventoy-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2021, longpanda <[email protected]>
#
# 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#^CDROM=.*#CDROM=/dev/dm-0#" -i /init
$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/easystartup/ventoy-initqueue.sh /initqueue/ventoy.sh
20 changes: 20 additions & 0 deletions IMG/cpio/ventoy/hook/easystartup/ventoy-initqueue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/ventoy/busybox/sh
#************************************************************************************
# Copyright (c) 2021, longpanda <[email protected]>
#
# 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/busybox/sh /ventoy/hook/easystartup/disk_hook.sh $*
6 changes: 6 additions & 0 deletions IMG/cpio/ventoy/ventoy_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ ventoy_get_os_type() {

# rhel6/CentOS6 and all other distributions based on them
elif $GREP -q 'el6' /proc/version; then
if [ -f /sbin/detectcd ]; then
if $GREP -q -i 'LENOVO-EasyStartup' /sbin/detectcd; then
echo 'easystartup'; return
fi
fi

echo 'rhel6'; return

# rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
Expand Down
8 changes: 8 additions & 0 deletions INSTALL/grub/grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,8 @@ function ventoy_reset_nojoliet {
else
vt_iso9660_nojoliet 0
fi
vt_append_extra_sector 0
}
function uefi_iso_menu_func {
Expand All @@ -787,6 +789,12 @@ function uefi_iso_menu_func {
else
set ventoy_fs_probe=iso9660
ventoy_reset_nojoliet
# Lenovo EasyStartup need an addional sector for boundary check
if vt_str_begin "$vt_volume_id" "EasyStartup"; then
vt_skip_svd "${vtoy_iso_part}${vt_chosen_path}"
vt_append_extra_sector 1
fi
fi
loopback loop "${1}${chosen_path}"
Expand Down

0 comments on commit 05e208e

Please sign in to comment.