4 VENTOY_PART_SIZE
=33554432
6 VENTOY_SECTOR_NUM
=65536
17 if uname
-a | egrep -q 'x86_64|amd64'; then
26 echo -e "\033[32m$*\033[0m"
30 echo -e "\033[33m$*\033[0m"
35 echo -e "\033[31m$*\033[0m"
39 echo "$*" >> .
/log.txt
42 check_tool_work_ok
() {
44 if ventoy_is_linux64
; then
45 vtdebug
"This is linux 64"
46 mkexfatfs
=mkexfatfs_64
49 vtdebug
"This is linux 32"
50 mkexfatfs
=mkexfatfs_32
54 if echo 1 | .
/tool
/hexdump > /dev
/null
; then
55 vtdebug
"hexdump test ok ..."
57 vtdebug
"hexdump test fail ..."
62 if .
/tool
/$mkexfatfs -V > /dev
/null
; then
63 vtdebug
"$mkexfatfs test ok ..."
65 vtdebug
"$mkexfatfs test fail ..."
70 if .
/tool
/$vtoyfat -T; then
71 vtdebug
"$vtoyfat test ok ..."
73 vtdebug
"$vtoyfat test fail ..."
78 vtdebug
"tool check success ..."
83 get_disk_part_name
() {
86 if echo $DISK | grep -q "/dev/loop"; then
88 elif echo $DISK | grep -q "/dev/nvme[0-9][0-9]*n[0-9]"; then
96 get_ventoy_version_from_cfg
() {
97 if grep -q 'set.*VENTOY_VERSION=' $1; then
98 grep 'set.*VENTOY_VERSION=' $1 | awk -F'"' '{print $2}'
104 is_disk_contains_ventoy
() {
107 PART1
=$(get_disk_part_name $1 1)
108 PART2
=$(get_disk_part_name $1 2)
110 if [ -e /sys
/class
/block
/${PART2#/dev/}/size
]; then
111 SIZE
=$(cat /sys/class/block/${PART2#/dev/}/size)
116 if ! [ -b $PART1 ]; then
117 vtdebug
"$PART1 not exist"
122 if ! [ -b $PART2 ]; then
123 vtdebug
"$PART2 not exist"
128 PART2_TYPE
=$(dd if=$DISK bs=1 count=1 skip=466 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
129 if [ "$PART2_TYPE" != "EF" ]; then
130 vtdebug
"part2 type is $PART2_TYPE not EF"
135 # PART1_TYPE=$(dd if=$DISK bs=1 count=1 skip=450 status=none | ./tool/hexdump -n1 -e '1/1 "%02X"')
136 # if [ "$PART1_TYPE" != "07" ]; then
137 # vtdebug "part1 type is $PART2_TYPE not 07"
142 if [ -e /sys
/class
/block
/${PART1#/dev/}/start
]; then
143 PART1_START
=$(cat /sys/class/block/${PART1#/dev/}/start)
146 if [ "$PART1_START" != "2048" ]; then
147 vtdebug
"part1 start is $PART1_START not 2048"
152 if [ "$VENTOY_SECTOR_NUM" != "$SIZE" ]; then
153 vtdebug
"part2 size is $SIZE not $VENTOY_SECTOR_NUM"
161 get_disk_ventoy_version
() {
163 if ! is_disk_contains_ventoy
$1; then
168 PART2
=$(get_disk_part_name $1 2)
170 if ventoy_is_linux64
; then
171 cmd
=.
/tool
/vtoyfat_64
173 cmd
=.
/tool
/vtoyfat_32
176 ParseVer
=$($cmd $PART2)
177 if [ $?
-eq 0 ]; then
178 vtdebug
"Ventoy version in $PART2 is $ParseVer"
187 format_ventoy_disk
() {
189 PART1
=$(get_disk_part_name $DISK 1)
190 PART2
=$(get_disk_part_name $DISK 2)
192 sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
194 part1_start_sector
=2048
195 part1_end_sector
=$(expr $sector_num - $VENTOY_SECTOR_NUM - 1)
196 export part2_start_sector
=$(expr $part1_end_sector + 1)
197 part2_end_sector
=$(expr $sector_num - 1)
199 vtdebug
"part1_start_sector=$part1_start_sector part1_end_sector=$part1_end_sector"
200 vtdebug
"part2_start_sector=$part2_start_sector part2_end_sector=$part2_end_sector"
202 if [ -e $PART2 ]; then
208 echo "Create partitions on $DISK by $2 ..."
210 if [ "$2" = "parted" ]; then
211 vtdebug
"format disk by parted ..."
212 parted
-a none
--script $DISK \
215 mkpart primary ntfs
$part1_start_sector $part1_end_sector \
216 mkpart primary fat16
$part2_start_sector $part2_end_sector \
220 vtdebug
"format disk by fdisk ..."
222 fdisk
$DISK >>.
/log.txt
2>&1 <<EOF
247 udevadm trigger
>/dev
/null
2>&1
248 partprobe
>/dev
/null
2>&1
251 echo 'mkfs on disk partitions ...'
252 for i
in 1 2 3 4 5 6 7; do
253 if [ -b $PART2 ]; then
256 echo "wait $PART2 ..."
261 if [ "$2" = "parted" ]; then
262 echo -en '\xEF' | dd of
=$DISK conv
=fsync bs
=1 count
=1 seek
=466
265 if ! [ -b $PART2 ]; then
266 MajorMinor
=$(sed "s/:/ /" /sys/class/block/${PART2#/dev/}/dev)
267 echo "mknod -m 0660 $PART2 b $MajorMinor ..."
268 mknod
-m 0660 $PART2 b
$MajorMinor
270 if ! [ -b $PART1 ]; then
271 MajorMinor
=$(sed "s/:/ /" /sys/class/block/${PART1#/dev/}/dev)
272 echo "mknod -m 0660 $PART1 b $MajorMinor ..."
273 mknod
-m 0660 $PART1 b
$MajorMinor
277 echo "create efi fat fs ..."
278 for i
in 0 1 2 3 4 5 6 7 8 9; do
279 if mkfs.vfat
-F 16 -n EFI
$PART2; then