Hi.
I'm trying to make a menu entry to start a specific Linux distro (usually installed on the USB drive).
Until now I used this:
title Start Linux root (hd0,n) kernel /boot/kernel_name root=UUID=[...] [other kernel parameters] initrd /boot/initrd_name
The problem is that it's very "static" (instead of "dynamic"). If I change the Linux kernel I have to modify it manually. It's not a big issue to change some numbers (most of the times) but still...
Another thing: if there is more than one kernel to be able to show options to boot with each one (a menu entry for each one).
What I've done so far:
In menu.lst I add:
title Start Linux from USB drive set FOUNDS=0 set FOUNDM=0 call /findkrnl.g4b if "%FOUNDS%"=="1" kernel /boot/%KERNEL% root=UUID=[...] [kernel parameters] && initrd /boot/initramfs-%KERVER%.fc18.i686.img && boot if "%FOUNDM%"=="1" write (md)0x220+8 %FK1%%FK2%%FK3%%FK4%%FK5%%FK6%%FK7%%FK8%%FK9%%FK10%title\r\nroot\r\ntitle Return to main menu...\r\nroot (bd)\r\nconfigfile /menu.lst\r\n\0 > nul && configfile (md)0x220+8 root (bd) configfile /menu.lst
Adding "configfile /menu.lst" to the end seems redundant but it is necessary so the menu entry should be selected with the up/down keys. Without this line you can't select it; you'll have to use left/right keys.
Is there a better "workaround"?
Also, adding "&& boot" seems redundant since it's not usually needed but in this case Linux won't boot because of the "configfile /menu.lst" line...
findkrnl.g4b:
!BAT clear find --set-root --ignore-floppies --ignore-cd uuid () [...] > nul || echo Linux partition not found! Returning to main menu... && pause --wait=5 && goto :finish ls /boot/ > (md)0x220+8 || echo /boot not found! Returning to main menu... && pause --wait=5 && root (bd) && goto :finish cat --locate=" vmlinuz-" (md)0x220+8 > (md)0x300+1 || echo kernel not found! Returning to main menu... && pause --wait=5 && root (bd) && goto :finish cat --skip=1 --locate=" " (md)0x300+1 > nul && goto :multi cat --skip=1 (md)0x300+1 | set VMPOSB= debug -1 set /a VMPOSB=0x%VMPOSB%+1 debug normal cat --skip=%VMPOSB% --locate=".fc18.i686" --number=1 (md)0x220+8 | set VMPOSE= if "%VMPOSE%"=="" echo kernel not found! Returning to main menu... && pause --wait=5 && root (bd) && goto :finish debug -1 set /a VMLEN=0x%VMPOSE%+10-%VMPOSB% debug normal cat --skip=%VMPOSB% --length=%VMLEN% (md)0x220+8 | set KERNEL= if not exist /boot/%KERNEL% echo kernel not found! Returning to main menu... && pause --wait=5 && root (bd) && goto :finish debug -1 set /a KERVERB=%VMPOSB%+8 set /a KERVERL=0x%VMPOSE%-%KERVERB% debug normal cat --skip=%KERVERB% --length=%KERVERL% (md)0x220+8 | set KERVER= if not exist /boot/initramfs-%KERVER%.fc18.i686.img echo initrd not found! Returning to main menu... && pause --wait=5 && root (bd) && goto :finish set FOUNDS=1 goto :finish :multi set SKIPPED=1 set ENDPOS=0 set N=1 :loop cat --skip=%SKIPPED% --locate=" " --number=1 (md)0x300+1 | set LE= if "%LE%"=="" goto :le0 debug -1 set /a ORGLE=%LE% set /a LE=0x%LE%-%SKIPPED% debug normal cat --skip=%SKIPPED% --length=%LE% (md)0x300+1 | set VMPOSB= debug -1 set /a SKIPPED=0x%ORGLE%+1 debug normal goto :endle :le0 cat --skip=%SKIPPED% (md)0x300+1 | set VMPOSB= set ENDPOS=1 :endle debug -1 set /a VMPOSB=0x%VMPOSB%+1 debug normal cat --skip=%VMPOSB% --locate=".fc18.i686" --number=1 (md)0x220+8 | set VMPOSE= if "%VMPOSE%"=="" goto :finish debug -1 set /a VMLEN=0x%VMPOSE%+10-%VMPOSB% debug normal cat --skip=%VMPOSB% --length=%VMLEN% (md)0x220+8 | set KERNEL= if exist /boot/%KERNEL% goto :ifkerx if "%ENDPOS%"=="1" goto :endloop cat --skip=%SKIPPED% (md)0x300+1 > nul || goto :endloop goto :loop :ifkerx debug -1 set /a KERVERB=%VMPOSB%+8 set /a KERVERL=0x%VMPOSE%-%KERVERB% debug normal cat --skip=%KERVERB% --length=%KERVERL% (md)0x220+8 | set KERVER= if exist /boot/initramfs-%KERVER%.fc18.i686.img goto :ifintx if "%ENDPOS%"=="1" goto :endloop cat --skip=%SKIPPED% (md)0x300+1 > nul || goto :endloop goto :loop :ifintx set FK%N%=title start Linux with %KERVER% kernel\r\nkernel /boot/%KERNEL% root=UUID=[...] [kernel parameters]\r\ninitrd /boot/initramfs-%KERVER%.fc18.i686.img\r\n set FKV%N%=%KERVER% debug -1 set FOUNDM=1 set /a N=%N%+1 debug normal if "%N%"=="11" goto :endloop if "%ENDPOS%"=="1" goto :endloop cat --skip=%SKIPPED% (md)0x300+1 > nul || goto :endloop goto :loop :endloop if "%FOUNDM%"=="0" echo No valid boot files found! Returning to main menu... && pause --wait=5 && root (bd) && goto :finish if "%N%"=="2" set FOUNDM=0 && set FOUNDS=1 && set KERNEL=vmlinuz-%FKV1%.fc18.i686 && set KERVER=%FKV1% :finish
It works almost fine.
I would appreciate any tip to help me improve speed, accuracy, memory usage and so on.
Also I'm trying to find a way to show the menu entries in ascending order, from the oldest kernel to the newest.
I know how to do a "bubble sort" but the problem is comparing the strings (FK%N%).
First I will have to divide them into "parts":
3.9.2-200 >> 3 9 2 200
But I couldn't find a function to search for a character or a substring in a string. "cat" would of been great but it works only with files...
After that I will have to compare each of the corresponding "parts". The problem is that I don't know a way to find if a value is higher or lower than other value, only to know if they are equal or not.
Could you please help me with these...?
Thank you.
Regards, David