Tiny Core Linux
Tiny Core Base => TCB Q&A Forum => Topic started by: erics on January 26, 2011, 07:08:28 AM
-
Hello .
Having written and compiled a C "hello World"-type program under Ubuntu I wonder howto run this and put the message on the screen in TC without user-intervention when TC boots ?
I suppose by reading the TC-docs the C-binaru must be converted to .ce format , is it ?
Everything in this TC-world is miles away from the usual Linux-paths .
First encounter with TC is quite a shock , nothing seems to work as usual pe: " ls -al /dev/disk/by-label " & 'mount' !
"man mount " : does not help either ,but this was to be expected given the small size of the system .
Very intriging , want to explore more .
Thanks in advance for every hint with that C-executable .
-
Binaries compiled with gcc against e.g. glibc (the gnu standard c libary), which is shared by ubuntu and tinycore can run directly on each system (as long as there aren't any compatibility issues like different architecture, gcc profiles, etc.). There's no need for converting anything.
To what you are referring is the package format for extensions. Whereas ubuntu uses .deb and fedora uses .rpm, tinycore uses .tcz. Although there are differences in the type and technique of files (.tcz is squashfs, .rpm is compressed cpio archive, etc.), it's basically the same on distros to use it. When you want to use a .tcz on tinycore you "install" it with tce-load -i /path/to/file.tcz or with a -w switch to download it from the web.
What you can do is, make an own extension for your hello world program, you will need compiletc and squashfs-tools-4.x extensions (download with appbrowser or tce-load -wi):
$ mkdir -p myext/usr/local/bin
$ gcc -o myext/usr/local/bin/helloworld helloworld.c
$ sudo chown -R root:staff myext
$ sudo mksquashfs myext myext.tcz
$ md5sum myext.tcz > myext.tcz.md5.txt
Then copy myext.tcz and myext.tcz.md5.txt to your tce folder (that is a folder called tce on any mountable partition, e.g. /mnt/sda1/tce) into the folder optional and edit a file called onboot.lst with myext.tcz in a line. Example:
/mnt/sda1/tce/onboot.lst
/mnt/sda1/tce/optional/myext.tcz
$ cat /mnt/sda1/tce/onboot.lst
myext.tcz
If you added or recreated new partitions (USB key or whatever) then run on a terminal
$ sudo rebuildfstab
$ sudo mount /dev/sda1
Tinycore will use the tce folder on any drive automatically as long as the device is already connected when booting. If you use an USB drive for that, add to your bootcodes waitusb=6, so that there's time for tinycore to recognize the device and mount it.
-
Thanks for the reply , things are somewhat clearer now .
Actually my program is a bit more complicated than the classical "hello world" by using C++ classes and functions .
I suppose the best way will be using 'static' linking in the whole affair ?
Thanks again for the advice , now I have an idea how to start
Erics
-
You're welcome! Static linking depends on what you want to achieve - if you want to have a binary, which you can throw somewhere and use it and there's enough space then do it statically and maybe compress it with UPX. If you're going to run other programs as well and you want to make it as small as possible then think about dynamic linking. TC basically provides all libraries you have on other linux'es, you just have to install them and their dev headers. There's no reason why dynamic linking should fail when it works on Ubuntu e.g.
-
"man mount " : does not help either ,but this was to be expected given the small size of the system .
what about
mount --help
optionally
tce-load -iw man-pages.tcz man.tcz
Also many extensions have their own equivalent -doc.tcz package.
These days many users would have redundant bandwith, so it might not make sense to sacrifice RAM or storage space for what can be accessed online at any moment.
-
If the compiled program is in your backup/restore files (someplace under /home/tc in a default setup), you don't need to create a .tgz. But you can if you want. ;)
Let's say you build your hello.c in the home directory (/home/tc) and now have a hello binary file there. Can you run it from the command line?
$ ./hello
If not, make sure the execution permission bits are set (using fluff or "chmod 755 hello").
Now if you want this to run automatically each time you boot TC, add a call to it in your /opt/bootlocal.sh file:
$ editor /opt/bootlocal.sh
(edit the file to include the line:
/home/tc/hello
)
or
$ echo "/home/tc/hello" >> /opt/bootlocal.sh
Alternatively, if you want to have your program run each time a user opens a terminal, add the call to the .ashrc file instead of /opt/bootlocal.sh.
--
Mike Lockmoore