From Mageia wiki
Jump to: navigation, search
m (Remaniement des numérotations des chapites)
m (ajout avertissement traduction)
Line 1: Line 1:
 
{{Bandeau_multi-langues-fr|[[Packagers_chroot|English]] ; [[Empaqueteurs_chroot|Français]] ; }}
 
{{Bandeau_multi-langues-fr|[[Packagers_chroot|English]] ; [[Empaqueteurs_chroot|Français]] ; }}
 
[[Main_Page | Accueil [en]]] → [[Accueil-fr | Accueil]] → [[Contribuer-fr | Équipes]] → [[Equipe_Packageurs-fr | Packageurs]] → [[Outils_Empaqueteur_Mageia-fr | Les outils d'empaquetage Mageia]]  → [[Empaqueteurs_chroot|chroot pour empaqueteur]] <hr>
 
[[Main_Page | Accueil [en]]] → [[Accueil-fr | Accueil]] → [[Contribuer-fr | Équipes]] → [[Equipe_Packageurs-fr | Packageurs]] → [[Outils_Empaqueteur_Mageia-fr | Les outils d'empaquetage Mageia]]  → [[Empaqueteurs_chroot|chroot pour empaqueteur]] <hr>
 +
 +
{{warning|Cette page est en cours de traduction. N'hésitez pas continuer la traduction, à la relire ou la corriger !}}
  
 
= Pourquoi utiliser chroot ? =
 
= Pourquoi utiliser chroot ? =

Revision as of 07:00, 31 July 2018

Template:Bandeau multi-langues-fr

Accueil [en] Accueil Équipes Packageurs Les outils d'empaquetage Mageiachroot pour empaqueteur


Warning!
Cette page est en cours de traduction. N'hésitez pas continuer la traduction, à la relire ou la corriger !

Pourquoi utiliser chroot ?

Often when building or rebuilding packages you will need to install various libraries and development headers, many of which you won't want on your regular day-to-day installation.

A self-contained chroot environment which can contain all needed development packages is an excellent solution. It can easily be backed up and used as a test environment as well as a build environment; all without cluttering up your main install.

And of course if you do manage to kill the chroot environment, it's as easy to fix as restoring the backup from a tarball or even starting it again from scratch.

Créer un chroot

Note: Mageia has a tool, iurt which is able to do auto-builds using a clean chroot environment each time and also enables the ability to cross-compile to other architectures. You will require high bandwidth to use this tool efficiently.

Prérequis

  • Root access to a running Mageia system
  • urpmi
  • access to a Mageia mirror, either remote (http/ftp/rsync...) or local (nfs/cdrom/file...)

Installation d'un chroot

You need to create your working directory. (/mnt/chroot/cauldron for eg). This directory will host your chrooted Mageia system

   mkdir -p /mnt/chroot/cauldron

Setup urpmi with the urpmi.addmedia command. urpmi allows you to install any version of Mageia in a chroot without modifying the urpmi configuration of your running system. We choose here to install Mageia cauldron system into the chroot. We will use the --distrib option of urpmi.addmedia which automatically configures the repository[1] for urpmi:

  • "Core"
  • "Core Updates"
  • "Non-free"
  • "Non-free Updates"

For 32bit systems

   urpmi.addmedia --distrib --urpmi-root /mnt/chroot/cauldron ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/Mageia/distrib/cauldron/i586

For 64bit systems

   urpmi.addmedia --distrib --urpmi-root /mnt/chroot/cauldron ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/Mageia/distrib/cauldron/x86_64

A list of mirrors is available at https://mirrors.mageia.org/

Installer un système de base

The minimum required packages for an operational chroot are:

  • Template:Pkg (required)
  • Template:Pkg (required for self contained chroot)
  • Template:Pkg (strongly recommended): where <XX> stands for the ISO code of the locale you usually use within your running system [1] In our example, locales-fr or locales-en.

You can also install additional packages during the initial setup. For example; syslinux

   urpmi  --urpmi-root /mnt/chroot/cauldron basesystem urpmi locales-fr syslinux

Accédez au chroot

To access the chroot;

   chroot /mnt/chroot/cauldron

Inside the self-contained chroot, you can work with it as a regular system. You can exit the chroot with the exit command.

Configuration minimale

  • DNS Setup: In order to have a working network connection within our chroot, you have to fill in /mnt/chroot/cauldron/etc/resolv.conf, the dns ip address of your provider. You can simply copy your working /etc/resolv.conf into the chroot /mnt/chroot/cauldron/etc/resolv.conf
   cp /etc/resolv.conf /mnt/chroot/cauldron/etc/resolv.conf
  • Mount /proc filesystem: outside the chroot, mount the /proc virtual filesystem of your running system inside your chroot
   mount -o bind /proc /mnt/chroot/cauldron/proc

Construire des paquets

In the chroot environment, you should now install the following packages:

  • rpm: our patched version of Red Hat's.
  • rpm-build: scripts used to build packages.
  • spec-helper: a tool to minimalize the specfiles by doing automatic things such as stripping the binaries and compressing the man pages.
  • libtool: used by some configure scripts to build shared libraries.
  • rpmlint: used to check the validity of the generated rpm.

You can now follow the Packagers_RPM_tutorial guide while using the chroot environment.

Bonus

Accédez à votre système chrooté via SSH

Enter into your chrooted system

   chroot /mnt/chroot/cauldron

Install the Template:Pkg package inside your chroot

   urpmi openssh-server

Change the default port (port 22), which will be used by the ssh server of your chrooted system to to some other port, 2222 for example, so it doesn't conflict with the real ssh server that might be running on the host machine. You'll have to edit /etc/ssh/sshd_config

   # $OpenBSD: sshd_config,v 1.74 2006/07/19 13:07:10 dtucker Exp $
   
   # This is the sshd server system-wide configuration file.  See
   # sshd_config(5) for more information.
   (...)
   Port 2222
   (...)

Launch the ssh server of your chrooted system

   systemctl start sshd

Add a user inside your chroot with useradd

   useradd jdoe
   passwd jdoe

Exit the chroot

   exit

Now, as long as the /proc filesystem is mounted inside your chroot and that your chrooted sshd server is running, you should be able to log in your chrooted system via ssh like this

   ssh jdoe@localhost -p 2222

If you don't get a shell after typing the password, you may need to add this to /etc/fstab in the chroot :

   none /dev/pts devpts defaults 0 0

And then, of course, mount it.

   mount /dev/pts

Accédez à d'autre partitions

Any other available partitions can also be shared to the chroot by binding them to a mount the same way as we did with /proc.

For example, if your /home is a separate partition;

   mount -o bind /home /mnt/chroot/cauldron/home

or for external media;

   mount -o bind /path/to/media /mnt/chroot/cauldron/media/external