4 VENTOY_PART_SIZE
=33554432
6 VENTOY_SECTOR_NUM
=65536
17 if [ -e /lib64
]; then
22 if [ -e /usr
/lib64
]; then
27 if uname
-a | egrep -q 'x86_64|amd64'; then
36 if [ -L /bin
/sh
]; then
37 vtdst
=$(readlink /bin/sh)
38 if [ "$vtdst" = "dash" ]; then
47 if ventoy_is_dash
; then
48 echo "\033[32m$*\033[0m"
50 echo -e "\033[32m$*\033[0m"
55 if ventoy_is_dash
; then
56 echo "\033[33m$*\033[0m"
58 echo -e "\033[33m$*\033[0m"
64 if ventoy_is_dash
; then
65 echo "\033[31m$*\033[0m"
67 echo -e "\033[31m$*\033[0m"
72 echo "$*" >> .
/log.txt
75 check_tool_work_ok
() {
77 if ventoy_is_linux64
; then
78 vtdebug
"This is linux 64"
79 mkexfatfs
=mkexfatfs_64
82 vtdebug
"This is linux 32"
83 mkexfatfs
=mkexfatfs_32
87 if echo 1 | .
/tool
/hexdump > /dev
/null
; then
88 vtdebug
"hexdump test ok ..."
90 vtdebug
"hexdump test fail ..."
95 if .
/tool
/$mkexfatfs -V > /dev
/null
; then
96 vtdebug
"$mkexfatfs test ok ..."
98 vtdebug
"$mkexfatfs test fail ..."
103 if .
/tool
/$vtoyfat -T; then
104 vtdebug
"$vtoyfat test ok ..."
106 vtdebug
"$vtoyfat test fail ..."
111 vtdebug
"tool check success ..."
116 get_disk_part_name
() {
119 if echo $DISK | grep -q "/dev/loop"; then
121 elif echo $DISK | grep -q "/dev/nvme[0-9][0-9]*n[0-9]"; then
129 get_ventoy_version_from_cfg
() {
130 if grep -q 'set.*VENTOY_VERSION=' $1; then
131 grep 'set.*VENTOY_VERSION=' $1 | awk -F'"' '{print $2}'
137 is_disk_contains_ventoy
() {
140 PART1
=$(get_disk_part_name $1 1)
141 PART2
=$(get_disk_part_name $1 2)
143 if [ -e /sys
/class
/block
/${PART2#/dev/}/size
]; then
144 SIZE
=$(cat /sys/class/block/${PART2#/dev/}/size)
149 if ! [ -b $PART1 ]; then
150 vtdebug
"$PART1 not exist"
155 if ! [ -b $PART2 ]; then
156 vtdebug
"$PART2 not exist"
161 PART2_TYPE
=$(dd if=$DISK bs=1 count=1 skip=466 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
162 if [ "$PART2_TYPE" != "EF" ]; then
163 vtdebug
"part2 type is $PART2_TYPE not EF"
168 PART1_TYPE
=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
169 if [ "$PART1_TYPE" != "07" ]; then
170 vtdebug
"part1 type is $PART2_TYPE not 07"
175 if [ -e /sys
/class
/block
/${PART1#/dev/}/start
]; then
176 PART1_START
=$(cat /sys/class/block/${PART1#/dev/}/start)
179 if [ "$PART1_START" != "2048" ]; then
180 vtdebug
"part1 start is $PART1_START not 2048"
185 if [ "$VENTOY_SECTOR_NUM" != "$SIZE" ]; then
186 vtdebug
"part2 size is $SIZE not $VENTOY_SECTOR_NUM"
194 get_disk_ventoy_version
() {
196 if ! is_disk_contains_ventoy
$1; then
201 PART2
=$(get_disk_part_name $1 2)
203 if ventoy_is_linux64
; then
204 cmd
=.
/tool
/vtoyfat_64
206 cmd
=.
/tool
/vtoyfat_32
209 ParseVer
=$($cmd $PART2)
210 if [ $?
-eq 0 ]; then
211 vtdebug
"Ventoy version in $PART2 is $ParseVer"
221 format_ventoy_disk
() {
223 PART2
=$(get_disk_part_name $DISK 2)
225 sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
227 part1_start_sector
=2048
228 part1_end_sector
=$(expr $sector_num - $VENTOY_SECTOR_NUM - 1)
229 export part2_start_sector
=$(expr $part1_end_sector + 1)
230 part2_end_sector
=$(expr $sector_num - 1)
232 if [ -e $PART2 ]; then
238 echo "Create partitions on $DISK ..."
240 fdisk
$DISK >/dev
/null
2>&1 <<EOF
264 udevadm trigger
>/dev
/null
2>&1
265 partprobe
>/dev
/null
2>&1
269 echo 'mkfs on disk partitions ...'
270 while ! [ -e $PART2 ]; do
271 echo "wait $PART2 ..."
275 echo "create efi fat fs ..."
276 for i
in 0 1 2 3 4 5 6 7 8 9; do
277 if mkfs.vfat
-F 16 -n EFI
$PART2; then