DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 13th May 2008
l2fl2f's Avatar
l2fl2f l2fl2f is offline
Real Name: Yves Guerin
Port Guard
 
Join Date: May 2008
Location: Montreal, Quebec, Canada
Posts: 25
Default passing arg from bootloadder to kernel

Hello,

I would like to know if the kernel can get some variables from the bootloader at boot time ? I would like to modify the beastie.4th (menu) to set a variable and the kernel will get it and put it into a variable accessible via sysctl to be process at later time (during boot up, inside a rc.d file).

Thanks in advance for your help.

l2fl2f
Reply With Quote
  #2   (View Single Post)  
Old 13th May 2008
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

It's not entirely clear what exactly you want to accomplish, but you can use loader.conf(5) to set variables, you can view the defaults in /boot/defaults/loader.conf

If this isn't what you mean, then tell what exactly you are trying to do.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #3   (View Single Post)  
Old 13th May 2008
l2fl2f's Avatar
l2fl2f l2fl2f is offline
Real Name: Yves Guerin
Port Guard
 
Join Date: May 2008
Location: Montreal, Quebec, Canada
Posts: 25
Default

Hello,

I will try to do my best to be more precise, the idea behind this post is the following:
I have a laptop and I would like to configure my network setup directly from the boot menu, change the original menu (beastie.4th) with this menu:
Welcome to FreeBSD
1- home network
2- office network
3- dhcp
4- no network
so I need to declare a variable into the bootloader environment (I did it) but I don't know if the kernel can read this variable and put it into the global namespace (or to get it via sysctl variable) so my modified netif shell script (/etc/rc.d) can read this variable to setup correctly the rc.conf, etc.

Regards
Reply With Quote
  #4   (View Single Post)  
Old 13th May 2008
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

Right, I'm far from an expert on this subject, but as far as I can find this isn't possible.

I think it would be easier to implement this as a rc(8) startup script, and use dialog(1) to select the option ...
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #5   (View Single Post)  
Old 13th May 2008
roddierod's Avatar
roddierod roddierod is offline
Real Name: Rod Person
VPN Cryptographer
 
Join Date: Apr 2008
Location: Pittsburgh, Pa
Posts: 437
Default

if you look down around line 271 of beastie.4th you can see hw.ata.ata_dma being set to 0. So I would think that you could set a sysctl variable. I'm no expert at Forth so I'd find some good resources on hacking Forth first.

Carpetsmoker way is easier, if you don't know Forth.
__________________
"The basic tool for the manipulation of reality is the manipulation of words. If you can control the meaning of words, you can control the people who must use the words." -Philip K. Dick
Reply With Quote
  #6   (View Single Post)  
Old 13th May 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

My question is why do you want to set it from /boot/loader?

I would expect scripts in /etc/rc.d to use values supplied from /etc/rc.conf for such needs.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #7   (View Single Post)  
Old 13th May 2008
richardpl richardpl is offline
Spam Deminer
 
Join Date: May 2008
Location: Croatia
Posts: 284
Default

Quote:
Originally Posted by l2fl2f View Post
Welcome to FreeBSD
1- home network
2- office network
3- dhcp
4- no network
Some kind of this can be done if for example home network use different device than office network and kernel then load required device module depending on user input, but userland configuration than should be done through rc.d scripts anyway (depending on loaded network card module).

About user defined variables - not likely possible but check kenv(1) anyway.

You could also load special version of kernel for home/office network.
Reply With Quote
  #8   (View Single Post)  
Old 13th May 2008
lvlamb's Avatar
lvlamb lvlamb is offline
Real Name: Louis V. Lambrecht
Spam Deminer
 
Join Date: May 2008
Location: .be
Posts: 221
Default

You could start the system with no network at all,
then put some ifconfig and dhclient in a wrapper (with all other network related stuff as ntpd or starting your mail fetcher).
Will even boot faster.
__________________
da more I know I know I know nuttin'
Reply With Quote
  #9   (View Single Post)  
Old 13th May 2008
l2fl2f's Avatar
l2fl2f l2fl2f is offline
Real Name: Yves Guerin
Port Guard
 
Join Date: May 2008
Location: Montreal, Quebec, Canada
Posts: 25
Wink

Hello,

I look into the beastie.4th and I am not an expert of Forth, so the bootloader init some sysctl variables, I look into the src/sys/sys/sysctl.h and I find the kern.dummy to be unused for now, I will try to set this variable depending of the selection from the new menu:

Welcome to FreeBSD
1- home network
2- office network
3- dhcp
4- no network

I try to display this menu with my netif rc.d script but if you start with a splash screen, the splash screen hide the menu and you wait until you realized that it take time (I send a sound to the speaker, but if the sound volume is off ...).

Thank in advance for your help, stay tune to get more news
Reply With Quote
Old 14th May 2008
l2fl2f's Avatar
l2fl2f l2fl2f is offline
Real Name: Yves Guerin
Port Guard
 
Join Date: May 2008
Location: Montreal, Quebec, Canada
Posts: 25
Default

Hello,

testing:

I add the following line into the beastie.4th:

# variables section
variable bootyg

I add the following line into the beastie-menu function
printmenuitem ." Escape to loader prompt" escapekey !
==> printmenuitem ." Network" bootyg !
printmenuitem ." Reboot" rebootkey !


I add this lines of code into the beastie-start function (copy-paste)
dup bootyg @ = if
s" 4" s" sysctl_var" setenv
0 boot
then

I echo into my netif script: sysctl -a | grep sysctl_var

I try kern.dummy : nothing change so I grab a variable that can be set: kern.domainname without any success. In fact after reading again the manpage for loader I realize that the following sysctl variables are changeable via the loader:
- hw.physmem
- etc.

So via the bootloader is may be impossible without modifying the code of the loader and of the kernel.

Next step: to get the flags that the boot prompt provide as "boot -s" to boot in single mode. So if you have some information on how the kernel deal with arguments given by the bootloader just drop a line.

Thank in advance for your help.
Reply With Quote
Old 14th May 2008
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Default

Quote:
Originally Posted by l2fl2f View Post
Hello,

testing:

I add the following line into the beastie.4th:

# variables section
variable bootyg

I add the following line into the beastie-menu function
printmenuitem ." Escape to loader prompt" escapekey !
==> printmenuitem ." Network" bootyg !
printmenuitem ." Reboot" rebootkey !


I add this lines of code into the beastie-start function (copy-paste)
dup bootyg @ = if
s" 4" s" sysctl_var" setenv
0 boot
then

I echo into my netif script: sysctl -a | grep sysctl_var
did you try Richardpl's suggestion:

kenv | grep sysctl_var

or

case in $(kenv sysctl_var)
1) echo home network ;;
2) echo office network ;;
3) echo dhcp ;;
*) echo no network ;;
esac
Reply With Quote
Old 14th May 2008
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

You might want to post this question to the questions or hackers maillist, because that's where the freebsd developers hang out, they might be able to give you a more definitive answer...
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
Old 14th May 2008
l2fl2f's Avatar
l2fl2f l2fl2f is offline
Real Name: Yves Guerin
Port Guard
 
Join Date: May 2008
Location: Montreal, Quebec, Canada
Posts: 25
Default

Hello,

I try to use an unused variable inside the bootloader: boot_verbose, but if I put another value than "NO" the kernel consider the value as a "YES" and I got the debug ON at startup.

I am starting looking into the kenv and may be I will find my way with: kernel_options.

I tried to start from the bootloader prompt: boot -yg (try to pass a flag to the kernel) and run kenv but I were unable to find my -yg flag.

I will finaly go to the mailing list on freebsd.

Thanks for your help.
Reply With Quote
Old 14th May 2008
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Default

your beastie.4th modification sets the boot env variable 'sysctl_var' to the value 4. you can get the value of your boot variable from netif.sh using kenv - please see my earlier post.

all you now need to do now is add 3 more menu items to beastie.4th each of which sets a different value of sysctl_var. then modify your netif or add your own rc script to setup your network based on this value.
Reply With Quote
Old 14th May 2008
richardpl richardpl is offline
Spam Deminer
 
Join Date: May 2008
Location: Croatia
Posts: 284
Default

I was wrong. It IS possible to pass arg - environment variables - to kernel and than such variables are available via kenv(1) after kernel is booted.

For example:

in bootloader do this before booting kernel (same thing can be done in forth script)

set OFFICE_NETWORK=YES
set HOME_NETWORK=NO
boot

after kernel have booted, you can check variables in following way:

kenv -q OFFICE_NETWORK
and kenv will print:
YES


I hope you got the point.
Reply With Quote
Old 14th May 2008
l2fl2f's Avatar
l2fl2f l2fl2f is offline
Real Name: Yves Guerin
Port Guard
 
Join Date: May 2008
Location: Montreal, Quebec, Canada
Posts: 25
Thumbs up

Hello,

You are right, I tested, at the menu of the bootloader, press 6 to go to the bootloader prompt and write set OFFICE_NETWORK=YES <Enter>, then boot <Enter> and with the kenv -q variable_name you get the answer.

Great

Thank you for your help and for your brain

(I know that moving from lx to FBSD, it will be a small step for humanity but a very big one for me)
Reply With Quote
Old 15th May 2008
l2fl2f's Avatar
l2fl2f l2fl2f is offline
Real Name: Yves Guerin
Port Guard
 
Join Date: May 2008
Location: Montreal, Quebec, Canada
Posts: 25
Smile Eureka, Bingo !

Hello,

I finally find the way to set, pass and retrieve a variable from the bootloader to my rc.d script file

the solution or the concept:
  1. WARNING: have a freebsd livecd (in case of error or typo in the beatie.4th, the pc won't boot, I warm you, I live this experience yesterday night )
  2. declare your variable into the loader.conf: myvar="toto"
  3. in the beastie.4th
    • declare a variable to handle the selection of your menu
    • add a menu item with your variable (copy and paste)
    • add a code to handle the selection of your menuitem
    • modify your variable (loader.conf) with the setenv function (copy and paste)
  4. in your rc.d script file use the kenv -q myvar to retrieve the value

the code:
  1. loader.conf
    • myvar="toto"
  2. beastie.4th, add in the declaration part
    • variable mymenuselection
    • in the :beastie-menu add this line:
      • printmenuitem ." Passing arg to rc.d file" mymenuselection !
    • in the :beastie-start add this code:
      • dup mymenuselection @ = if
        s" COUCOU" s" myvar" setenv
        0 boot
        then
  3. in your rc.d file:
    • VALUE=`kenv -a myvar` or kenv -q myvar
  4. Save and reboot

Now, I am able to choose from the startup of my laptop which network configuration I will use and I am able to see my splashscreen until X start

Thanks to all of you, who help me to find this solution (especially to richardpl and to ephemera)
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
kernel version 0?? Stellar OpenBSD General 5 30th August 2009 11:07 PM
problem passing /dev/fd/n to programs TerryP Programming 2 15th April 2009 08:24 AM
kernel modules Mr-Biscuit FreeBSD General 0 2nd March 2009 06:18 AM
Passing args to port / make while installing apache robot FreeBSD Ports and Packages 2 27th August 2008 01:55 PM
passing make args/variables to builds of prerequisite ports jbhappy FreeBSD Ports and Packages 2 18th July 2008 02:35 PM


All times are GMT. The time now is 04:46 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick