WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Adding dynamic TC Autorun feature  (Read 4292 times)

Offline AlejandroPadrino

  • Full Member
  • ***
  • Posts: 143
Adding dynamic TC Autorun feature
« on: July 13, 2023, 11:02:01 PM »
Hello to all,

related to this post http://forum.tinycorelinux.net/index.php/topic,26314.0.html, I made a autorun script feature for TC.  You can use it in your own way.

The script is useful for finding and loading .TCZ extensions across many device and folder locations, and only takes like valid location the last device and folder found.  In this script, all the specified devices are mounted, and same devices are dismounted if specified file was not found.  If the specified file is found in any specified folder, the device remains mounted after TC finished the boot process.  Code may be located in /opt/bootlocal.sh file and, if you want to load a .TCZ extension after, you can take the sample script opera12.sh file to modify as you like.

Code to add in /opt/bootlocal.sh file:
Code: [Select]
# PsaCrypt AutoRun.Sh checking.
echo "${RED}Mounting TCE FileSystems ...${NORMAL}";
 tceAutoRun=;
 tceFolder=;
 tceFile=autorun.sh;

for zb00 in "hdd5" "hdd4" "hdd3" "hdd2" "hdd1" "hdc5" "hdc4" "hdc3" "hdc2" "hdc1" "hdb5" "hdb4" "hdb3" "hdb2" "hdb1" "hda5" "hda4" "hda3" "hda2" "hda1" "sdd5" "sdd4" "sdd3" "sdd2" "sdd1" "sdc5" "sdc4" "sdc3" "sdc2" "sdc1" "sdb5" "sdb4" "sdb3" "sdb2" "sdb1" "sda5" "sda4" "sda3" "sda2" "sda1";
do
 tmpDev=;
 tmpFolder=;
 sudo mount -w /dev/$zb00;

for zb01 in "cde" "tc" "tce" "TinyCoreLinux";
do
 if [ -f /mnt/$zb00/$zb01/$tceFile ]; then tmpFolder=/mnt/$zb00/$zb01; tmpDev=/mnt/$zb00/$zb01/$tceFile ; fi;
done;

 if [ -n "$tmpDev" ]; then tceFolder=$tmpFolder; tceAutoRun=$tmpDev ; echo $tmpDev ; fi;
 if [ ! -n "$tmpDev" ]; then sudo umount -f -r /dev/$zb00 ; fi;
done;

for zb00 in "sr3" "sr2" "sr1" "sr0";
do
 tmpDev=;
 tmpFolder=;
 sudo mount -r /dev/$zb00;

for zb01 in "cde" "tc" "tce" "TinyCoreLinux";
do
 if [ -f /mnt/$zb00/$zb01/$tceFile ]; then tmpFolder=/mnt/$zb00/$zb01; tmpDev=/mnt/$zb00/$zb01/$tceFile ; fi;
done;

 if [ -n "$tmpDev" ]; then tceFolder=$tmpFolder; tceAutoRun=$tmpDev ; echo $tmpDev ; fi;
 if [ ! -n "$tmpDev" ]; then sudo umount -f -r /dev/$zb00 ; fi;
done;

# Execute tceAutoRun file.
export tceAutoRun tceFolder;
if [ -f "$tceAutoRun" ]; then sudo nohup $tceAutoRun $tceFolder > /dev/null ; fi;
exit;

#end.

After this code, the file autorun.sh is launched if it was found.  Then I made a custom .TCZ package, loaded in autorun.sh file, to load the script launchers (like opera12.sh sample) into TC filesystem, to call these launchers from console or another script file.

Sample loader for .TCZ extensions (opera12.sh):
Code: [Select]
#!/bin/sh
# PsaCrypt loader for Opera 12 Web Browser.

echo "${RED}Finding for .TCZ Files ...${NORMAL}";
 tceFolder=;
 tceFile=opera-12.tcz;

for zb00 in "hdd5" "hdd4" "hdd3" "hdd2" "hdd1" "hdc5" "hdc4" "hdc3" "hdc2" "hdc1" "hdb5" "hdb4" "hdb3" "hdb2" "hdb1" "hda5" "hda4" "hda3" "hda2" "hda1" "sdd5" "sdd4" "sdd3" "sdd2" "sdd1" "sdc5" "sdc4" "sdc3" "sdc2" "sdc1" "sdb5" "sdb4" "sdb3" "sdb2" "sdb1" "sda5" "sda4" "sda3" "sda2" "sda1";
do
 tmpFolder=;

for zb01 in "cde" "tc" "tce" "TinyCoreLinux";
do
 if [ -f /mnt/$zb00/$zb01/tce-autoload/$tceFile ]; then tmpFolder=/mnt/$zb00/$zb01/tce-autoload ; fi;
done;

 if [ -n "$tmpFolder" ]; then tceFolder=$tmpFolder; echo Folder: $tmpFolder ; fi;
done;

for zb00 in "sr3" "sr2" "sr1" "sr0";
do
 tmpFolder=;

for zb01 in "cde" "tc" "tce" "TinyCoreLinux";
do
 if [ -f /mnt/$zb00/$zb01/tce-autoload/$tceFile ]; then tmpFolder=/mnt/$zb00/$zb01/tce-autoload ; fi;
done;

 if [ -n "$tmpFolder" ]; then tceFolder=$tmpFolder; echo Folder: $tmpFolder ; fi;
done;

# Execute loader file.
if [ -f "$tceFolder/$tceFile" ]; then su tc -c "chdir $tceFolder/ && tce-load -i $tceFolder/$tceFile && echo Done."; fi;
if [ ! -f "$tceFolder/$tceFile" ]; then echo Error: Opera .TCZ files not found.; fi;
exit;

#end.

Take note that you must use this scripts with warning because /opt/bootlocal.sh file is launched as root user.

Enjoy.   ;-)
« Last Edit: July 13, 2023, 11:21:12 PM by AlejandroPadrino »

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: Adding dynamic TC Autorun feature
« Reply #1 on: July 14, 2023, 03:36:02 AM »
Hi AlejandroPadrino,

Nice that You share Your improvements for TinyCore!
Sorry, I am too dumb and can't understand what are the advantages of Your approach against f.e. onboot.lst (my_special.lst, ... )? Where the dependences will be looked for? Of course You may answer that the script is on my screen and I can grok it by myself, but I will be grateful for help.

Thanks in advance.

Offline AlejandroPadrino

  • Full Member
  • ***
  • Posts: 143
Re: Adding dynamic TC Autorun feature
« Reply #2 on: July 14, 2023, 05:16:44 AM »
Since I know TinyCore Linux (TC4), I found some problems in onboot.lst feature when loading TC from DVD.  I remastered the core, but it haves a limitation near 341mb.  Growing my few knowledge in Linux scripting I found this way to build a better TC working for me.

The script works locating all devices and folders specified finding for a file.  If the file is found, the device who contains the file remains mounted after TC boot.  If you compare code in /opt/bootlocal.sh and opera12.sh, you can see the same code structure, but in opera12.sh launcher there is no mount/umount commands.

To load extension dependencies, it was automatically, same as onboot.lst file.  You simply must copy .TCZ extensions and dependencies into the right folder specified to tce-load command.  Do you understand now?

Best.  :-)

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: Adding dynamic TC Autorun feature
« Reply #3 on: July 14, 2023, 11:25:41 AM »
Thanks for explanations!

But I still have questions ( Isn't it too boring?
1) This is TC4 specific issue?
2) It is necessary for loading from DVD only (I use USB flash drives)?
3) The size limitation of 341 MB? Never knew about it. What is the cause of this limit?

Have a nice Core!

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11702
Re: Adding dynamic TC Autorun feature
« Reply #4 on: July 14, 2023, 02:20:04 PM »
Hi jazzbiker
... I remastered the core, but it haves a limitation near 341mb. ...
... 3) The size limitation of 341 MB? Never knew about it. What is the cause of this limit?
As far as I know, there is no limit on the size of the initrd (core.gz) per se.
However, the initrd contains the root filesystem (compressed) which gets
unpacked/uncompressed and resides in RAM:
http://distro.ibiblio.org/tinycorelinux/architecture.html
So depending on how much RAM you have, and how much you add to the
initrd, you may find yourself running short on RAM.

Searching for  maximum initrd size  will return some sites suggesting a limit
on the maximum address in RAM a bootloader will write to exists.

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: Adding dynamic TC Autorun feature
« Reply #5 on: July 14, 2023, 04:02:02 PM »
Thanks, Rich,
I've missed that AlejandroPadrino talks about "remastering", which really means initrd which will reside in the RAM. Probably it's for the booting fast as possible.
But then where will reside /home? Persistent?

So here we can see an example of the choice:
1. Fast extensions and slow /home
vs
2. Slow boot and slower extensions and fast /home.

I put stupid questions because I choose fast /home )

Probably the need for additional extension tools is caused by very small drives capacity.

Thanks for the answer and sorry for the stupid questions!
« Last Edit: July 14, 2023, 04:06:06 PM by jazzbiker »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11702
Re: Adding dynamic TC Autorun feature
« Reply #6 on: July 14, 2023, 04:17:39 PM »
Hi jazzbiker
... But then where will reside /home? Persistent? ...
The initrd contains an empty home directory. If you have a persistent
home, it will be mounted under the home directory, /home/tc for example.
If your home was backed up, it will be restored to /home/tc for example, but
will reside fully in RAM.

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: Adding dynamic TC Autorun feature
« Reply #7 on: July 14, 2023, 04:29:24 PM »
Hi Rich,
But maximizing the size of initrd to fill the whole RAM will leave almost no free room for /home.
Probably this is normal for some use cases.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11702
Re: Adding dynamic TC Autorun feature
« Reply #8 on: July 14, 2023, 04:38:45 PM »
Hi jazzbiker
If home is persistent, it only consumes a few hundred bytes
for a mountpoint, with everything else on persistent storage.

If your home was backed up, the kernel probably allocates
RAM to allow it to be restored.

If you manage to size the initrd to use all of the RAM, you
will likely have problems.  ::)

Offline AlejandroPadrino

  • Full Member
  • ***
  • Posts: 143
Re: Adding dynamic TC Autorun feature
« Reply #9 on: July 14, 2023, 04:41:11 PM »
Hello,

in my computers, the problem is loading all TC releases from DVD.  It can not start the X graphics server.  There is no problem loading from USB.  The limit of 341mb in custom core (.gz compressed) is for 2gb RAM.  Custom root filesystem uncompressed into RAM is about 942mb in size.

Hope this helps you, Jazzbiker.

Best.  :-)

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: Adding dynamic TC Autorun feature
« Reply #10 on: July 14, 2023, 04:49:59 PM »
Ok, then 341 MB is not some limit but Your conscious decision, right? To leave about 1 GB for /home.
One more stupid question, please:
why X doesn't start for You if it starts for every good guy? Good guys use TinyCore, I'm pretty sure.
And why not use USB if there is no problems with them?

I'm not trolling, just curious.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11702
Re: Adding dynamic TC Autorun feature
« Reply #11 on: July 14, 2023, 05:09:35 PM »
Hi AlejandroPadrino
in my computers, the problem is loading all TC releases from DVD.  It can not start the X graphics server. ...
I have a laptop that likes to stop at  failed in waitforX  when booting
certain versions, especially 64 bit. I solved it by adding:
Code: [Select]
sleep 3as the first line in ~/.xsession to delay the start of Xorg.

Offline AlejandroPadrino

  • Full Member
  • ***
  • Posts: 143
Re: Adding dynamic TC Autorun feature
« Reply #12 on: July 14, 2023, 06:48:02 PM »
Hello Rich,

to be in detail, not all releases.  TC 4.1 is the only that I tried and starts X graphics server, but TC 4.1 does not load custom .TCZ configuration booting from DVD.  After this I tried TC8, TC10 and TC13.  No one of these releases starts X graphics server in my computers.  This is the other reason to make my custom TC core with X graphics server included in root filesystem.  I use TC as recovery tool for my software compilers.  My main custom Linux is maded from Linux Lite (Ubuntu based), and haves a 4 gb compressed filesystem.  But Linux Lite does not start with QEmu in Android devices.  TC starts with QEmu emulation on Android.