LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-08-2006, 11:24 AM   #1
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
Set environment variable from GRUB


I have read several times that a method exist to set an environment variable from the GRUB boot prompt. Unfortunately I cannot find how to do it anymore, not even in Google.

The intention is to tell GRUB something during boot time, like:
Code:
myvar=foo
and then retrieve this variable somewhere, preferably in a bash script.

jlinkels
 
Old 08-08-2006, 12:07 PM   #2
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,467
Blog Entries: 1

Rep: Reputation: 66
If I understand right, you can pass any string to kernel and retrieve it in "/proc/cmdline" file.

For instance, if you change the line in "/boot/grub/menu.lst" from:
Code:
kernel /vmlinuz-2.6.17-1.2157_FC5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
to

Code:
kernel /vmlinuz-2.6.17-1.2157_FC5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet whatever-you-want
the string "whatever-you-want" will be in "/proc/cmdline" in the next boot.

This scheme is used to pass arbitrary strings to initialization scripts under /etc/init.d/, but you can use it for anything else you need. Just don't use a already taken string, like noacip, dma=, vga=, etc...

I hope this can help you....
 
Old 08-08-2006, 12:13 PM   #3
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Yes, and you can have an example in /usr/share/initramfs-tools/init:

This is run in the initrd but you can do it everywhere.

Code:
for x in $(cat /proc/cmdline); do
        case $x in
        init=*)
                init=${x#init=}
                ;;
        root=*)
                ROOT=${x#root=}
                case $ROOT in
                LABEL=*)
                        ROOT="/dev/disk/by-label/${ROOT#LABEL=}"
                        ;;
                UUID=*)
                        ROOT="/dev/disk/by-uuid/${ROOT#UUID=}"
                        ;;
                esac
                ;;
        rootflags=*)
                ROOTFLAGS="-o ${x#rootflags=}"
                ;;
        cryptopts=*)
                cryptopts="${x#cryptopts=}"
                ;;
        nfsroot=*)
                NFSROOT="${x#nfsroot=}"
                ;;
        nfsopts=*)
                NFSOPTS="-o ${x#nfsopts=}"
                ;;
        boot=*)
                BOOT=${x#boot=}
                ;;
        resume=*)
                RESUME="${x#resume=}"
                ;;
        noresume)
                NORESUME=y
                ;;
        quiet)
                quiet=y
                ;;
        ro)
                readonly=y

...
 
Old 08-08-2006, 02:11 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Original Poster
Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
Wow... so darned simple. That is exactly what I need. And nowhere to find with google.

Thanks, this helps!

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set environment variable pranith Linux - Newbie 1 01-27-2005 11:23 PM
How to set a value of environment variable? ukrainet Linux - Newbie 1 12-28-2004 04:33 AM
How to set an environment variable? dantemarmol Linux - Newbie 7 08-22-2003 10:59 AM
How to set a environment variable in rh? yenonn Linux - Newbie 11 02-21-2003 10:24 PM
how to set CC environment variable mr.moto General 2 12-18-2001 01:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration