[syslinux] OT: Question on running command from boot menu

H. Peter Anvin hpa at zytor.com
Thu Jan 1 12:51:27 PST 2009


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
> fi


Perhaps 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.




More information about the Syslinux mailing list