]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Support Lenovo EasyStartup
authorlongpanda <admin@ventoy.net>
Mon, 23 Aug 2021 08:56:17 +0000 (16:56 +0800)
committerlongpanda <admin@ventoy.net>
Mon, 23 Aug 2021 08:56:17 +0000 (16:56 +0800)
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_cmd.c
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c
IMG/cpio/ventoy/hook/easystartup/disk_hook.sh [new file with mode: 0644]
IMG/cpio/ventoy/hook/easystartup/ventoy-hook.sh [new file with mode: 0644]
IMG/cpio/ventoy/hook/easystartup/ventoy-initqueue.sh [new file with mode: 0644]
IMG/cpio/ventoy/ventoy_chain.sh
INSTALL/grub/grub.cfg

index cdf5333aec2c34a34ff380e5e16ffc60d0c7c35b..848ba8746a2bceadab33883f4201ce4f8b5afd33 100644 (file)
@@ -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_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)
 };
 
 int ventoy_register_all_cmd(void)
index 3185a7a5273287f04c35236ec328f2c80aad645a..8e503b1e190f9d5cf1b2bb604afc71f6f49b79f5 100644 (file)
@@ -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_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);
 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);
index 2ff731f1c92af4e654f9e856a0c59f5c50d584f5..560355ab745aa5aaddd9fd262d4bcd2bea08975d 100644 (file)
@@ -38,6 +38,9 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
 
 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)
 char * ventoy_get_line(char *start)
 {
     if (start == NULL)
@@ -658,6 +661,11 @@ static grub_uint32_t ventoy_linux_get_virt_chunk_count(void)
         count++;
     }
     
         count++;
     }
     
+    if (g_append_ext_sector > 0)
+    {
+        count++;
+    }
+    
     return count;
 }
 
     return count;
 }
 
@@ -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;
     }
     {
         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;
 }
 
     return size;
 }
@@ -727,6 +740,27 @@ static void ventoy_linux_fill_virt_data(    grub_uint64_t isosize, ventoy_chain_
         cur++;
     }
 
         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;
     if (g_conf_replace_offset > 0)
     {
         cpio_secs = g_conf_replace_new_len_align / 2048;
@@ -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);
 }
 
     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;
 grub_err_t ventoy_cmd_load_cpio(grub_extcmd_context_t ctxt, int argc, char **args)
 {
     int i;
diff --git a/IMG/cpio/ventoy/hook/easystartup/disk_hook.sh b/IMG/cpio/ventoy/hook/easystartup/disk_hook.sh
new file mode 100644 (file)
index 0000000..d9b3d48
--- /dev/null
@@ -0,0 +1,83 @@
+#!/ventoy/busybox/sh
+#************************************************************************************
+# Copyright (c) 2021, 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
+
+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
diff --git a/IMG/cpio/ventoy/hook/easystartup/ventoy-hook.sh b/IMG/cpio/ventoy/hook/easystartup/ventoy-hook.sh
new file mode 100644 (file)
index 0000000..39658c4
--- /dev/null
@@ -0,0 +1,23 @@
+#!/ventoy/busybox/sh
+#************************************************************************************
+# Copyright (c) 2021, 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#^CDROM=.*#CDROM=/dev/dm-0#" -i /init
+$BUSYBOX_PATH/cp -a $VTOY_PATH/hook/easystartup/ventoy-initqueue.sh  /initqueue/ventoy.sh
diff --git a/IMG/cpio/ventoy/hook/easystartup/ventoy-initqueue.sh b/IMG/cpio/ventoy/hook/easystartup/ventoy-initqueue.sh
new file mode 100644 (file)
index 0000000..d4c8b5f
--- /dev/null
@@ -0,0 +1,20 @@
+#!/ventoy/busybox/sh
+#************************************************************************************
+# Copyright (c) 2021, 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/busybox/sh /ventoy/hook/easystartup/disk_hook.sh $*
index 10fcc426dbb5e9a38d54f572ca1c45756d4933d8..3b12922b33d71b2d9f8eb2ad4dc69ce484226dcd 100644 (file)
@@ -58,6 +58,12 @@ ventoy_get_os_type() {
 
     # rhel6/CentOS6 and all other distributions based on them
     elif $GREP -q 'el6' /proc/version; then
 
     # 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
         echo 'rhel6'; return
 
     # rhel7/CentOS7/rhel8/CentOS8 and all other distributions based on them
index 2b3be9551795ce104723bac0efae08a8b09c60e6..e596a0aad2b68891773adf928377a6b5f822e7b7 100644 (file)
@@ -761,6 +761,8 @@ function ventoy_reset_nojoliet {
     else
         vt_iso9660_nojoliet 0
     fi
     else
         vt_iso9660_nojoliet 0
     fi
+    
+    vt_append_extra_sector 0
 }
 
 function uefi_iso_menu_func {
 }
 
 function uefi_iso_menu_func {
@@ -787,6 +789,12 @@ function uefi_iso_menu_func {
     else
         set ventoy_fs_probe=iso9660
         ventoy_reset_nojoliet
     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}"
     fi
 
     loopback loop "${1}${chosen_path}"