WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Boot code to support script  (Read 3028 times)

Offline ndog

  • Newbie
  • *
  • Posts: 1
  • Never stop learning!
Boot code to support script
« on: June 27, 2013, 05:44:27 AM »
Hi

I am looking for a light weight terminal only linux distro.

All I need to do is boot into terminal, run a bash script, restore.sh or backup.sh, and I want my grub menu to have the two options.

I would like to support a boot code to launch terminal command. I have looked at tiny core linux which is very fast and looked at the boot codes page, unfortunately it doesn't support what I think I am trying to do. I hope it may be possible to do what I want on tiny core! Maybe someone clever here has done this??

If the answer is no, please recommend a distro that can support this.. I have experience in bash scripting, but not much distro knowledge ....

menu.lst

title microcore backup
find --set-root /core/vmlinuz
set PRE="sudo mount /dev/sdb1 /mnt"
set RUN="sudo bash /mnt/backup.sh"
kernel /boot/vmlinuz %PRE% %RUN%
append initrd=/boot/core.gz

title microcore restore
find --set-root /core/vmlinuz
set PRE="sudo mount /dev/sdb1 /mnt"
set RUN="sudo bash /mnt/restore.sh"
kernel /boot/vmlinuz %PRE% %RUN%
append initrd=/boot/core.gz

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: Boot code to support script
« Reply #1 on: June 27, 2013, 06:45:27 AM »
Besides from not understanding about those uncommon boot options, you would probably have to load the bash extension onboot in order to have bash available at an early stage.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline Lee

  • Hero Member
  • *****
  • Posts: 645
    • My Core wiki user page
Re: Boot code to support script
« Reply #2 on: June 27, 2013, 08:28:13 AM »
The kernel command line, including your "custom" boot codes, is available after boot in /proc/cmdline, so you can parse that to pick up the PRE and RUN values.

/opt/bootsync.sh runs as root as one of the last steps in the boot sequence, so that would be a likely place to do your scripting.

If your scripting requires bash then load bash.tcz "onboot".  If you are using vanilla scripting that can run under the busybox ash then you don't even need that.

If the value you show in PRE is a complete command, it looks like you will be mounting /dev/sdb1 on /mnt instead of on /mnt/sdb1.  Since Core, by default, mounts file systems in /mnt/<device>, mounting one on /mnt would likely make things interesting if anything else were previously mounted.  If your tce directory happens to reside on /dev/sdb1 then it ( /dev/sdb1 ) will be be automatically mounted on /mnt/sdb1 during boot.

Edit: Clarification of "it" in last sentence.  2013-06-27 11:28 edt
« Last Edit: June 27, 2013, 11:34:46 AM by Lee »
32 bit core4.7.7, Xprogs, Xorg-7.6, wbar, jwm  |  - Testing -
PPR, data persistence through filetool.sh          |  32 bit core 8.0 alpha 1
USB Flash drive, one partition, ext2, grub4dos  | Otherwise similar

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11514
Re: Boot code to support script
« Reply #3 on: June 27, 2013, 09:31:49 AM »
Hi ndog
Check out this thread for an example of one way to implement custom boot codes:
http://forum.tinycorelinux.net/index.php/topic,14172.msg79767.html#msg79767
Take a look in /etc/init.d/tc-init for more information about parsing the kernel command line. The /etc/init.d/tc-functions
script contains a  getbootparam  function which also may be of some use.