User/kernelspace stuff to set/get kernel variables
Hello
I've been looking on the web, and couldn't really find what i would want...
Basically: is it possible to - one way or another - set variables at kernel boot and read those using userspace utilities?
for instance: i boot my kernel (using any old bootmanager that accepts kernel params)
LILO: linux network=dhcp
and later, in the init scripts, i check the value of this variable using some sort of userspace program, and if it happends to be 'dhcp' i'll invoke the dhcp client. Otherwise i'd just give a static address.
I have other uses for this, for instance, you want your disks to be FSCK'ed, but don't wanna boot first, or, don't wanna go in single user mode
LILO: linux dofsck=true
Does something like this exist? Is it implementable in an easy way? (I know a few programming languages, but only little C(++)....)
Thanks
DK
Quoted 5 lines · DevilKin
Hello
I've been looking on the web, and couldn't really find what i would want...
Basically: is it possible to - one way or another - set variables at kernel boot and read those using userspace utilities?
Sorry, I don't know, but see below for possible solution to your problem anyway.
Quoted 4 lines
for instance: i boot my kernel (using any old bootmanager that accepts kernel params)
LILO: linux network=dhcp
You might want to familiarize yourself with the following kernel parameter:
"ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>"
where most options are obvious, and you'll probably want device to be "eth0" and autoconf to be "dhcp".
HTH,
Daniel
Quoted 20 lines
and later, in the init scripts, i check the value of this variable using some sort of userspace program, and if it happends to be 'dhcp' i'll invoke the dhcp client. Otherwise i'd just give a static address.
I have other uses for this, for instance, you want your disks to be FSCK'ed, but don't wanna boot first, or, don't wanna go in single user mode
LILO: linux dofsck=true
Does something like this exist? Is it implementable in an easy way? (I know a few programming languages, but only little C(++)....)
Thanks
DK
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 4 lines
Daniel A. Freedman Laboratory for Atomic and Solid State Physics Department of Physics Cornell University
Quoted 11 lines · DevilKin
Hello
I've been looking on the web, and couldn't really find what i would want...
Basically: is it possible to - one way or another - set variables at kernel boot and read those using userspace utilities?
for instance: i boot my kernel (using any old bootmanager that accepts kernel params)
LILO: linux network=dhcp
Is this what you want?
cat /proc/cmdline
Cheers,
Dick Johnson
Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).
Santa Claus is coming to town...
He knows if you've been sleeping,
He knows if you're awake;
He knows if you've been bad or good,
So he must be Attorney General Ashcroft.
Hi DK.
Quoted 8 lines
Basically: is it possible to - one way or another - set variables at kernel boot and read those using userspace utilities?
for instance: i boot my kernel (using any old bootmanager that accepts kernel params)
LILO: linux network=dhcp
and later, in the init scripts, i check the value of this variable using some sort of userspace program, and if it happends to be 'dhcp' i'll invoke the dhcp client.
[--8<--SNIP--8<--]
You'll at least find that in /proc/1/environ
It's a null-terminated list of strings that consist of what you want. You'll see it as well while dumping the kernel log (dmesg) at the begining. For my machine, I have:
--8<--
Kernel command line: auto BOOT_IMAGE=linux root=806 devfs=mount idebus=33 --8<--
Regards,
Yann.
--
.---------------------------.----------------------.------------------.
| Yann E. MORIN | Real-Time Embedded | ASCII RIBBON /"\ | | phone (+33/0) 299 055 231 | Software Designer | CAMPAIGN \ / | | fax (+33/0) 299 055 221 °----------------------: AGAINST X | | [email protected] www.atosorigin.com | HTML MAIL / \ |
°--------------------------------------------------°------------------°
Quoted 15 lines · DevilKin
Hello
I've been looking on the web, and couldn't really find what i would want...
Basically: is it possible to - one way or another - set variables at kernel boot and read those using userspace utilities?
for instance: i boot my kernel (using any old bootmanager that accepts kernel params)
LILO: linux network=dhcp
and later, in the init scripts, i check the value of this variable using some sort of userspace program, and if it happends to be 'dhcp' i'll invoke the dhcp client. Otherwise i'd just give a static address.
Quoted 8 lines
I have other uses for this, for instance, you want your disks to be FSCK'ed, but don't wanna boot first, or, don't wanna go in single user mode
LILO: linux dofsck=true
Does something like this exist? Is it implementable in an easy way? (I know a few programming languages, but only little C(++)....)
If you pass a parameter that is not recognized by the kernel, it will be passed to init as environment variable,
so all you need to do is check for the variable in your init scripts ($network in your example).
regards, Jan.
Quoted 9 lines
Thanks
DK
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 3 lines · Jan Janak
If you pass a parameter that is not recognized by the kernel, it will be passed to init as environment variable, so all you need to do is check for the variable in your init scripts ($network in your example).
IIRC, Red Hat scripts grab them from /proc/cmdline
--
Russell King ([email protected]) The developer of ARM Linux
http://www.arm.linux.org.uk/personal/aboutme.html
Quoted 6 lines · Russell King
Quoted 3 lines · Jan Janak
If you pass a parameter that is not recognized by the kernel, it will be passed to init as environment variable, so all you need to do is check for the variable in your init scripts ($network in your example).
IIRC, Red Hat scripts grab them from
/proc/cmdline
Only parameters of the form foo=bar will be set as environment variables (if not
recognized by the kernel).
AFAIK Red Hat scripts grab parameters of different form from /proc/cmdline.
But parameter of the form network=dhcp will be set as environment variable and
this is IMHO the easiest way how to get the parameter value in startup scripts.
regards, Jan.
Quoted 4 lines
--
Russell King ([email protected]) The developer of ARM Linux
http://www.arm.linux.org.uk/personal/aboutme.html
Followup to: <[email protected]> By author: DevilKin <[email protected]> In newsgroup: linux.dev.kernel
Quoted 8 lines
Hello
I've been looking on the web, and couldn't really find what i would want...
Basically: is it possible to - one way or another - set variables at kernel boot and read those using userspace utilities?
The entire kernel command line is quoted verbatim in /proc/cmdline.
Additionally, items of the form foo=bar that are not recognized by the kernel become environment variables to init, and items not of that form *sometimes* become command-line options to init...
-hpa
Signature · 3 lines
<[email protected]> at work, <[email protected]> in private! "Unix gives you enough rope to shoot yourself in the foot." http://www.zytor.com/~hpa/puzzle.txt <[email protected]>