Debian Codegraph @

pkg/syslinux/makeboot64.cmd

raw
1 @echo off
2 setlocal EnableDelayedExpansion
3 rem 12/21/2026 - replaced wmic with PowerShell command and changed to use batch file label subroutines
4 rem This batch file was modified by Tom Hoar.
5 rem 01/13/2016 - Added error routine and other minor changes by Robert Rubino
6 rem This batch file was modified by Steven Shiau.
7 rem The original one is from PDLA http://pendrivelinux.com
8 rem This batch file was created by ©2007 PDLA http://pendrivelinux.com
9
10 call :main %*
11
12 exit /b %ERRORLEVEL%
13
14
15 :main
16
17 title %~nx0
18 pushd "%~dp0"
19
20 call :test-systemdrive
21 if %ERRORLEVEL% neq 0 ( exit /b %ERRORLEVEL% )
22
23 call :welcome
24
25 call :test-filesystem
26 if %ERRORLEVEL% neq 0 ( exit /b %ERRORLEVEL% )
27
28 call :make-bootable
29 if %ERRORLEVEL% equ 0 (
30 call :success-message
31 ) else (
32 call :fail-message
33 )
34
35 echo *** Press any key to exit this window ***
36 pause > nul
37 color
38
39 popd
40
41 exit /b %ERRORLEVEL%
42
43
44 :test-systemdrive
45 if /i [%~d0] == [%SystemDrive%] (
46 color 4f
47 echo Do not run %~nx0 from your local system hard drive.
48 echo It should only be run from your USB drive.
49 exit /b 1
50 rem echo %~d0 | "%windir%\system32\findstr.exe" /B /I "%SystemDrive%" && color 4f && echo You can _NOT_ RUN %~nx0 from your local system hard drive! It should only be run from your USB drive or USB drive. && goto end
51 ) else (
52 echo Pass. Target drive is not the SystemDrive ^(%SystemDrive%^)
53 )
54 exit /b %ERRORLEVEL%
55
56
57 :welcome
58 echo -----------------------------------------------------------------
59 echo This batch file prepares drive %~d0 for boot using syslinux64
60 echo --------------------- WARNING -----------------------------------
61 echo Run this file from your portable USB drive ONLY.
62 echo.
63 echo Running this file from your hard drive may overwrite your current
64 echo Master Boot Record (MBR) and render your Windows Operating System
65 echo un-bootable. YOU HAVE BEEN WARNED.
66 echo.
67 echo This batch file is offered in hopes that it is useful and
68 echo comes with absolutely no warranty.
69 echo.
70 echo *** USE AT YOUR OWN RISK ***
71 echo -------------------------------------------------------------------
72 REM cls
73 exit /b %ERRORLEVEL%
74
75
76 :test-filesystem
77
78 REM Microsoft depricated wmic. Replace with Powershell
79 REM wmic logicaldisk where caption="%~d0" get filesystem|find "FAT32">nul
80
81 set "_letter=%~d0
82
83 echo.
84 echo Testing the filesystem on drive %_letter%. Please wait. . .
85
86 REM Call PowerShell to get the file system type. Remove the colon (:) in variable
87 for /f "delims=" %%f in ('PowerShell.exe -command "Get-Volume -DriveLetter "%_letter::=%" | Select-Object -ExpandProperty FileSystem"') do (
88 set "FileSystem=%%f"
89 )
90
91 if [%FileSystem%] == [FAT32] (
92 echo The target ^(USB^) drive is FAT32.
93 set /a EXITCODE=0
94 ) else (
95 echo Please format your USB drive as FAT32
96 set /a EXITCODE=1
97 )
98 echo.
99
100 exit /b %EXITCODE%
101
102
103 :make-bootable
104 echo Press any key to make drive %~d0 bootable
105 echo or close this window to abort...
106 pause > nul
107 cls
108 echo syslinux64.exe -d syslinux -mafi %~d0
109 exit /b %ERRORLEVEL%
110
111
112 :success-message
113 color 2D
114 echo.
115 echo ~~~~~~~~ Congratulations ~~~~~~~
116 echo.
117 echo The hidden file ldlinux.sys has been installed.
118 echo Your %~d0 drive should now be bootable.
119 echo //NOTE// If your USB drive fails to boot (maybe buggy BIOS),
120 echo try to use "syslinux64 -d syslinux -sfmar %~d0".
121 exit /b %ERRORLEVEL%
122
123
124 :fail-message
125 color 4f
126 echo.
127 echo ----------------------------
128 echo *** FATAL ERROR ***
129 echo *** %~d0 drive is not bootable for Clonezilla ***
130 echo *** %~nx0 should be run as Administrator ***
131 echo *** or other major failure has occurred ***
132 echo ----------------------------
133 exit /b %ERRORLEVEL%