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;
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);
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;
--- /dev/null
+#!/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
+
+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
+
--- /dev/null
+#!/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
+
+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
fi
fi
+ if $GREP -q 'android.x86' /proc/version; then
+ echo 'android'; return
+ fi
+
echo "default"
}
--- /dev/null
+#!/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
+
#************************************************************************************
function ventoy_power {
- configfile ${vtoy_path}/grub/power.cfg
+ configfile ($root)/grub/power.cfg
}
function get_os_type {
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
}
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)
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
2
ef
a
-2
+1
w
EOF
fi
#!/bin/sh
dos2unix -q ./tool/ventoy_lib.sh
+dos2unix -q ./tool/VentoyWorker.sh
. ./tool/ventoy_lib.sh
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
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
exit 1
fi
+rm -f log.txt
* 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
**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)
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);
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
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;
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)
{
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;
}