Update ventoy_lib.sh

This commit is contained in:
longpanda 2020-05-24 20:25:47 +08:00 committed by GitHub
parent 73c196a823
commit a54b6f692c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 31 deletions

View File

@ -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() {
@ -207,7 +184,6 @@ get_disk_ventoy_version() {
ventoy_false
}
format_ventoy_disk() {
DISK=$1
PART1=$(get_disk_part_name $DISK 1)
@ -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 ..."
fdisk $DISK >/dev/null 2>&1 <<EOF
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 >>./log.txt 2>&1 <<EOF
o
n
p
@ -250,6 +241,7 @@ a
2
w
EOF
fi
echo "Done"
udevadm trigger >/dev/null 2>&1
@ -266,6 +258,10 @@ EOF
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 ..."