本帖最後由 阿達金田一 於 2021-2-15 20:51 編輯
如果要用 find /bootmgr 又要完美一點...
就比較麻煩...不過你找的那個文章...其實裡面有解答了
只是沒有寫的比較完整
先假設 usb 中有一個檔案 flag.usb 做為判斷 usb 的旗標檔
[Bash shell] 純文本查看 復制代碼
find --ignore-floppies --ignore-cd /flag.usb | set usb=
set list=(md)0x60500+0x100
find --ignore-floppies --ignore-cd /bootmgr > %list%
cat --length=10 --skip=0 %list% | set p=
if exist p if "%p%"=="%usb%" set p=
if exist p root %p% && chainloader /bootmgr && boot
cat --length=10 --skip=10 %list% | set p=
if exist p if "%p%"=="%usb%" set p=
if exist p root %p% && chainloader /bootmgr && boot
第1行...沒啥好說...就是找出 usb 的位置
第3行...用來暫存 find /bootmgr 輸出 的 記憶體位址
第4行...把 find /bootmgr 輸出 到 記憶體位址
第6行 ... 記憶體位址 跳過0個字元 長度10 輸出到 set p=
第7行 ... 如果 變數p 存在時 , 則如果 %p% 等於 %usb% , 則 set p=
簡單說就是... 變數p 存在 且 "%p%" 等於 "%usb%" 時 , 刪除 變數p
第8行 ... 如果 變數p 存在時 , root + chainloader + boot
簡單說就是... 變數p 存在...才會跑 root + chainloader + boot
至於後面就是 6-8 的重覆...
第10行... 就是跳過10個字元, 也就是 find 輸出的第2個
我這裡是只用2次...
也就是會判斷 find /bootmgr 輸出的前2個
這裡建議是 find 一定要用 --ignore-floppies --ignore-cd
因為這樣 find 輸出 基本應該都是 (hdx,x) ... 字串長度才一致 , 不然可能會出問題
而2次其實就夠了...因為只是要找出第1個 不是 usb 的 bootmgr
正常應該 usb 也應該只有 1 個...
也就是就算 usb 排前面 , 前2個只有一個會是 usb 的 bootmgr
當然如果你 usb 中一堆 /bootmgr 那可能要多重覆幾次
如果把 win bootmgr 的 hdd 用 map 交換到 hd0 也可以
[Bash shell] 純文本查看 復制代碼
find --ignore-floppies --ignore-cd /flag.usb | set usb=
set list=(md)0x60500+0x100
find --ignore-floppies --ignore-cd /bootmgr > %list%
cat --length=10 --skip=0 %list% | set p=
if exist p if "%p%"=="%usb%" set p=
if exist p root %p% && map () (hd0) && map (hd0) () && map --hook
cat --length=10 --skip=10 %list% | set p=
if exist p if "%p%"=="%usb%" set p=
if exist p root %p% && map () (hd0) && map (hd0) () && map --hook
root (hd0)
chainloader /bootmgr
補充個用 批次檔 來處理的方式...就是會自動重覆判斷...直到沒資料
[Bash shell] 純文本查看 復制代碼 !BAT
find --ignore-floppies --ignore-cd /flag.usb | set usb=
set list=(md)0x60500+0x100
find --ignore-floppies --ignore-cd %1 > %%list%%
echo find %1
cat %%list%%
set /a sk=0
:find
cat --length=10 --skip=%%sk%% %%list%% | set p=
set /a sk=%%sk%%+10
if not exist p exit
if "%%p%%"=="%%usb%%" goto :find
echo %%p%% boot
root %%p%%
chainloader %1
boot
假設批次檔存成 /grub4dos/hddboot.bat
title hdd boot
/grub4dos/hddboot.bat /bootmgr
/grub4dos/hddboot.bat /ntldr
簡單說就是後面加上要 find 的檔案
|