Michael D. Setzer II
2009-Jan-01  11:33 UTC
[syslinux] OT: Question on running command from boot menu
I have a project that disk imaging from a cd using isolinux and a dialog gui 
system, but some users want to setup systems to run automatically. Some 
can download the development kit, and built an image with a modified script, 
but others don't have the skills or resources. I've come up with a
system that
seems to work with both the isolinux.cfg or menu.lst with grub4dos and I 
believe regular grub as well.  The system adds a run=" " option to
cmdline.
A simple option could just be run="fg4l ipaddress" which would
download a
script from ftp and run it. 
Below is a more complex option that runs multi-line command. Using \n didn't
work, so came up with a method to use CR as a marker, and replacing it.
Single line from menu.lst used by grub4dos, but same works with 
isolinux.cfg.
kernel /linux/bz27.10 root=/dev/ram0 rw ramdisk_size=65536 run="e2fsck 
/dev/hda2CRmount /dev/hda2 /mnt/localCRlzop -d -c /mnt/local/d8new.lzo | 
ntfsclone -r --overwrite /dev/hda1 - CRumount /mnt/localCRsleep 5CRreboot"
The cd will the load the kernel, and the above line is in the /proc/cmdline
file.
The user g4l automatically logs on, and this is at the beginning of the 
g4lmenu script to process the cmdline if anything in the run=" "
exists.
### 12/31/20008 added to allow running command from grub
### add run="command line" to the grub line
### creates /tmp/runcmd to stop running twice.
### added sed CR filtering to allow multi-line commands
### run="command1CRcommand2CRcommand3"
if [ ! -s "/tmp/runcmd" ] ; then
  cat /proc/cmdline | grep run | cut -d\"  -f 2 | sed -e
's/CR/\n/g' >/tmp/runcmd;
  if [ -s /tmp/runcmd ] ; then
    sh /tmp/runcmd
    sleep 10;
  fi
fi
The above system does seem to work in my limited test, and it would be 
rather simple to modify the isolinux.cfg or other using isomaster or similar 
windows program.
Wondering if I am missing anything in this, or warnings that might need to be 
included.
Thanks.
+----------------------------------------------------------+
  Michael D. Setzer II -  Computer Science Instructor      
  Guam Community College  Computer Center                  
  mailto:mikes at kuentos.guam.net                            
  mailto:msetzerii at gmail.com
  http://www.guam.net/home/mikes
  Guam - Where America's Day Begins                        
+----------------------------------------------------------+
http://setiathome.berkeley.edu (Original)
Number of Seti Units Returned:  19,471
Processing time:  32 years, 290 days, 12 hours, 58 minutes
(Total Hours: 287,489)
BOINC at HOME CREDITS
SETI 7,122,242.9956 | EINSTEIN 2,218,390.1109 | ROSETTA 
736,835.9944
H. Peter Anvin
2009-Jan-01  20:51 UTC
[syslinux] OT: Question on running command from boot menu
Michael D. Setzer II wrote:> > Below is a more complex option that runs multi-line command. Using \n didn't > work, so came up with a method to use CR as a marker, and replacing it. >In most cases you can just use ; or perhaps better &&. There usually isn't much reason to have multiline commands in Unix.> Single line from menu.lst used by grub4dos, but same works with > isolinux.cfg. > > kernel /linux/bz27.10 root=/dev/ram0 rw ramdisk_size=65536 run="e2fsck > /dev/hda2CRmount /dev/hda2 /mnt/localCRlzop -d -c /mnt/local/d8new.lzo | > ntfsclone -r --overwrite /dev/hda1 - CRumount /mnt/localCRsleep 5CRreboot" > > The cd will the load the kernel, and the above line is in the /proc/cmdline file. > The user g4l automatically logs on, and this is at the beginning of the > g4lmenu script to process the cmdline if anything in the run=" " exists. > > ### 12/31/20008 added to allow running command from grub > ### add run="command line" to the grub line > ### creates /tmp/runcmd to stop running twice. > ### added sed CR filtering to allow multi-line commands > ### run="command1CRcommand2CRcommand3" > if [ ! -s "/tmp/runcmd" ] ; then > cat /proc/cmdline | grep run | cut -d\" -f 2 | sed -e 's/CR/\n/g' >/tmp/runcmd; > if [ -s /tmp/runcmd ] ; then > sh /tmp/runcmd > sleep 10; > fi > fiPerhaps a cleaner version: sed -r -e 's/^(|.*[[:space:]])run="(.*)"([[:space:]].*|)$/\2/e' \ < /proc/cmdline> > The above system does seem to work in my limited test, and it would be > rather simple to modify the isolinux.cfg or other using isomaster or similar > windows program. > > Wondering if I am missing anything in this, or warnings that might need to be > included. >Overall, it should work, I believe. There are always issues (neither your versions or mine handle commands that need embedded double quotes, for example). -- H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.