Development/Howto/Chroot

From Mandriva Community Wiki

Jump to: navigation, search


Contents

Introduction

Installating mandriva linux in a chroot is a simple and efficient way to work with several version of the Mandriva distribution within your actual running Mandriva Linux system. Indeed, if you mostly want to work with alternate version of mandriva linux within the command line interface, you'll easy have access to those alternate mandriva Linux version thanks to the chroot system command.

So for example, you can run a cooker version of mandriva inside a rock solid official Mandriva Linux release.

You can create a clean chroot environment in one of two ways:

  • by copying an existing clean install
  • or by using urpmi.

Copying a existing clean install

For this example we use the local system, but you can install a clean system on another partition or computer and copy that instead.

# rsync -av --one-file-system / /mnt/chroot/

If you have separate /usr and /var partitions, redo it for each mount point, except network and special entry. You want only the system as separate:

You have /usr and /var:

for i in "var usr"; do
  mkdir ${mychroot}/${i}
  rsync -av --one-file-system /${i} /mnt/chroot/${i}
done

You'll need to recreate /dev without devfs by remounting / with -o bind and using rsync, or using makedev.

Outside the chroot: mkdir /mnt/disk

mount -o bind / /mnt/disk
rsync -av /mnt/disk/dev/ /mnt/chroot/dev/
umount /mnt/disk

FIXME:This section needs to be updated

Creating a chroot with urpmi

Requirements

  • Root access to a running Mandriva linux system
  • urpmi (version 4.9.5 or above). Shipped with Mandriva Linux since Mandriva Linux 2007.0
  • an access to a Mandriva Linux mirror, either distant (http/ftp/rsync...) or local (nfs/cdrom/file...)
  • db42-utils and db46-utils if you wish to install a previous version in the chroot

Installing the chroot

  • You need to create your working directory. (/mnt/chroot/cooker for eg). This directory will host your chrooted mandriva linux system
 mkdir -p /mnt/chroot/cooker
  • Setup urpmi with the urpmi.addmedia command. urpmi since urpmi-4.9.5, allows you to install any version of mandriva linux in a chroot without modifying the urpmi configuration of your running system. We choose here to install a Mandriva Linux cooker system into the chroot. We will use the --distrib option of urpmi.addmedia which automagically configure the following repository[1] for urpmi:
    • "Main"
    • "Main Updates"
    • "Contrib"
    • "Contrib Updates"
    • ""Non-free"
    • "Non-free Updates"
urpmi.addmedia --distrib --urpmi-root /mnt/chroot/cooker ftp://ftp.proxad.net/pub/Distributions_Linux/MandrivaLinux/devel/cooker/i586
  • Install your mandriva linux system. In order to install a fully functional Mandriva Linux system, you'll have to install the following packages:
    • basesystem (required)
    • urpmi (recommended)
    • locales-<XX> (optionnal): where <XX> stands for the ISO code of the locale you usually use within your running system [1] In our example, we will install the locales-fr package.
    • Any additionnal package you want (optionnal)... Here we want to install a complete gnome environnment in the chroot by using the task-gnome metapackage.

If you chrooted on a partition and if if you need to boot on it, you might wish to read this section before launching urpmi (even if the document talks about virtual machine, this will work for any real partition): Building_a_virtual_machine_with_VirtualBox#Installation_using_a_chroot_.28non_bootable.29_directory

urpmi  --urpmi-root /mnt/chroot/cooker basesystem urpmi locales-fr task-gnome
  • Check that your chrooted mandriva linux system is fully functionnal. You should be able to access your new system with the chroot command.
chroot /mnt/chroot/cooker
Inside the chroot, you can work with your chrooted system as usual. You can exit the chroot with the exit command.

Basic Configuration of the chroot

DNS Setup

In order to have a working network connection within our chroot, you have to fill in /mnt/chroot/cooker/etc/resolv.conf, the dns ip address of your provider. You can simply copy your working /etc/resolv.conf into the chroot /mnt/chroot/cooker/etc/resolv.conf

cp /etc/resolv.conf /mnt/chroot/cooker/etc/resolv.conf

Mount /proc

Outside the chroot, mount the /proc virtual filesystem of your running system inside your chroot

mount -o bind /proc /mnt/chroot/cooker/proc

How to ...

Access your chrooted system via SSH

  • Enter into your chrooted system
chroot /mnt/chroot/cooker
  • Install the openssh-server 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
service sshd start
  • 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

Using icecream inside chroot

Outside chroot install icecream client package and start daemon. Still outside the chroot, mount the /var/cache virtual filesystem of your running system inside your chroot

mount -o bind /var/cache /mnt/chroot/cooker/var/cache

Inside chroot, just install icecream package and log again to enable it. Your compilations inside chroot should now be routed by outside icecrem daemon.

Access your data

If the home directory is located in a seperate partition, you can use it also as the the home directory of your chrooted system

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

Launch X Applications inside the chroot

You can run any graphical application installed inside your chroot as long as your host system is running a X server.

There is different way to do this:

  • Use xhost
  • Use a nested X server like Xnest or the more modern Xephyr
  • Access your chroot via SSH using the X11 forwarding (ssh -X) feature

Using xhost

  • Run the following command outside the chroot:
$ xhost +localhost
  • Then enter the chroot and load your graphical application as in the following example:
$  DISPLAY=localhost:0 /usr/bin/mozilla

FIXME:seems that this tips isn't working anymore

Using Xnest

  • Install Xnest into your running host system
urpmi x11-server-xnest
  • Run the following command outside the chroot:
$ Xnest -ac :1
  • Then enter the chroot and load your graphical application as in the following example:
$  export DISPLAY=localhost:1
$ /usr/bin/mozilla

Using Xephyr

  • Install Xephyr package into your running host system
urpmi x11-server-xephyr
  • Run the following command outside the chroot:
$ Xephyr -ac :1
  • Then enter the chroot and load your graphical application as in the following example:
$  export DISPLAY=localhost:1
$ /usr/bin/mozilla

Using SSH X11 forwarding

FIXME

Personal tools