Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: aw on May 17, 2016, 11:47:58 AM
-
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
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}"
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
# 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
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!
-
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.
-
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.
-
Persistent opt is not mounted that early, so he'd have to remaster still.
-
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.
-
Or use the pretce boot code as used here:
http://wiki.tinycorelinux.net/wiki:pretce
-
Thanks for all the responses!
I didn't consider the fact that /opt is not mounted/restored at that time.
The pretce boot option has the correct functionality, except I think it happens too late in the boot process.
It appears in all cases I would need to remaster the initrd (particularly for PiCore which doesn't use extlinux / limited to one initrd).
In this case, modifying /etc/init.d/rcS would be the cleanest solution. Thanks @andyj
-
On piCore as far as I know there you can only have one initrd. I use rcS to mount overlays to cut boot time. But that requires a custom kernel, but again I have to have that to have the gpio display available at boot, so it all comes together. Good luck.
-
Try creating an initrd with only your modified rcS.
Then "cat core.gz custom.gz" > newcore.gz.
Then use newcore.gz in your bootloader.
-
Cat'ting two gz files works in theory, but only the first cpio archive is unpacked. Files in the second one didn't get extracted in my test.
-
Maybe a Pi peculiarity? It works on x86.
-
I was trying it on x86_64. I did a zcat of the new file then piped through cpio. Maybe the boot loader handles the file differently?
-
You need to cpio the full directory structure of your files. Then compress the cpio file.
See the remastering wiki articles describing the construction of an initrd.
-
That's not what you said earlier:
Try creating an initrd with only your modified rcS.
Then "cat core.gz custom.gz" > newcore.gz.
Then use newcore.gz in your bootloader.
For x86 and x86_64 I've loaded them separately so I could use the stock initrd's unmodified:
DEFAULT pxe
LABEL pxe
KERNEL pxelinux.cfg/default-boot/vmlinuz64-7-1rc1
INITRD pxelinux.cfg/default-boot/rootfs64-7-1rc2.gz,pxelinux.cfg/default-boot/modules64-7-1rc1.gz,pxelinux.cfg/default-boot/my-syslog-data.gz
APPEND host=syslog-vm printk.time=1 syslog quiet noswap nozswap tce=/ httplist=192.168.50.5:/syslog.lst
On the Pi multiple initrd's don't work so I've always rebuilt my own. I'm familiar with the process.
-
I was trying it on x86_64. I did a zcat of the new file then piped through cpio. Maybe the boot loader handles the file differently?
Yes, the kernel's decompressor differs here. Userspace cpio can't unpack catted archives.