And this particular mechanism described here is for x86 only. It's unfortunate that the boot mechanism is architecture specific.
Anyway, back to boot arguments. Using grub, you use the menu.lst file to determine how the system boots. In particular, the kernel$ line specifies which kernel to boot, and you can pass boot arguments. For example, it might say
kernel$ /platform/i86pc/kernel/$ISADIR/unix -B console=ttya
and, in this case, what comes after -B is the boot arguments. This is a list of key=value pairs, comma separated.
Another example, from my implementation of PXE boot,might be:
-B install_pkgs=http://172.18.1.7:8080/pkgs/0m8/pkgs/
So that's how they're defined, and you can really define anything you like. It's up to the system to interpret them as it sees fit.
When the system boots, how do you access these parameters? They're present in the system configuration as displayed by prtconf. In particular
prtconf -v /devices
gets you the information you want - containing a bunch of standard information and the boot arguments. Try this on a running system, and you'll see things like what program actually got booted:
name='bootprog' type=string items=1
value='/platform/i86pc/multiboot'
So, all you have to do to find the value of a boot argument is look through the prtconf output for the name of the boot argument you're after, and then pick the value off the next line. Going back to my example earlier, we just look for install_pkgs and get the value. This little snippet does the job:
PKGMEDIA=`/usr/sbin/prtconf -v /devices | \
/usr/bin/sed -n '/install_pkgs/{;n;p;}' | \
/usr/bin/cut -f 2 -d \'`
(Breaking this down, sed -n outputs nothing by default, looks for the pattern in /install_pkgs/, then the {;n;p;} skips to the next line and prints it, then cut grabs the second word, split by the quote. Ugly as heck.)
At this point, you can test whether the argument was defined, and use it in your scripts.
2 comments:
see also devprop which is an easier way to get boot arguments. Not sure if it was part of OpenSolaris or if it came later in Solaris 11 though.
Hm. I see devprop is definitely there in illumos, and using it means I can strip a little more out of the boot archive, which is always going to help.
Post a Comment