WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: TC inside chroot  (Read 6992 times)

Offline scfan

  • Newbie
  • *
  • Posts: 10
TC inside chroot
« on: October 12, 2010, 07:58:23 AM »
Hi everyone,

I've been playing with TC on a chroot, however, I'm having some problems.

I've followed the instructions from the Remastering Wiki page, however, when trying to install something, I'm not able to.

I've mounted proc with mount -t proc none working_folder/proc and I've edited resolv.conf to use DNS. I'm able to ping by IP and name, and even wget files, however, when using tce-load or ab, I can't install anything.

$ tce-load -wi xchat

Nothing happens. It just stays there. No output, no errors, nothing.

If I use Xnest and try and do it via appbrowser, the same thing happens. appbrowser just sits there, and nothing happens.

I'm able to connect to the repositories and get a listing, but no install anything.

Any tips?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11077
Re: TC inside chroot
« Reply #1 on: October 12, 2010, 09:01:07 AM »
TC was not designed to run extracted (scattered), and chroot is an additional complication on top.

Some initialization might be missing (things done on boot normally), like the location of the tce dir.


To trace a script's execution, add " -x" to the first line, ie "#!/bin/sh -x"
The only barriers that can stop you are the ones you create yourself.

Offline scfan

  • Newbie
  • *
  • Posts: 10
Re: TC inside chroot
« Reply #2 on: October 12, 2010, 09:21:24 AM »
TC was not designed to run extracted (scattered), and chroot is an additional complication on top.

Some initialization might be missing (things done on boot normally), like the location of the tce dir.


To trace a script's execution, add " -x" to the first line, ie "#!/bin/sh -x"

I see. That's probably it, however, what other way do you recommend to "Remaster" it?

Any recommendations on what scripts to look at?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11077
Re: TC inside chroot
« Reply #3 on: October 12, 2010, 09:54:17 AM »
If you intend to include extensions in the image, it depends on the extension whether just unpacking is enough or if something else is needed. Doing a tce-load in the chroot, even successfully, would just download and loop-mount the extension.

If you're new in this, check out the ezremaster program first. There's a wiki walkthrough on it at http://tinycorelinux.com/wiki/Remastering+with+ezremaster
The only barriers that can stop you are the ones you create yourself.

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: TC inside chroot
« Reply #4 on: October 12, 2010, 10:41:28 AM »
Quote
I've been playing with TC on a chroot, however, I'm having some problems.

I am drifting slightly off-topic, but I'd like to add some useful information. I build my extensions in a chroot. I had some problems as well, but I was able to resolve them for my use case. I use the following command within the chroot environment to mount the first four filesystems in /etc/fstab:

for m in /proc /sys /dev/pts /dev/shm; do mkdir -p $m; mount $m; done

Compiling in a chroot is nice because I just extract tinycore.gz, extract the compiler and other required extensions, extract the source, compile, then remove the tinycore.gz and extension files. Everything left over is part of the extension.
« Last Edit: October 12, 2010, 10:48:59 AM by danielibarnes »

Offline scfan

  • Newbie
  • *
  • Posts: 10
Re: TC inside chroot
« Reply #5 on: October 12, 2010, 05:05:28 PM »
Quote
I've been playing with TC on a chroot, however, I'm having some problems.

I am drifting slightly off-topic, but I'd like to add some useful information. I build my extensions in a chroot. I had some problems as well, but I was able to resolve them for my use case. I use the following command within the chroot environment to mount the first four filesystems in /etc/fstab:

for m in /proc /sys /dev/pts /dev/shm; do mkdir -p $m; mount $m; done

Compiling in a chroot is nice because I just extract tinycore.gz, extract the compiler and other required extensions, extract the source, compile, then remove the tinycore.gz and extension files. Everything left over is part of the extension.

Hi there,

Thanks for the tip. I'm sure it's way better than what I was doing.

I like the idea of having tinycore inside chroot, makes it easier to script and make changes, however, even with your tip, I still can't install anything.

If was never able to do this, I would have quit by now, the problem is that it has worked before. I'm 100% positive. This is what makes me trying to make it work.

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: TC inside chroot
« Reply #6 on: October 12, 2010, 05:32:46 PM »
All of my extensions build successfully within a 2.x chroot. I've not tested with 3.x yet. Here is what I do:
1) Extract tinycore.gz
2) Extract extensions
3) Run this:
echo tc > /etc/sysconfig/tcuser
/sbin/ldconfig
for m in /proc /sys /dev/pts /dev/shm; do mkdir -p \$m; mount \$m; done
find /usr/local/tce.installed -not -empty -exec sh {} \; &/dev/null
export CFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export CXXFLAGS="-march=i486 -mtune=i686 -Os -pipe"
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
# Run build script

Note that you won't see anything udev does in a chroot so might have to populate /dev yourself for anything which isn't included in tinycore.gz.

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Re: TC inside chroot
« Reply #7 on: October 12, 2010, 07:21:05 PM »
A while ago I did some analysis where I repeatedly set up chroot "jails" in which the "action" took place. By and large I did the same as danielibarnes has suggested. My final script contained everything what I deemed required, and it took a fair amount of trial-and-error to get it right. There are a few (minor ?) differences between my "hack" to what has already been suggested, but I'm not sure that those are substantial enough to justify the full publication of my script. In the end it was created for quite a different purpose.

The one thing that strikes me is that you might not be on the same page WRT how to prepare the chroot "jail" with the required extensions. Bear in mind that the boot process of TC involves more than just extraction of the initrd. I found I had to "emulate" to some degree the role that '/etc/init.d/tc-config' (and "friends") are playing. In my case that meant running (in the root of the "jail"):
Code: [Select]
for DIR in usr/local/tce.icons usr/local/tce.installed usr/local/tce.menu \
        tmp/tce tmp/tcloop ; do
    [ -d "$DIR" ] || sudo mkdir "$DIR"
    sudo chgrp staff "$DIR"
    sudo chmod g+w "$DIR"
done
echo '/tmp/tce' > opt/.tce_dir
I believe that after copying the respective 'tcz' files (plus their 'dep' files) into the 'tmp/tce' directory of the "jail" I was able to use 'tce-load -i ...' when "inside". Maybe something along this line is missing in your approach.

A further point of note is what is required to allow for X clients to run from the "inside". That needed more tweaking, and as I'm not sure that you'll need such I'd rather hold back with discussing it here.

Offline scfan

  • Newbie
  • *
  • Posts: 10
Re: TC inside chroot
« Reply #8 on: October 13, 2010, 01:46:32 AM »
Thank you both very much for the suggestions. I'll give them a try in a few hours and report back here.

Regarding the graphical applications, I was able to use Xnest on my host and then just exported the DISPLAY variable and was able to start the windows manager and all applications. The problem is that I can't "remaster" anything without being able to install additions.

Once again, thanks for the tips.

Offline scfan

  • Newbie
  • *
  • Posts: 10
Re: TC inside chroot
« Reply #9 on: October 13, 2010, 01:58:13 AM »
Code: [Select]
for DIR in usr/local/tce.icons usr/local/tce.installed usr/local/tce.menu \
        tmp/tce tmp/tcloop ; do
    [ -d "$DIR" ] || sudo mkdir "$DIR"
    sudo chgrp staff "$DIR"
    sudo chmod g+w "$DIR"
done
echo '/tmp/tce' > opt/.tce_dir

Awesome. This made it work very NICELY! Along with the information about mount provided by danielibarnes I now have it fully working.

Thanks for the great tips guys!!

Offline scfan

  • Newbie
  • *
  • Posts: 10
Re: TC inside chroot
« Reply #10 on: October 13, 2010, 02:00:52 AM »
BTW guys,

I'm updating my scripts (I have one to create a new chroot and another one to build the ISO). What did you guys do on yours to have commands being done inside the chroot?

I mean, so far I've only done commands originating on my host system. How can I, on the script, make it run the script that maro posted.

Another question is related to a problem raised by curaga. I'm installing the applications on chroot, and they are still installed when I create the ISO, however, they all fail to start. In this case, with Firefox, is complaining with:

Code: [Select]
/usr/local/firefox-official/firefox-bin: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory
« Last Edit: October 13, 2010, 02:05:57 AM by scfan »

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Re: TC inside chroot
« Reply #11 on: October 13, 2010, 03:01:36 AM »
Are you asking of how to execute a script that resides "inside" from the "outside"? In my case I created just a single script for chroot setup and test execution. It contained (using a here-document) the "worker" script which was to be run "inside".

Assuming '/tmp/jail' represents the root of the chroot, I was using something like
Code: [Select]
cat > /tmp/jail/tmp/worker.sh <<EOF
#!/bin/sh
....
EOF
to create the worker script and then finally called it with
Code: [Select]
chmod +x /tmp/jail/tmp/worker.sh
sudo chroot /tmp/jail su -c "/tmp/worker.sh PARAMETERS" $USER

If you go down this path be aware that in a here-document you need to use backspace as escape character for characters like '$' and unquoted '\'. The alternative is obviously to copy a script from the "outside" to the "inside", which might be easier depending on the complexity of this "worker" script.

Edit: I forgot to add that the code snippet from reply #7 was run by the setup script after the initrd extraction. That means it was executed from the "outside" (after a 'cd /tmp/jail'). I could imagine that it it's possible to integrate it into the "worker" script (to be run fairly early on), but that was not how I did it. In principle all the setup and preparation was done from the "outside" and afer the execution of the "worker" script just a small amount of results were copied back to the "outside", followed by a comprehensive cleanup.
« Last Edit: October 13, 2010, 03:14:42 AM by maro »

Offline scfan

  • Newbie
  • *
  • Posts: 10
Re: TC inside chroot
« Reply #12 on: October 13, 2010, 05:11:07 AM »
Are you asking of how to execute a script that resides "inside" from the "outside"? In my case I created just a single script for chroot setup and test execution. It contained (using a here-document) the "worker" script which was to be run "inside".

Assuming '/tmp/jail' represents the root of the chroot, I was using something like
Code: [Select]
cat > /tmp/jail/tmp/worker.sh <<EOF
#!/bin/sh
....
EOF
to create the worker script and then finally called it with
Code: [Select]
chmod +x /tmp/jail/tmp/worker.sh
sudo chroot /tmp/jail su -c "/tmp/worker.sh PARAMETERS" $USER

If you go down this path be aware that in a here-document you need to use backspace as escape character for characters like '$' and unquoted '\'. The alternative is obviously to copy a script from the "outside" to the "inside", which might be easier depending on the complexity of this "worker" script.

Edit: I forgot to add that the code snippet from reply #7 was run by the setup script after the initrd extraction. That means it was executed from the "outside" (after a 'cd /tmp/jail'). I could imagine that it it's possible to integrate it into the "worker" script (to be run fairly early on), but that was not how I did it. In principle all the setup and preparation was done from the "outside" and afer the execution of the "worker" script just a small amount of results were copied back to the "outside", followed by a comprehensive cleanup.

Hi there,

Thank you so very much for all the helping you've been giving.

I'm getting really close to what I want to accomplish, thanks to all the help from this forum

The only "problem" I have now, is that after adding a couple more extensions (mostly to be able to build software from source), I'm now getting a "Kernel panic - not syncing: No init found".

The weird thing is that the script I made to create the .ISO was working before, and only after adding more software (compiled from source) and extensions, this error started appearing.

Any tips on why this is happening?

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: TC inside chroot
« Reply #13 on: October 13, 2010, 10:59:50 AM »
What is the size of your root filesystem? is it close to the amount of memory on the machine?

Offline scfan

  • Newbie
  • *
  • Posts: 10
Re: TC inside chroot
« Reply #14 on: October 13, 2010, 11:53:18 AM »
Hi,

No. The machine (Virtual), has 1024MB and the filesystem has 263MB. The resulting ISO is less than 150MB.