]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - INSTALL/Ventoy2Disk.sh
Update Ventoy2Disk.sh
[Ventoy.git] / INSTALL / Ventoy2Disk.sh
index 6432217849da4cde9c9453158022e94bb4784cd9..96dd77fb85cc6e348568db7ec2afd33bebdd14d9 100644 (file)
@@ -110,24 +110,49 @@ if ! check_tool_work_ok; then
     exit 1
 fi
 
+testEF=$(echo -en '\xEF' | ./tool/hexdump -n 1 -e '1/1 "%02X"')
+if [ "$testEF" != "EF" ]; then
+    vtdebug "testEF=##${testEF}##"
+    vterr "There is something wrong with the interpreter !"
+    exit 1
+fi
+
 grep "^$DISK" /proc/mounts | while read mtline; do
-    mtpnt=$(echo $mtline | awk '{print $DISK}')
+    mtpnt=$(echo $mtline | awk '{print $2}')
     vtdebug "Trying to umount $mtpnt ..."
     umount $mtpnt >/dev/null 2>&1
 done
 
+if swapon -s | grep -q "^${DISK}[0-9]"; then
+    swapon -s | grep "^${DISK}[0-9]" | awk '{print $1}' | while read line; do
+        vtdebug "Trying to swapoff $line ..."
+        swapoff $line
+    done
+fi
+
+
 if grep "$DISK" /proc/mounts; then
     vterr "$DISK is already mounted, please umount it first!"
     cd $OLDDIR
     exit 1
 fi
 
+if swapon -s | grep -q "^${DISK}[0-9]"; then
+    vterr "$DISK is used as swap, please swapoff it first!"
+    cd $OLDDIR
+    exit 1
+fi
+
 
 if [ "$MODE" = "install" ]; then
     vtdebug "install ventoy ..."
-    
-    if ! fdisk -v >/dev/null 2>&1; then
-        vterr "fdisk is needed by ventoy installation, but is not found in the system."
+
+    if parted -v > /dev/null 2>&1; then
+        PARTTOOL='parted'
+    elif fdisk -v >/dev/null 2>&1; then
+        PARTTOOL='fdisk'
+    else
+        vterr "Both parted and fdisk are not found in the sysstem, Ventoy can't create new partition."
         cd $OLDDIR
         exit 1
     fi
@@ -191,7 +216,7 @@ if [ "$MODE" = "install" ]; then
         exit 1
     fi
 
-    format_ventoy_disk $DISK
+    format_ventoy_disk $DISK $PARTTOOL
 
     # format part1
     if ventoy_is_linux64; then
@@ -230,6 +255,12 @@ if [ "$MODE" = "install" ]; then
     
     vtinfo "esp partition processing ..."
     
+    sleep 1
+    mtpnt=$(grep "^${DISK}2" /proc/mounts | awk '{print $2}')
+    if [ -n "$mtpnt" ]; then
+        umount $mtpnt >/dev/null 2>&1
+    fi
+    
     if [ "$SECUREBOOT" != "YES" ]; then
         mkdir ./tmp_mnt
         
@@ -239,9 +270,14 @@ if [ "$MODE" = "install" ]; then
                 vtdebug "mounting part2 success"
                 break
             fi
+            
+            mtpnt=$(grep "^${DISK}2" /proc/mounts | awk '{print $2}')
+            if [ -n "$mtpnt" ]; then
+                umount $mtpnt >/dev/null 2>&1
+            fi
             sleep 2
         done
-              
+
         rm -f ./tmp_mnt/EFI/BOOT/BOOTX64.EFI
         rm -f ./tmp_mnt/EFI/BOOT/grubx64.efi
         rm -f ./tmp_mnt/EFI/BOOT/MokManager.efi