General TC > Programming & Scripting - Unofficial

Patch for a pre-boot script

(1/3) > >>

aw:
Hi,

I occasionally want to run some commands (or a script) before the system boots. I've made a small patch to tc-config which will execute the file /opt/preboot.sh before "Booting Core".

Here's the patch file:

https://gist.github.com/aw/346c56912abd744803d054a9df04662f


--- Code: ---diff --git a/etc/init.d/tc-config b/etc/init.d/tc-config
index f6002dd..c44876c 100755
--- a/etc/init.d/tc-config
+++ b/etc/init.d/tc-config
@@ -25,6 +25,8 @@ addUser(){
 
 # Main
 
+[ -f "/opt/preboot.sh" ] && /opt/preboot.sh
+
 clear                               
 echo "${GREEN}Booting ${YELLOW}Core $VERSION ${NORMAL}"
 echo "${GREEN}Running Linux Kernel ${YELLOW}$KERNEL${GREEN}.${NORMAL}"

--- End code ---

Here's an example use-case:

On PiCore, if the system doesn't have an RTC, the year always resets/begins at 1970. To fix that, I've introduced a boot option called builddate which sets the system date very early in the boot process, based on a UNIX timestamp


--- Code: ---# example /opt/preboot.sh
#
# builddate from /proc/cmdline = 1463499605

. /etc/init.d/tc-functions

builddate=$(getbootparam "builddate")
if [ ${builddate-} ]; then
  [ "$builddate" -lt `/bin/date +%s` ] || /bin/date +%s -s @${builddate}
fi

--- End code ---

Would it be possible to patch the official tc-config to allow us to add our own preboot scripts? I'm sure others have encountered situations requiring certain actions before TinyCore starts booting.

Thanks!

andyj:
Actually, that's what /etc/init.d/rcS is for. Anything you want to run before tc-config will need to be in the root file system. Update this file with your commands and rebuild it.

jls:
Hi
How you american say: my 2 cents:
The advantage of aw proposal is that if one has persistent opt there is no need to rebuild the initrd.

curaga:
Persistent opt is not mounted that early, so he'd have to remaster still.

andyj:
If you want /opt mounted before then, then you need to do it in rcS. Back to that file. Technically you don't have to rebuild the stock initrd, you could make your own with just the changed files and load it after the stock initrd in extlinux.config.

Navigation

[0] Message Index

[#] Next page

Go to full version