RSS: Blog | Wiki | Forum

Compiling EasyOS in chroot

Un article de Easyneuf.

This is a HOWTO to build your own EasyOS development image. To build a production image, you have to use the autobuild repository and use Luc's chroot.

[modifier] Build your environment

During compilation, some software aren't made to be cross-compiled and will use their development files (C headers, libraries) directly on the system. It is thus better to create a minimalistic Linux distribution to create your image.

Our choice here is to use a Debian-based distribution. It is necessary to have the debootstrap and chroot tools to build this minimalistic distribution.

The following example happens in the howtobuild directory of the fredo user and creates a etch-chroot directory. You can of course change these settings.

Here are the steps to follow to perform the installation:

Become root :

fredo@ubuntu:~/howtobuild$ su
root@ubuntu:~/howtobuild#

Install the distribution (here a debian 'etch' in the 'etch-chroot' directory):

root@ubuntu:~/howtobuild# debootstrap etch etch-chroot http://ftp.debian.org/debian
I: Retrieving Release
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Checking component main on http://ftp.debian.org/debian...
I: Retrieving adduser
I: Validating adduser
I: Retrieving apt
[...]
I: Configuring sysklogd...
I: Configuring tasksel...
I: Base system installed successfully.
root@ubuntu:~/howtobuild# 

Now we have a basic Debian distribution. We can thus change the root directory with chroot to get into this distribution:

root@ubuntu:~/howtobuild# chroot etch-chroot
root@ubuntu:/# 

Now, we have to download the remaining necessary software:

root@ubuntu:/# apt-get update
Réception de : 1 http://ftp.debian.org etch Release.gpg ...
[...]
root@ubuntu:/# apt-get install zip tar bzip2 bison libncurses5-dev pkg-config gettext libglib2.0-dev xutils intltool unzip zip libidl-dev locales gcc make g++ ccache  bc libtool automake1.9 automake1.4 autoconf flex libpng12-dev mercurial libxml2 ssh curl vim less grub
Lecture des listes de paquets... 
Construction de l'arbre des dépendances...

During the installation, the installer is asking if you really want to install all these uncertified packages. Answer yes to all the questions.

To free some disk space, we clean up the temporary files.

root@ubuntu:/# apt-get clean

The following procedure forces the locale to en_US.UTF-8. It is necessary to use the filenames in encoded in UTF-8. Furthermore, the chroot keeps the environment variables, including those about the language.

root@ubuntu:/# dpkg-reconfigure -freadline locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
  LANGUAGE = "fr_FR:fr:en_GB:en",
  LC_ALL = (unset),
  LANG = "fr_FR.UTF-8"
    are supported and installed on your system.
[...]
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
Configuring locales
-------------------

Locale is a framework to switch between multiple languages for users who can select to use their language, country, characters, collation order, etc.

Choose which locales to generate.  The selection will be saved to `/etc/locale.gen', which you can also edit manually (you need to run `locale-gen' afterwards).

When `All locales' is selected, /etc/locale.gen will be set as a symlink to /usr/share/i18n/SUPPORTED.

  1. Tous les choix possibles        80. da_DK.UTF-8 UTF-8               159. es_PA.UTF-8 UTF-8              238. iw_IL ISO-8859-8        317. se_NO UTF-8
  2. aa_DJ ISO-8859-1                81. de_AT ISO-8859-1                160. es_PE ISO-8859-1               239. iw_IL.UTF-8 UTF-8       318. si_LK UTF-8
  3. aa_DJ.UTF-8 UTF-8               82. de_AT.UTF-8 UTF-8               161. es_PE.UTF-8 UTF-8              240. ja_JP.EUC-JP EUC-JP     319. sid_ET UTF-8
  [...]
  78. da_DK ISO-8859-1               157. es_NI.UTF-8 UTF-8              236. it_IT.UTF-8 UTF-8              315. rw_RW UTF-8             394. zu_ZA.UTF-8 UTF-8
  79. da_DK.ISO-8859-15 ISO-8859-15  158. es_PA ISO-8859-1               237. it_IT@euro ISO-8859-15         316. sa_IN UTF-8

(Enter the items you want to select, separated by spaces.)

Locales to be generated:  126 197

[...]
root@ubuntu:/#

Now, we have to add a use to the chrooted system: I use here the same uid as on the main system to easily copy files between the two.

root@ubuntu:/# adduser -uid 1000 fredo
Ajout de l'utilisateur « fredo »...
Ajout du nouveau groupe « fredo » (1000)...
Ajout du nouvel utilisateur « fredo » (1000) avec le groupe « fredo »...
Création du répertoire personnel « /home/fredo »...
Copie des fichiers depuis « /etc/skel »...
Enter new UNIX password: 
Retype new UNIX password: 
[...]

[modifier] Build the image

In the chroot, we log as the new user:

root@ubuntu:/# su - fredo
fredo@ubuntu$

Now we can get the project :

fredo@ubuntu:~$ hg clone http://hg.easyneuf.org/9buildroot
requesting all changes
adding changesets
adding manifests
adding file changes
added 1558 changesets with 6921 changes to 4770 files
3400 files updated, 0 files merged, 0 files removed, 0 files unresolved
fredo@ubuntu:~$ cd 9buildroot/

The project downloads the source files of the needed software in a directory called downloads, in the user home directory. The files are only downloaded if they do not exist in this directory. However, sometimes a server won't answer the download request, thus stopping the compilation.

It is thus better to download the source files before starting the compilation:

fredo@ubuntu:~$ MERCURIAL_SERVER="http://hg.easyneuf.org" ./build --config
fredo@ubuntu:~$ MERCURIAL_SERVER="http://hg.easyneuf.org" make source
[...]
100%[===========================================================>] 41 853 865     3.64M/s    ETA 00:00

10:53:25 (3.02 MB/s) - « /home/fredo/downloads/linux-2.6.18.6.tar.bz2 » sauvegardé [41853865/41853865]

Terminé --10:53:25--
Téléchargement: 41 853 865 octets dans 1 fichiers
fredo@ubuntu:~/9buildroot$

Then, we can finally start building the image :

fredo@ubuntu:~/9buildroot$ MERCURIAL_SERVER="http://hg.easyneuf.org" ./build
Build log is stored in /home/fredo/9buildroot/buildroot.log
Build started at Wed, 23 May 2007 15:38:23 +0000
Wait while deleting old crosstool
Cleaning crosstool
checkout crosstool
building crosstool
Setting up ccache
Making crosstool tarball
Deleting crosstool build
Cleaning buildroot
building buildroot
Finished at Wed, 23 May 2007 21:45:38 +0000
fredo@ubuntu: ~/9buildroot