diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c index 28133ce2..1e795c3c 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_linux.c @@ -686,6 +686,8 @@ static grub_uint32_t ventoy_linux_get_override_chunk_size(void) static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *override) { initrd_info *node; + grub_uint32_t mod; + grub_uint32_t newlen; grub_uint64_t sector; ventoy_override_chunk *cur; @@ -699,13 +701,20 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove continue; } + newlen = (grub_uint32_t)(node->size + g_ventoy_cpio_size); + mod = newlen % 4; + if (mod > 0) + { + newlen += 4 - mod; + } + if (node->iso_type == 0) { ventoy_iso9660_override *dirent = (ventoy_iso9660_override *)node->override_data; node->override_length = sizeof(ventoy_iso9660_override); dirent->first_sector = (grub_uint32_t)sector; - dirent->size = (grub_uint32_t)(node->size + g_ventoy_cpio_size); + dirent->size = newlen; dirent->first_sector_be = grub_swap_bytes32(dirent->first_sector); dirent->size_be = grub_swap_bytes32(dirent->size); @@ -716,7 +725,7 @@ static void ventoy_linux_fill_override_data( grub_uint64_t isosize, void *ove ventoy_udf_override *udf = (ventoy_udf_override *)node->override_data; node->override_length = sizeof(ventoy_udf_override); - udf->length = (grub_uint32_t)(node->size + g_ventoy_cpio_size); + udf->length = newlen; udf->position = (grub_uint32_t)sector - node->udf_start_block; sector += (udf->length + 2047) / 2048; diff --git a/IMG/cpio/ventoy/hook/android/ventoy-disk.sh b/IMG/cpio/ventoy/hook/android/ventoy-disk.sh new file mode 100644 index 00000000..a9aee8d8 --- /dev/null +++ b/IMG/cpio/ventoy/hook/android/ventoy-disk.sh @@ -0,0 +1,42 @@ +#!/ventoy/busybox/sh +#************************************************************************************ +# Copyright (c) 2020, longpanda +# +# 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 . +# +#************************************************************************************ + +. /ventoy/hook/ventoy-hook-lib.sh + +if is_ventoy_hook_finished; then + exit 0 +fi + +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" "noreplace" + +if ! [ -e $VTOY_DM_PATH ]; then + blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/') + mknod -m 0666 $VTOY_DM_PATH b $blkdev_num +fi + +# OK finish +set_ventoy_hook_finish + diff --git a/IMG/cpio/ventoy/hook/android/ventoy-hook.sh b/IMG/cpio/ventoy/hook/android/ventoy-hook.sh new file mode 100644 index 00000000..4a315be6 --- /dev/null +++ b/IMG/cpio/ventoy/hook/android/ventoy-hook.sh @@ -0,0 +1,27 @@ +#!/ventoy/busybox/sh +#************************************************************************************ +# Copyright (c) 2020, longpanda +# +# 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 . +# +#************************************************************************************ + +. $VTOY_PATH/hook/ventoy-os-lib.sh + +if ! [ -d /dev ]; then + $BUSYBOX_PATH/mkdir /dev +fi + +$SED "1a\export ROOT=/dev/mapper/ventoy" -i /init +$SED "/check_root \$device/i\ $BUSYBOX_PATH/sh $VTOY_PATH/hook/android/ventoy-disk.sh" -i /init diff --git a/IMG/cpio/ventoy/ventoy.sh b/IMG/cpio/ventoy/ventoy.sh index e64a4a76..edab7e8c 100644 --- a/IMG/cpio/ventoy/ventoy.sh +++ b/IMG/cpio/ventoy/ventoy.sh @@ -184,6 +184,10 @@ ventoy_get_os_type() { fi fi + if $GREP -q 'android.x86' /proc/version; then + echo 'android'; return + fi + echo "default" } diff --git a/INSTALL/CreatePersistentImg.sh b/INSTALL/CreatePersistentImg.sh new file mode 100644 index 00000000..83f1e7e1 --- /dev/null +++ b/INSTALL/CreatePersistentImg.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +size=1024 +fstype=ext4 +label=casper-rw + +print_usage() { + echo 'Usage: CreatePersistentImg.sh [ -s size ] [ -t fstype ] [ -l LABEL ]' + echo ' OPTION: (optional)' + echo ' -s size in MB, default is 1024' + echo ' -t filesystem type, default is ext4 ext2/ext3/ext4/xfs are supported now' + echo ' -l label, default is casper-rw' + echo '' +} + +while [ -n "$1" ]; do + if [ "$1" = "-s" ]; then + shift + size=$1 + elif [ "$1" = "-t" ]; then + shift + fstype=$1 + elif [ "$1" = "-l" ]; then + shift + label=$1 + else + print_usage + exit 1 + fi + shift +done + + +# check label +if [ -z "$label" ]; then + echo "The label can NOT be empty." + exit 1 +fi + +# check size +if echo $size | grep -q "^[0-9][0-9]*$"; then + if [ $size -le 1 ]; then + echo "Invalid size $size" + exit 1 + fi +else + echo "Invalid size $size" + exit 1 +fi + + +# check file system type +# nodiscard must be set for ext2/3/4 +# -K must be set for xfs +if echo $fstype | grep -q '^ext[234]$'; then + fsopt='-E nodiscard' +elif [ "$fstype" = "xfs" ]; then + fsopt='-K' +else + echo "unsupported file system $fstype" + exit 1 +fi + +# 00->ff avoid sparse file +dd if=/dev/zero bs=1M count=$size | tr '\000' '\377' > persistence.img +sync + +freeloop=$(losetup -f) + +losetup $freeloop persistence.img + +mkfs -t $fstype $fsopt -L $label $freeloop + +sync + +losetup -d $freeloop + diff --git a/INSTALL/EFI/BOOT/grubx64_real.efi b/INSTALL/EFI/BOOT/grubx64_real.efi index 0323fce7..e6ba9bb6 100644 Binary files a/INSTALL/EFI/BOOT/grubx64_real.efi and b/INSTALL/EFI/BOOT/grubx64_real.efi differ diff --git a/INSTALL/Ventoy2Disk.exe b/INSTALL/Ventoy2Disk.exe index ded8b109..2ed82b79 100644 Binary files a/INSTALL/Ventoy2Disk.exe and b/INSTALL/Ventoy2Disk.exe differ diff --git a/INSTALL/grub/grub.cfg b/INSTALL/grub/grub.cfg index 2a2175d3..b1ef9b0a 100644 --- a/INSTALL/grub/grub.cfg +++ b/INSTALL/grub/grub.cfg @@ -17,7 +17,7 @@ #************************************************************************************ function ventoy_power { - configfile ${vtoy_path}/grub/power.cfg + configfile ($root)/grub/power.cfg } function get_os_type { @@ -117,9 +117,11 @@ function distro_specify_initrd_file_phase2 { vt_linux_specify_initrd_file /boot/iniramfs.igz elif [ -f (loop)/initrd-x86_64 ]; then vt_linux_specify_initrd_file /initrd-x86_64 - elif [ -f (loop)/live/initrd.img ]; then + elif [ -f (loop)/live/initrd.img ]; then vt_linux_specify_initrd_file /live/initrd.img - + elif [ -f (loop)/initrd.img ]; then + vt_linux_specify_initrd_file /initrd.img + fi } diff --git a/INSTALL/grub/i386-pc/core.img b/INSTALL/grub/i386-pc/core.img index 83dd2167..424bb76a 100644 Binary files a/INSTALL/grub/i386-pc/core.img and b/INSTALL/grub/i386-pc/core.img differ diff --git a/INSTALL/tool/VentoyWorker.sh b/INSTALL/tool/VentoyWorker.sh index 224ddf8c..817a149f 100644 --- a/INSTALL/tool/VentoyWorker.sh +++ b/INSTALL/tool/VentoyWorker.sh @@ -266,6 +266,16 @@ else dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=440 + PART1_ACTIVE=$(dd if=$DISK bs=1 count=1 skip=446 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"') + PART2_ACTIVE=$(dd if=$DISK bs=1 count=1 skip=462 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"') + + vtdebug "PART1_ACTIVE=$PART1_ACTIVE PART2_ACTIVE=$PART2_ACTIVE" + if [ "$PART1_ACTIVE" = "00" ] && [ "$PART2_ACTIVE" = "80" ]; then + vtdebug "change 1st partition active, 2nd partition inactive ..." + echo -en '\x80' | dd of=$DISK conv=fsync bs=1 count=1 seek=446 status=none + echo -en '\x00' | dd of=$DISK conv=fsync bs=1 count=1 seek=462 status=none + fi + ./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1 disk_sector_num=$(cat /sys/block/${DISK#/dev/}/size) diff --git a/INSTALL/tool/ventoy_lib.sh b/INSTALL/tool/ventoy_lib.sh index dd9e0959..80dea30a 100644 --- a/INSTALL/tool/ventoy_lib.sh +++ b/INSTALL/tool/ventoy_lib.sh @@ -216,7 +216,7 @@ format_ventoy_disk() { unit s \ mkpart primary ntfs $part1_start_sector $part1_end_sector \ mkpart primary fat16 $part2_start_sector $part2_end_sector \ - set 2 boot on \ + set 1 boot on \ quit sync @@ -243,7 +243,7 @@ t 2 ef a -2 +1 w EOF fi diff --git a/INSTALL/ventoy/ventoy.cpio b/INSTALL/ventoy/ventoy.cpio index d8bac6aa..a45afff7 100644 Binary files a/INSTALL/ventoy/ventoy.cpio and b/INSTALL/ventoy/ventoy.cpio differ diff --git a/INSTALL/ventoy_pack.sh b/INSTALL/ventoy_pack.sh index 6701dc97..9e3b4841 100644 --- a/INSTALL/ventoy_pack.sh +++ b/INSTALL/ventoy_pack.sh @@ -1,6 +1,7 @@ #!/bin/sh dos2unix -q ./tool/ventoy_lib.sh +dos2unix -q ./tool/VentoyWorker.sh . ./tool/ventoy_lib.sh @@ -30,7 +31,7 @@ while ! grep -q 524288 /sys/block/${LOOP#/dev/}/size 2>/dev/null; do sleep 1 done -format_ventoy_disk $LOOP +format_ventoy_disk $LOOP fdisk $GRUB_DIR/sbin/grub-bios-setup --skip-fs-probe --directory="./grub/i386-pc" $LOOP @@ -77,8 +78,9 @@ xz --check=crc32 $tmpdir/boot/core.img cp -a ./tool $tmpdir/ cp -a Ventoy2Disk.sh $tmpdir/ - +cp -a CreatePersistentImg.sh $tmpdir/ dos2unix -q $tmpdir/Ventoy2Disk.sh +dos2unix -q $tmpdir/CreatePersistentImg.sh #32MB disk img dd status=none if=$LOOP of=$tmpdir/ventoy/ventoy.disk.img bs=512 count=$VENTOY_SECTOR_NUM skip=$part2_start_sector @@ -119,4 +121,5 @@ else exit 1 fi +rm -f log.txt diff --git a/README.md b/README.md index 64e689e4..5d7a9494 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,15 @@ See https://www.ventoy.net for detail. * Legacy + UEFI supported in the same way * UEFI Secure Boot supported (since 1.0.07+) * Persistence supported (since 1.0.11+) +* WIM files boot supported (Legacy + UEFI) (1.0.12+) +* Auto installation supported (1.0.09+) * ISO files larger than 4GB supported * Native boot menu style for Legacy & UEFI * Most type of OS supported, 200+ iso files tested * Not only boot but also complete installation process +* ISO files can be listed in List mode/TreeView mode * "Ventoy Compatible" concept * Plugin Framework -* Auto installation supported (1.0.09+) * Readonly to USB drive during boot * USB normal use unaffected * Data nondestructive during version upgrade @@ -43,6 +45,7 @@ Title | Link **Customize Theme** | [https://www.ventoy.net/en/plugin_theme.html](https://www.ventoy.net/en/plugin_theme.html) **Auto Installation** | [https://www.ventoy.net/en/plugin_autoinstall.html](https://www.ventoy.net/en/plugin_autoinstall.html) **Persistence Support** | [https://www.ventoy.net/en/plugin_persistence.html](https://www.ventoy.net/en/plugin_persistence.html) +**Boot WIM file** | [https://www.ventoy.net/en/plugin_wimboot.html](https://www.ventoy.net/en/plugin_wimboot.html) **Memdisk Mode** | [https://www.ventoy.net/en/doc_memdisk.html](https://www.ventoy.net/en/doc_memdisk.html) **TreeView Mode** | [https://www.ventoy.net/en/doc_treeview.html](https://www.ventoy.net/en/doc_treeview.html) **Disk Layout** | [https://www.ventoy.net/en/doc_disk_layout.html](https://www.ventoy.net/en/doc_disk_layout.html) diff --git a/Ventoy2Disk/Ventoy2Disk/PhyDrive.c b/Ventoy2Disk/Ventoy2Disk/PhyDrive.c index 535e1a91..7e90421e 100644 --- a/Ventoy2Disk/Ventoy2Disk/PhyDrive.c +++ b/Ventoy2Disk/Ventoy2Disk/PhyDrive.c @@ -1591,6 +1591,18 @@ int UpdateVentoy2PhyDrive(PHY_DRIVE_INFO *pPhyDrive) Log("Write Boot Image ret:%u dwSize:%u Error:%u", bRet, dwSize, LASTERR); } + if (0x00 == MBR.PartTbl[0].Active && 0x80 == MBR.PartTbl[1].Active) + { + Log("Need to chage 1st partition active and 2nd partition inactive."); + + MBR.PartTbl[0].Active = 0x80; + MBR.PartTbl[1].Active = 0x00; + + SetFilePointer(hDrive, 0, NULL, FILE_BEGIN); + bRet = WriteFile(hDrive, &MBR, 512, &dwSize, NULL); + Log("Write NEW MBR ret:%u dwSize:%u Error:%u", bRet, dwSize, LASTERR); + } + //Refresh Drive Layout DeviceIoControl(hDrive, IOCTL_DISK_UPDATE_PROPERTIES, NULL, 0, NULL, 0, &dwSize, NULL); diff --git a/Ventoy2Disk/Ventoy2Disk/Utility.c b/Ventoy2Disk/Ventoy2Disk/Utility.c index 356b4ab7..a1023fad 100644 --- a/Ventoy2Disk/Ventoy2Disk/Utility.c +++ b/Ventoy2Disk/Ventoy2Disk/Utility.c @@ -449,7 +449,7 @@ int VentoyFillMBR(UINT64 DiskSizeBytes, MBR_HEAD *pMBR) PartSectorCount = DiskSectorCount - VENTOY_EFI_PART_SIZE / 512 - PartStartSector; VentoyFillLocation(DiskSizeBytes, PartStartSector, PartSectorCount, pMBR->PartTbl); - pMBR->PartTbl[0].Active = 0x00; + pMBR->PartTbl[0].Active = 0x80; // bootable pMBR->PartTbl[0].FsFlag = 0x07; // exFAT/NTFS/HPFS //Part2 @@ -457,7 +457,7 @@ int VentoyFillMBR(UINT64 DiskSizeBytes, MBR_HEAD *pMBR) PartSectorCount = VENTOY_EFI_PART_SIZE / 512; VentoyFillLocation(DiskSizeBytes, PartStartSector, PartSectorCount, pMBR->PartTbl + 1); - pMBR->PartTbl[1].Active = 0x80; // bootable + pMBR->PartTbl[1].Active = 0x00; pMBR->PartTbl[1].FsFlag = 0xEF; // EFI System Partition pMBR->Byte55 = 0x55; diff --git a/Ventoy2Disk/Ventoy2Disk/Ventoy2Disk.c b/Ventoy2Disk/Ventoy2Disk/Ventoy2Disk.c index 0a84ce2f..e4da2110 100644 --- a/Ventoy2Disk/Ventoy2Disk/Ventoy2Disk.c +++ b/Ventoy2Disk/Ventoy2Disk/Ventoy2Disk.c @@ -140,8 +140,7 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes) PartStartSector = (UINT32)((SizeBytes - VENTOY_EFI_PART_SIZE) / 512); PartSectorCount = VENTOY_EFI_PART_SIZE / 512; - if (MBR.PartTbl[1].Active != 0x80 || - MBR.PartTbl[1].FsFlag != 0xEF || + if (MBR.PartTbl[1].FsFlag != 0xEF || MBR.PartTbl[1].StartSectorId != PartStartSector || MBR.PartTbl[1].SectorCount != PartSectorCount) { @@ -149,6 +148,12 @@ static BOOL IsVentoyPhyDrive(int PhyDrive, UINT64 SizeBytes) return FALSE; } + if (MBR.PartTbl[0].Active != 0x80 && MBR.PartTbl[1].Active != 0x80) + { + Log("Part1 and Part2 are both NOT active 0x%x 0x%x", MBR.PartTbl[0].Active, MBR.PartTbl[1].Active); + return FALSE; + } + Log("PhysicalDrive%d is ventoy disk", PhyDrive); return TRUE; }