Skip to content

Commit

Permalink
Update ventoy_lib.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ventoy authored May 24, 2020
1 parent 73c196a commit a54b6f6
Showing 1 changed file with 27 additions and 31 deletions.
58 changes: 27 additions & 31 deletions INSTALL/tool/ventoy_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,17 @@ ventoy_is_linux64() {
ventoy_false
}

ventoy_is_dash() {
if [ -L /bin/sh ]; then
vtdst=$(readlink /bin/sh)
if [ "$vtdst" = "dash" ]; then
ventoy_true
return
fi
fi
ventoy_false
}

vtinfo() {
if ventoy_is_dash; then
echo "\033[32m$*\033[0m"
else
echo -e "\033[32m$*\033[0m"
fi
echo -e "\033[32m$*\033[0m"
}

vtwarn() {
if ventoy_is_dash; then
echo "\033[33m$*\033[0m"
else
echo -e "\033[33m$*\033[0m"
fi
echo -e "\033[33m$*\033[0m"
}


vterr() {
if ventoy_is_dash; then
echo "\033[31m$*\033[0m"
else
echo -e "\033[31m$*\033[0m"
fi
echo -e "\033[31m$*\033[0m"
}

vtdebug() {
Expand Down Expand Up @@ -207,7 +184,6 @@ get_disk_ventoy_version() {
ventoy_false
}


format_ventoy_disk() {
DISK=$1
PART1=$(get_disk_part_name $DISK 1)
Expand All @@ -220,15 +196,30 @@ format_ventoy_disk() {
export part2_start_sector=$(expr $part1_end_sector + 1)
part2_end_sector=$(expr $sector_num - 1)

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 ..."
echo "Create partitions on $DISK by $2 ..."

if [ "$2" = "parted" ]; then
vtdebug "format disk by parted ..."
parted -a none --script $DISK \
mklabel msdos \
unit s \
mkpart primary ntfs $part1_start_sector $part1_end_sector \
mkpart primary fat16 $part2_start_sector $part2_end_sector \
set 2 boot on \
quit
else
vtdebug "format disk by fdisk ..."

fdisk $DISK >/dev/null 2>&1 <<EOF
fdisk $DISK >>./log.txt 2>&1 <<EOF
o
n
p
Expand All @@ -250,7 +241,8 @@ a
2
w
EOF

fi

echo "Done"
udevadm trigger >/dev/null 2>&1
partprobe >/dev/null 2>&1
Expand All @@ -265,7 +257,11 @@ EOF
sleep 1
fi
done


if [ "$2" = "parted" ]; then
echo -en '\xEF' | dd of=$DISK conv=fsync bs=1 count=1 seek=466
fi

if ! [ -b $PART2 ]; then
MajorMinor=$(sed "s/:/ /" /sys/class/block/${PART2#/dev/}/dev)
echo "mknod -m 0660 $PART2 b $MajorMinor ..."
Expand Down

0 comments on commit a54b6f6

Please sign in to comment.