2

After lot of googling and posting and crying over obscure GCC linker error messages I concluded that the only way to reliably build something in foreign CPU architecture is to set up a chroot environment. That is kind of funny, because I'm already running Debian in VirtualBox, so now it will be virtual system in virtual system.

As I read through various tutorials on chroot I noticed two things that I don't like about them:

  1. They always include a command that downloads system from some URL they have chosen, like below. I want to use similar system I already have, and as minified as possible.

    sudo debootstrap --variant=buildd --arch i386 lucid /var/chroot/ http://mirror.url.com/ubuntu/
    
  2. There's never actual mention about compiling a project that is located on host system. Like I don't really want to copy my project somewhere - if that was the case, I can just setup another virtual box system.

So I wanted to ask if someone actually did manage to create chroot system and used it to build a project. Of course it would be ideal if that system was as minimal as possible since I'm just installing it for libraries. And it would be really nice if it just downloaded 32bit version of 64bit system it's running from.

Linux programmers keep saying how programming on Linux is much easier than windows. I'd love to finally experience some of that.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Tomáš Zato
  • 1,776
  • it's amazing how much stuff (i love that technical term) i use to build and debug 64-bit programs and with disk space so cheap, i just used a full 32-bit system to save my time. – Skaperen Sep 30 '15 at 09:16

2 Answers2

1

I already wrote a tutorial on creating a 32-bit chroot, so I'm not going to repeat it here, and I'm going to assume that you've read it. In this answer I'll just address the specific points in your question.

They always include a command that downloads system from some URL they have chosen, like below. I want to use similar system I already have, and as minified as possible.

You do need to download the packages. Most 32-bit packages are not installed or installable on your system because you have 64-bit packages that provide the same files.

You do need to pick the version of the 32-bit distribution to install. The same technique can be used to install other versions of a distribution after all.

You're stating two incompatible goals: one is to have a minimal system, the other is to reproduce the 64-bit system you already have. If you want a minimal system, start with what debootstrap installs. Sure, you can probably save a few megabytes of space by removing a few packages that will never be used in the chroot, but it isn't worth the time to fiddle with the dependencies (you'd probably have to break a lot of dependencies to excise the packages that aren't strictly necessary). If you want to reproduce your existing installation, use apt-clone if available (example), and if not use dpkg --get-selections and apt-mark.

There's never actual mention about compiling a project that is located on host system. Like I don't really want to copy my project somewhere - if that was the case, I can just setup another virtual box system.

The chroot set up by schroot already has your home directory. More precisely, /home is bind-mounted inside the chroot. So if your project is somewhere under /home, it's already available inside the chroot.

If you want to make other directories available, add entries to /etc/schroot/default/fstab, copying the existing entry for /home, e.g.

/dev            /dev            none    rw,bind         0       0
/dev/pts        /dev/pts        none    rw,bind         0       0
/home           /home           none    rw,bind         0       0
/tmp            /tmp            none    rw,bind         0       0
/scratch        /scrath         none    rw,bind         0       0

So I wanted to ask if someone actually did manage to create chroot system and used it to build a project.

I do this all the time. In fact it's why I wrote that post in the first place.

0

Build one in a VM, first, then copy it to a subdirectory to be your chroot one.

And, yes, I have done this and used it to do 32-bit clean builds.

Skaperen
  • 716
  • You mean that I just copy whole .vhd file into my x64 system? Are you sure your answer is sincerely all you can say on that matter? – Tomáš Zato Sep 30 '15 at 10:03