Jump to content











Photo
- - - - -

grub4dos batch file converts @root drive to Linux equivalent


  • Please log in to reply
2 replies to this topic

#1 Mythenadia

Mythenadia
  • Members
  • 5 posts
  •  
    United States

Posted 17 November 2016 - 04:45 AM

Some Linux kernels accept a boot parameter/cheatcode that say "boot from this drive/partition", but how do you get a Linux drive name in a grub4dos menu?  Place this grub4dos batch file where it can be called from your grub4dos menu.lst:

!BAT
# root2lin.g4b grub4dos batch file by Mythenadia
# Returns @root drive/partition in linux format
# e.g. (hd2,18) in grub4dos becomes sdc19 in linux
# Handy for passing @root as a linux kernel parameter
# Works for 26 drives, but could easily be expanded
# Remove or alter the echoed "sd" prefix if necessary

debug off
setlocal
set /a drv=*0x82a0&0x1f
set /a prt=*0x829e&0xffff+1
call :substr abcdefghijklmnopqrstuvwxyz %drv% 1 | set drv=
echo sd%drv%%%prt%
endlocal
debug normal
exit

:substr
# Generic substring routine where input, start, length can all be variables
# Result goes to stdout, or can be piped to another command
# Typical usage example:
#   call :substr input start length | set output=
#   set /a output = %output%
setlocal
set input=%1
echo %input:~%2,%3%
endlocal
exit

Here's an example of how to use root2lin.g4b in a grub4dos menu.lst:

...
title Porteus 3.2 XFCE\n Booting Linux from beyond partition 15 test
find --set-root --ignore-floppies --ignore-cd /porteus/porteus-v3.2-i586.sgn
call (bd)/root2lin.g4b | set disk=
kernel /boot/syslinux/vmlinuz from=/dev/%disk% changes=/porteus noauto
initrd /boot/syslinux/initrd.xz
...

Yeah, I know you can write a batch file to memory in a grub4dos menu, then run it with initscript, but I couldn't figure out how to pass any parameters that way.

 

Don't know if this would be useful to anyone else, but I thought I'd share it just in case.

 

--

Cheers,

Mythenadia

 



#2 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13333 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 17 November 2016 - 08:27 AM

Well, if this isn't a coincidence ... , we were talking of exactly the same thing just yesterday :w00t: , here, JFYI :):
http://reboot.pro/to...ts-in-grub4dos/
 
So, the day before yesterday there was nothing and now there are four different ways, 3 batches and one set of a few lines to be put in menu.lst ...
 
You are reading the root disk and volume from grub4dos internal locations :thumbsup: , which is much simpler than parsing a string (though it is limited to the root),  and you can make it more compact, getting rid of the subroutine, using a "delayed expansion" trick, i.e.:
set string=abcdefghijklmnopwrstuvwxyz
call set drv=%^string:~%drv%%,1%
The notes on the other thread about disk and volumes still stand, however, the drv is a disk, and the prt is a volume ... :whistling:

:duff:
Wonko

#3 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13333 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 17 November 2016 - 07:44 PM

:thumbsup: Thanks to your use of the variables in memory, and a built-in function for ascii conversion, we have now a one-liner :smiling9::
http://reboot.pro/to...b4dos/?p=200822

:duff:
Wonko






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users