4 VENTOY_PART_SIZE
=33554432
6 VENTOY_SECTOR_NUM
=65536
17 if uname
-a | egrep -q 'x86_64|amd64'; then
26 if [ -L /bin
/sh
]; then
27 vtdst
=$(readlink /bin/sh)
28 if [ "$vtdst" = "dash" ]; then
37 if ventoy_is_dash
; then
38 echo "\033[32m$*\033[0m"
40 echo -e "\033[32m$*\033[0m"
45 if ventoy_is_dash
; then
46 echo "\033[33m$*\033[0m"
48 echo -e "\033[33m$*\033[0m"
54 if ventoy_is_dash
; then
55 echo "\033[31m$*\033[0m"
57 echo -e "\033[31m$*\033[0m"
62 echo "$*" >> .
/log.txt
65 check_tool_work_ok
() {
67 if ventoy_is_linux64
; then
68 vtdebug
"This is linux 64"
69 mkexfatfs
=mkexfatfs_64
72 vtdebug
"This is linux 32"
73 mkexfatfs
=mkexfatfs_32
77 if echo 1 | .
/tool
/hexdump > /dev
/null
; then
78 vtdebug
"hexdump test ok ..."
80 vtdebug
"hexdump test fail ..."
85 if .
/tool
/$mkexfatfs -V > /dev
/null
; then
86 vtdebug
"$mkexfatfs test ok ..."
88 vtdebug
"$mkexfatfs test fail ..."
93 if .
/tool
/$vtoyfat -T; then
94 vtdebug
"$vtoyfat test ok ..."
96 vtdebug
"$vtoyfat test fail ..."
101 vtdebug
"tool check success ..."
106 get_disk_part_name
() {
109 if echo $DISK | grep -q "/dev/loop"; then
111 elif echo $DISK | grep -q "/dev/nvme[0-9][0-9]*n[0-9]"; then
119 get_ventoy_version_from_cfg
() {
120 if grep -q 'set.*VENTOY_VERSION=' $1; then
121 grep 'set.*VENTOY_VERSION=' $1 | awk -F'"' '{print $2}'
127 is_disk_contains_ventoy
() {
130 PART1
=$(get_disk_part_name $1 1)
131 PART2
=$(get_disk_part_name $1 2)
133 if [ -e /sys
/class
/block
/${PART2#/dev/}/size
]; then
134 SIZE
=$(cat /sys/class/block/${PART2#/dev/}/size)
139 if ! [ -b $PART1 ]; then
140 vtdebug
"$PART1 not exist"
145 if ! [ -b $PART2 ]; then
146 vtdebug
"$PART2 not exist"
151 PART2_TYPE
=$(dd if=$DISK bs=1 count=1 skip=466 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
152 if [ "$PART2_TYPE" != "EF" ]; then
153 vtdebug
"part2 type is $PART2_TYPE not EF"
158 # PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
159 # if [ "$PART1_TYPE" != "07" ]; then
160 # vtdebug "part1 type is $PART2_TYPE not 07"
165 if [ -e /sys
/class
/block
/${PART1#/dev/}/start
]; then
166 PART1_START
=$(cat /sys/class/block/${PART1#/dev/}/start)
169 if [ "$PART1_START" != "2048" ]; then
170 vtdebug
"part1 start is $PART1_START not 2048"
175 if [ "$VENTOY_SECTOR_NUM" != "$SIZE" ]; then
176 vtdebug
"part2 size is $SIZE not $VENTOY_SECTOR_NUM"
184 get_disk_ventoy_version
() {
186 if ! is_disk_contains_ventoy
$1; then
191 PART2
=$(get_disk_part_name $1 2)
193 if ventoy_is_linux64
; then
194 cmd
=.
/tool
/vtoyfat_64
196 cmd
=.
/tool
/vtoyfat_32
199 ParseVer
=$($cmd $PART2)
200 if [ $?
-eq 0 ]; then
201 vtdebug
"Ventoy version in $PART2 is $ParseVer"
211 format_ventoy_disk
() {
213 PART2
=$(get_disk_part_name $DISK 2)
215 sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
217 part1_start_sector
=2048
218 part1_end_sector
=$(expr $sector_num - $VENTOY_SECTOR_NUM - 1)
219 export part2_start_sector
=$(expr $part1_end_sector + 1)
220 part2_end_sector
=$(expr $sector_num - 1)
222 if [ -e $PART2 ]; then
228 echo "Create partitions on $DISK ..."
230 fdisk
$DISK >/dev
/null
2>&1 <<EOF
254 udevadm trigger
>/dev
/null
2>&1
255 partprobe
>/dev
/null
2>&1
259 echo 'mkfs on disk partitions ...'
260 while ! [ -e $PART2 ]; do
261 echo "wait $PART2 ..."
265 echo "create efi fat fs ..."
266 for i
in 0 1 2 3 4 5 6 7 8 9; do
267 if mkfs.vfat
-F 16 -n EFI
$PART2; then