WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How to make custom boot codes?  (Read 7568 times)

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
How to make custom boot codes?
« on: January 17, 2009, 06:06:43 AM »
Can someone explain how to make custom boot codes.
big pc man

Offline florian

  • Full Member
  • ***
  • Posts: 116
    • Home Page
Re: How to make custom boot codes?
« Reply #1 on: January 17, 2009, 08:55:31 AM »
/proc/cmdline contains all the bootcodes, thus your can parse/grep this file for your own custom ones.

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: How to make custom boot codes?
« Reply #2 on: January 17, 2009, 06:59:36 PM »
Thanks for the tip. When I look in /proc/cmdline it is a 0 byte file. So I must being missing something here.
big pc man

Offline ^thehatsrule^

  • Administrator
  • Hero Member
  • *****
  • Posts: 1726
Re: How to make custom boot codes?
« Reply #3 on: January 17, 2009, 08:18:33 PM »
That's because it's in /proc

Just try and read it :)

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: How to make custom boot codes?
« Reply #4 on: January 18, 2009, 05:21:14 AM »
I guess I'm a little dense. I don't know what "read" /proc means. Could you explain what you mean to this old man. I don't see the big picture yet as to how boot codes work. I thought they would end up being simply a list of links to scripts that I could add to. Using vi, cmdline is empty  Here's what I did:
« Last Edit: January 18, 2009, 05:25:09 AM by bigpcman »
big pc man

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: How to make custom boot codes?
« Reply #5 on: January 18, 2009, 05:57:21 AM »
To be honest, I don't know what thehats means either.  It seems to me that /proc/cmdline should contain a  single string listing everything that was sent to the kernel from grub.

As for using boot options, see /etc/init.d/tc-config, somewhere around line 108, for an example...a very simple and effective example
Code: [Select]
# Here we check all the boot parameters using the fastest way known to men, case & loop
for i in `cat /proc/cmdline`; do
  case $i in
    *=*)
          case $i in
           waitusb*) WAITUSB=${i#*=} ;;
           lang*) LANGUAGE=${i#*=} ;;
           kmap*) KEYMAP=${i#*=} ;;
           tz*) TZ=${i#*=} ;;
           desktop*) DESKTOP=${i#*=} ;;
           user*) USER=${i#*=} ;;
           home*) MYHOME=${i#*=} ;;
           cryptohome*) CRYPTOHOME=${i#*=} ;;
           opt*) MYOPT=${i#*=} ;;
           local*) LOCAL=${i#*=} ;;
           dosswapfile*) DOSSWAP=1; SWAPFILE=${i#*=} ;;
           tce*) TCE=${i#*=} ;;
           resume*) RESUME=${i#*=} ;;
           host*) HOST=1 ;;
           settime*) SETTIME=${i#*=} ;;
          esac
      ;;
      *)
          case $i in
           nofstab) NOFSTAB=1 ;;
           syslog) SYSLOG=1 ;;
           noutc) NOUTC=1 ;;
           nodhcp) NODHCP=1 ;;
           checkfs) CHECKFS=1 ;;
           noicons) NOICONS=1 ;;
           nolocal) NOLOCAL=1 ;;
           noswap) NOSWAP=1 ;;
           secure) SECURE=1 ;;
           protect) PROTECT=1 ;;
           ssh) SSH=1 ;;
           cron) CRON=1 ;;
           laptop) LAPTOP=1 ;;
           base) ONLYBASE=1 ;;
           eject) EJECT=1 ;;
           pause) PAUSE=1 ;;
          esac
      ;;
  esac
done
Notice there is a case nested in a case.  This is to separate "param=value" from simply "param".  If you use only one of those types of parameters, you will not need the nested case.  In this example, each action within the case startement merely sets a variable, to be used later on in the script.  You could instead add whatever consequential actions you want within case itself...all depends on what feels best for you.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10070
Re: How to make custom boot codes?
« Reply #6 on: January 18, 2009, 07:26:44 AM »
Quote
bash-3.2$ cat /proc/cmdline
root=/dev/sda1 vga=791 splash=silent

To test for your own bootcode, and run a script, you could add this to bootlocal.sh:
Quote
if grep "mybootcode" /proc/cmdline > /dev/null; then
myscript.sh
fi
The only barriers that can stop you are the ones you create yourself.

Offline ^thehatsrule^

  • Administrator
  • Hero Member
  • *****
  • Posts: 1726
Re: How to make custom boot codes?
« Reply #7 on: January 18, 2009, 10:38:41 AM »
I was referring "it" to /proc/cmdline... which seems to have been shown.  For an explanation of /proc, you could look it up for more information but it's basically for linux system/process info.

You can also use tc-functions' getbootparam and checkbootparam.
« Last Edit: January 18, 2009, 10:41:31 AM by ^thehatsrule^ »

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: How to make custom boot codes?
« Reply #8 on: January 18, 2009, 05:53:39 PM »
Thanks to all for the more detailed explanations. I like the idea of a simple grep of the cmdline in a bootlocal script. I'm still unclear as to the /proc/cmdline operation. What I gather from your explanation is that cmdline contains the boot command option codes as entered by the user but this information is not stored in the file named cmdline since it is a 0 byte file. So is cmdline a system command of some kind then? Sorry I'm not up on all this.

-----------------------------------
edit: I've been reading up on /proc a little so I'm beginning to get the big picture. It looks like cmdline is a command but if it is it doesn't have execute permission.
« Last Edit: January 18, 2009, 06:07:48 PM by bigpcman »
big pc man

Offline florian

  • Full Member
  • ***
  • Posts: 116
    • Home Page
Re: How to make custom boot codes?
« Reply #9 on: January 18, 2009, 11:11:14 PM »
/proc is a special beast because it's a "virtual" filesystem. It contains pseudo files that pertain to the runtime state of the Linux kernel. Most files in /proc are thus listed as zero bytes but usually contain a large amount of information (which you can nicely access from shell scripts  ;) )

find out more from here:
http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: How to make custom boot codes?
« Reply #10 on: January 19, 2009, 05:40:47 AM »
Thanks, the link points to the information I was looking for. I've never had to delve into this area before. 
big pc man