View previous topic :: View next topic |
Author |
Message |
dobbs Tux's lil' helper
Joined: 20 Aug 2005 Posts: 105 Location: Wenatchee, WA
|
Posted: Wed Jul 21, 2010 10:08 pm Post subject: kernel boot args as environment variables |
|
|
So I read somewhere that you can pass environment variables via the boot command line like so (see "nodename"):
Code: | ip=dhcp nodename=clothoprime root=/dev/nfs ro nfsroot=10.0.2.182:/storage/netboot/arch/i686 init=/boot/stateless.sh BOOT_IMAGE=/bzImage.clothoprime |
These are the args for a single system image diskless system where I wanted a quick hack to pass the hostname. Environment variables via PXE kernel args fit that bill, but I can't find the nodename variable anywhere. Anyone else have experience here?
This was a stop-gap solution until I figure out how to read the hostname via dhcp (help appreciated), but I'm obstinate enough to explore why it's not working. |
|
Back to top |
|
|
krinn Watchman
Joined: 02 May 2003 Posts: 7470
|
Posted: Thu Jul 22, 2010 12:28 am Post subject: |
|
|
look for it in cat /proc/cmdline |
|
Back to top |
|
|
dobbs Tux's lil' helper
Joined: 20 Aug 2005 Posts: 105 Location: Wenatchee, WA
|
Posted: Fri Jul 23, 2010 1:55 pm Post subject: |
|
|
Yeah, I saw that, but that's not an environment variable. And even after more than a decade of this stuff, awk and sed still confuse the hell out of me, so parsing that is beyond me.
Do you know if the link in the original post out of date or otherwise incorrect? |
|
Back to top |
|
|
lxg Veteran
Joined: 12 Nov 2005 Posts: 1019 Location: Aachen, Germany
|
Posted: Fri Jul 23, 2010 2:25 pm Post subject: |
|
|
I don't know if that's true; I think somebody wrote it for a reason … but I just tried and I can't reproduce it. Maybe this has also to do with some Gentoo internals, e.g. there could be something that resets environment variables for security reasons.
However, the “scary” sed stuff isn't so bad after all. For example, to parse a command line value into a variable into a shell script, you could do the following:
Code: |
# your /proc/cmdline be: root=/dev/sda2 ro video=uvesafb:1280x1024-32,mtrr:3,ywrap FOOBAR=moobar bla=nah
# and you want to catch the value of FOOBAR (consisting of lowercase letters, numbers, underscores)
MY_SHELLSCRIPT_FOOBAR="$(perl -pe 's|^.*FOOBAR=([a-z0-9_]*).*$|\1|g' /proc/cmdline)"
echo $MY_SHELLSCRIPT_FOOBAR
|
_________________ lxg.de – codebits and tech talk |
|
Back to top |
|
|
dobbs Tux's lil' helper
Joined: 20 Aug 2005 Posts: 105 Location: Wenatchee, WA
|
Posted: Sat Jul 24, 2010 6:23 am Post subject: |
|
|
If something Gentoo is messing with the environment, it'd have to be a kernel patch. I'm calling a script with the init= arg (that eventually chains to init). Pretty sure nothing else is resident. Or I'm just wrong in that assumption. I'm tempted to try this with a vanilla kernel, but I suspect this feature was simply removed.
And thanks for the perl snippet! |
|
Back to top |
|
|
|