Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
passing arguments to init inside initramfs
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
flower1024
n00b
n00b


Joined: 04 Sep 2006
Posts: 7

PostPosted: Mon Sep 04, 2006 3:56 pm    Post subject: passing arguments to init inside initramfs Reply with quote

hi,

i created my own initramfs and want to pass arguments to the init process inside it.

e.g.

/init -> normal start
/init backup --> come up with dialog system for backup

background: i use the initramfs to boot from an crypted usb device on multiple machines. and now i want to implement an dialog-driven backup system just inside initramfs (so i can dd-copy everything and its still crypted) before the system starts.

my initramfs is inside the kernel and i dont want an second kernel kust for the backup....

kind regards
flower
Back to top
View user's profile Send private message
Dominique_71
Veteran
Veteran


Joined: 17 Aug 2005
Posts: 1709
Location: Switzerland (Romandie)

PostPosted: Mon Sep 04, 2006 6:07 pm    Post subject: Reply with quote

You have to add the name of your environment variable in /etc/conf.d/env_whitelist, otherwise init will not accept the variable.
After, you can pass it in grub by editing the command line at boot time, or by doing 2 configurations in menu.lst, one without the param, the other with something as
Code:
<name_of_your_env_variable>=backup
in the kernel command line.

BTW, do you know how I can pass the outpuf of a command to a variable in an init script. I am doing an init script to switch at boot time between the opengl infrastructure and the nvidia infrastructure. It begin to work well, but the part with eselect take a lot of time, and it will be better if I can pass the output of "eselect opengl show" to a variable, and do a conditional test in order to switch or not the opengl.
Back to top
View user's profile Send private message
flower1024
n00b
n00b


Joined: 04 Sep 2006
Posts: 7

PostPosted: Mon Sep 04, 2006 7:08 pm    Post subject: Reply with quote

thanks for your reply
i'll test it tomorrow

one thing i don't understand: which process will not accept the env var? cause my init is just a script inside the initramfs... (shell = /bin/sh)

btw: you can always get the complete command line by cat /proc/cmdline - the problem is even if i mount proc its not there in initramfs - only when the system has startet.

here is your answer:
the output from anything you write between backticks will be inserted right there:
Code:

VAR=`ls -l`
echo $VAR


note: they are backticks. on german keyb-layout it is shift+left from backspace. there are three kinds of this ticks so make sure you get the right one!


Last edited by flower1024 on Mon Sep 04, 2006 8:08 pm; edited 1 time in total
Back to top
View user's profile Send private message
Dominique_71
Veteran
Veteran


Joined: 17 Aug 2005
Posts: 1709
Location: Switzerland (Romandie)

PostPosted: Mon Sep 04, 2006 7:52 pm    Post subject: Reply with quote

flower1024 wrote:
thanks for your reply
i'll test it tomorrow

one thing i don't understand: which process will not accept the env var? cause my init is just a script inside the initramfs... (shell = /bin/sh)

It is init that don't will accept it. Init don't accept environment variable by default. You have to authorise each variable you want to use in this file. It doesn't matter if init is in ram or not, it will work the same.

Quote:
btw: you can always get the complete command line by cat /proc/cmdline - the problem is even if i mount proc its not there in initramfs - only when the system has startet.

here is your answer:
the output from anything you write between backticks will be inserted right there:
VAR=`ls -l`
echo $VAR

note: they are backticks. on german keyb-layout it is shift+left from backspace. there are three kinds of this ticks so make sure you get the right one!

Thank you. I found a better solution with a $(command) construct. I can use the $(construct) inside the test. Just look here.
Back to top
View user's profile Send private message
flower1024
n00b
n00b


Joined: 04 Sep 2006
Posts: 7

PostPosted: Mon Sep 04, 2006 7:57 pm    Post subject: Reply with quote

but init is a script which i wrote!
it doesn't know anything about gentoo....or any /etc/env
the only thing why it could work is that my shell /bin/sh will look at this env-file and enable them; i'll test that tomorrow

/bin/sh (running my script) is pid1 not init. it will start the "normal" gentoo init when it has mounted my root fs.

the normal init process /bin/init has nothing to do with it, cause it does not exists at this time (root is not mounted yet). it is execute before /bin/init starts!

/usr/src/linux/Documentation/filesystems/ramfs-rootfs-initramfs.txt describes the initramfs (which is nearly the same as an initrd)

reply to your question:
the ${command} construct won't work. the only reason for it is that you can write sth. like

Code:

TIMER=1
echo "${TIMER}er"
echo "$TIMERer"


if you remove the brackets in this example then the var will not be found (shell is looking for TIMEer which is not existing).
Back to top
View user's profile Send private message
Dominique_71
Veteran
Veteran


Joined: 17 Aug 2005
Posts: 1709
Location: Switzerland (Romandie)

PostPosted: Mon Sep 04, 2006 8:24 pm    Post subject: Reply with quote

It was a confusion. In any linux, init is the first process the kernel will start. So maybe at next time, it will be better to choose another name.

It is $(command), not ${command}. You can take a look here to see how it work.

I think at it is possible to do MY_VAR=`$(command)` but I use directly $(command) in a test and it work.
Back to top
View user's profile Send private message
flower1024
n00b
n00b


Joined: 04 Sep 2006
Posts: 7

PostPosted: Mon Sep 04, 2006 8:27 pm    Post subject: Reply with quote

oh i missread the brackets.

in initramfs it is not possible to use another name, cause the kernel will start /bin/init in initramfs and this init decides which init really has to start. init= which worked with initrd does not work with the new initramfs format
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware 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