mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-06-04 00:48:48 -04:00
add GPT support
This commit is contained in:
parent
1d034f0a24
commit
9ecbff9ce6
16 changed files with 853 additions and 110 deletions
|
@ -12,6 +12,7 @@ print_usage() {
|
|||
echo ' OPTION: (optional)'
|
||||
echo ' -r SIZE_MB preserve some space at the bottom of the disk (only for install)'
|
||||
echo ' -s enable secure boot support (default is disabled)'
|
||||
echo ' -g use GPT partition style, default is MBR (only for install)'
|
||||
echo ''
|
||||
|
||||
}
|
||||
|
@ -27,6 +28,8 @@ while [ -n "$1" ]; do
|
|||
MODE="update"
|
||||
elif [ "$1" = "-s" ]; then
|
||||
SECUREBOOT="YES"
|
||||
elif [ "$1" = "-g" ]; then
|
||||
VTGPT="YES"
|
||||
elif [ "$1" = "-r" ]; then
|
||||
RESERVE_SPACE="YES"
|
||||
shift
|
||||
|
@ -110,13 +113,22 @@ fi
|
|||
if [ "$MODE" = "install" ]; then
|
||||
vtdebug "install ventoy ..."
|
||||
|
||||
if parted -v > /dev/null 2>&1; then
|
||||
PARTTOOL='parted'
|
||||
elif fdisk -v >/dev/null 2>&1; then
|
||||
PARTTOOL='fdisk'
|
||||
if [ -n "$VTGPT" ]; then
|
||||
if parted -v > /dev/null 2>&1; then
|
||||
PARTTOOL='parted'
|
||||
else
|
||||
vterr "parted is not found in the sysstem, Ventoy can't create new partition."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
vterr "Both parted and fdisk are not found in the sysstem, Ventoy can't create new partition."
|
||||
exit 1
|
||||
if parted -v > /dev/null 2>&1; then
|
||||
PARTTOOL='parted'
|
||||
elif fdisk -v >/dev/null 2>&1; then
|
||||
PARTTOOL='fdisk'
|
||||
else
|
||||
vterr "Both parted and fdisk are not found in the sysstem, Ventoy can't create new partition."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
version=$(get_disk_ventoy_version $DISK)
|
||||
|
@ -148,11 +160,15 @@ if [ "$MODE" = "install" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
|
||||
#Print disk info
|
||||
echo "Disk : $DISK"
|
||||
parted -s $DISK p 2>&1 | grep Model
|
||||
echo "Size : $disk_size_gb GB"
|
||||
echo "Size : $disk_size_gb GB"
|
||||
if [ -n "$VTGPT" ]; then
|
||||
echo "Style: GPT"
|
||||
else
|
||||
echo "Style: MBR"
|
||||
fi
|
||||
echo ''
|
||||
|
||||
if [ -n "$RESERVE_SPACE" ]; then
|
||||
|
@ -192,7 +208,13 @@ if [ "$MODE" = "install" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
format_ventoy_disk $RESERVE_SIZE_MB $DISK $PARTTOOL
|
||||
if [ -n "$VTGPT" ]; then
|
||||
vtdebug "format_ventoy_disk_gpt $RESERVE_SIZE_MB $DISK $PARTTOOL ..."
|
||||
format_ventoy_disk_gpt $RESERVE_SIZE_MB $DISK $PARTTOOL
|
||||
else
|
||||
vtdebug "format_ventoy_disk_mbr $RESERVE_SIZE_MB $DISK $PARTTOOL ..."
|
||||
format_ventoy_disk_mbr $RESERVE_SIZE_MB $DISK $PARTTOOL
|
||||
fi
|
||||
|
||||
# format part1
|
||||
if ventoy_is_linux64; then
|
||||
|
@ -216,8 +238,17 @@ if [ "$MODE" = "install" ]; then
|
|||
chmod +x ./tool/vtoy_gen_uuid
|
||||
|
||||
vtinfo "writing data to disk ..."
|
||||
|
||||
dd status=none conv=fsync if=./boot/boot.img of=$DISK bs=1 count=446
|
||||
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
|
||||
|
||||
if [ -n "$VTGPT" ]; then
|
||||
echo -en '\x22' | dd status=none of=$DISK conv=fsync bs=1 count=1 seek=92
|
||||
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2014 seek=34
|
||||
echo -en '\x23' | dd of=$DISK conv=fsync bs=1 count=1 seek=17908 status=none
|
||||
else
|
||||
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
|
||||
fi
|
||||
|
||||
./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start_sector
|
||||
|
||||
#disk uuid
|
||||
|
@ -307,8 +338,11 @@ else
|
|||
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
|
||||
|
||||
|
||||
./tool/xzcat ./boot/core.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=2047 seek=1
|
||||
|
||||
|
||||
./tool/xzcat ./ventoy/ventoy.disk.img.xz | dd status=none conv=fsync of=$DISK bs=512 count=$VENTOY_SECTOR_NUM seek=$part2_start
|
||||
|
||||
sync
|
||||
|
|
|
@ -103,7 +103,7 @@ get_ventoy_version_from_cfg() {
|
|||
}
|
||||
|
||||
is_disk_contains_ventoy() {
|
||||
DISK=$1
|
||||
DISK=$1
|
||||
|
||||
PART1=$(get_disk_part_name $1 1)
|
||||
PART2=$(get_disk_part_name $1 2)
|
||||
|
@ -126,11 +126,15 @@ is_disk_contains_ventoy() {
|
|||
return
|
||||
fi
|
||||
|
||||
PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
PART2_TYPE=$(dd if=$DISK bs=1 count=1 skip=466 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
if [ "$PART2_TYPE" != "EF" ]; then
|
||||
vtdebug "part2 type is $PART2_TYPE not EF"
|
||||
ventoy_false
|
||||
return
|
||||
|
||||
if [ "$PART1_TYPE" != "EE" ]; then
|
||||
if [ "$PART2_TYPE" != "EF" ]; then
|
||||
vtdebug "part2 type is $PART2_TYPE not EF"
|
||||
ventoy_false
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
|
||||
|
@ -185,7 +189,7 @@ get_disk_ventoy_version() {
|
|||
ventoy_false
|
||||
}
|
||||
|
||||
format_ventoy_disk() {
|
||||
format_ventoy_disk_mbr() {
|
||||
reserve_mb=$1
|
||||
DISK=$2
|
||||
PARTTOOL=$3
|
||||
|
@ -218,7 +222,7 @@ format_ventoy_disk() {
|
|||
fi
|
||||
|
||||
echo ""
|
||||
echo "Create partitions on $DISK by $PARTTOOL ..."
|
||||
echo "Create partitions on $DISK by $PARTTOOL in MBR style ..."
|
||||
|
||||
if [ "$PARTTOOL" = "parted" ]; then
|
||||
vtdebug "format disk by parted ..."
|
||||
|
@ -300,5 +304,95 @@ EOF
|
|||
}
|
||||
|
||||
|
||||
format_ventoy_disk_gpt() {
|
||||
reserve_mb=$1
|
||||
DISK=$2
|
||||
PARTTOOL=$3
|
||||
|
||||
PART1=$(get_disk_part_name $DISK 1)
|
||||
PART2=$(get_disk_part_name $DISK 2)
|
||||
|
||||
sector_num=$(cat /sys/block/${DISK#/dev/}/size)
|
||||
|
||||
part1_start_sector=2048
|
||||
|
||||
if [ $reserve_mb -gt 0 ]; then
|
||||
reserve_sector_num=$(expr $reserve_mb \* 2048 + 33)
|
||||
part1_end_sector=$(expr $sector_num - $reserve_sector_num - $VENTOY_SECTOR_NUM - 1)
|
||||
else
|
||||
part1_end_sector=$(expr $sector_num - $VENTOY_SECTOR_NUM - 34)
|
||||
fi
|
||||
|
||||
part2_start_sector=$(expr $part1_end_sector + 1)
|
||||
part2_end_sector=$(expr $part2_start_sector + $VENTOY_SECTOR_NUM - 1)
|
||||
|
||||
export part2_start_sector
|
||||
|
||||
vtdebug "part1_start_sector=$part1_start_sector part1_end_sector=$part1_end_sector"
|
||||
vtdebug "part2_start_sector=$part2_start_sector part2_end_sector=$part2_end_sector"
|
||||
|
||||
if [ -e $PART2 ]; then
|
||||
echo "delete $PART2"
|
||||
rm -f $PART2
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Create partitions on $DISK by $PARTTOOL in GPT style ..."
|
||||
|
||||
vtdebug "format disk by parted ..."
|
||||
parted -a none --script $DISK \
|
||||
mklabel gpt \
|
||||
unit s \
|
||||
mkpart Ventoy ntfs $part1_start_sector $part1_end_sector \
|
||||
mkpart VTOYEFI fat16 $part2_start_sector $part2_end_sector \
|
||||
set 2 boot on \
|
||||
set 2 esp on \
|
||||
set 2 hidden on \
|
||||
quit
|
||||
|
||||
sync
|
||||
|
||||
udevadm trigger >/dev/null 2>&1
|
||||
partprobe >/dev/null 2>&1
|
||||
sleep 3
|
||||
echo "Done"
|
||||
|
||||
echo 'mkfs on disk partitions ...'
|
||||
for i in 1 2 3 4 5 6 7; do
|
||||
if [ -b $PART2 ]; then
|
||||
break
|
||||
else
|
||||
echo "wait $PART2 ..."
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if ! [ -b $PART2 ]; then
|
||||
MajorMinor=$(sed "s/:/ /" /sys/class/block/${PART2#/dev/}/dev)
|
||||
echo "mknod -m 0660 $PART2 b $MajorMinor ..."
|
||||
mknod -m 0660 $PART2 b $MajorMinor
|
||||
|
||||
if ! [ -b $PART1 ]; then
|
||||
MajorMinor=$(sed "s/:/ /" /sys/class/block/${PART1#/dev/}/dev)
|
||||
echo "mknod -m 0660 $PART1 b $MajorMinor ..."
|
||||
mknod -m 0660 $PART1 b $MajorMinor
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "create efi fat fs $PART2 ..."
|
||||
for i in 0 1 2 3 4 5 6 7 8 9; do
|
||||
if mkfs.vfat -F 16 -n VTOYEFI $PART2; then
|
||||
echo 'success'
|
||||
break
|
||||
else
|
||||
echo "$? retry ..."
|
||||
sleep 2
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue