Tiny Core Base > TCB Q&A Forum
How to make custom boot codes?
mikshaw:
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: ---# 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
--- End code ---
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.
curaga:
--- Quote ---bash-3.2$ cat /proc/cmdline
root=/dev/sda1 vga=791 splash=silent
--- End quote ---
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
--- End quote ---
^thehatsrule^:
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.
bigpcman:
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.
florian:
/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
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version