Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
kernel boot args as environment variables
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
dobbs
Tux's lil' helper
Tux's lil' helper


Joined: 20 Aug 2005
Posts: 105
Location: Wenatchee, WA

PostPosted: Wed Jul 21, 2010 10:08 pm    Post subject: kernel boot args as environment variables Reply with quote

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
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Thu Jul 22, 2010 12:28 am    Post subject: Reply with quote

look for it in cat /proc/cmdline
Back to top
View user's profile Send private message
dobbs
Tux's lil' helper
Tux's lil' helper


Joined: 20 Aug 2005
Posts: 105
Location: Wenatchee, WA

PostPosted: Fri Jul 23, 2010 1:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
lxg
Veteran
Veteran


Joined: 12 Nov 2005
Posts: 1019
Location: Aachen, Germany

PostPosted: Fri Jul 23, 2010 2:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
dobbs
Tux's lil' helper
Tux's lil' helper


Joined: 20 Aug 2005
Posts: 105
Location: Wenatchee, WA

PostPosted: Sat Jul 24, 2010 6:23 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum