From Mageia wiki
Jump to: navigation, search
(remove {{title}} - theres no template with this name)
Line 1: Line 1:
 +
 +
NOTE: This page is obsolete. Instead of using chroot, use systemd-nspawn. See
 +
https://wiki.mageia.org/en/Systemd-nspawn
 +
 
__TOC__
 
__TOC__
 +
 
= Introduction =
 
= Introduction =
 
Installating Mageia in a chroot is a simple and efficient way to work with the Mageia distribution within your running Mageia system. Indeed, if you mostly want to work with alternate version of Mageia within the commandline interface, you'll easy have access to Mageia thanks to the {{prog|chroot}} system command.
 
Installating Mageia in a chroot is a simple and efficient way to work with the Mageia distribution within your running Mageia system. Indeed, if you mostly want to work with alternate version of Mageia within the commandline interface, you'll easy have access to Mageia thanks to the {{prog|chroot}} system command.

Revision as of 13:13, 20 May 2019

NOTE: This page is obsolete. Instead of using chroot, use systemd-nspawn. See https://wiki.mageia.org/en/Systemd-nspawn

Introduction

Installating Mageia in a chroot is a simple and efficient way to work with the Mageia distribution within your running Mageia system. Indeed, if you mostly want to work with alternate version of Mageia within the commandline interface, you'll easy have access to Mageia thanks to the chroot system command.

So for example, you can run a Cauldron version of Mageia inside a rock solid official Mageia release.

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

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

Note: If you want to use this for packaging software, please have a look at the special instructions at Packagers chroot.

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
  

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 Mageia system
  • urpmi (version 4.9.5 or above).
  • Access to a Mageia mirror, either distant (HTTP/FTP/RSYNC...) or local (NFS/CD/DVD-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/mageia for eg). This directory will host your chrooted Mageia system
 mkdir -p /mnt/chroot/mageia
  
  • Setup urpmi with the urpmi.addmedia command. Template:Pkg since urpmi-4.9.5, 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 a Mageia Cauldron system into the chroot. We will use the --distrib option of urpmi.addmedia which automatically configure the following repository<ref>Check out the urpmi.addmedia manual if you want to fine tune your repository configuration</ref> for urpmi:
 **"Main"
 **"Main Updates"
 **"Contrib"
 **"Contrib Updates"
 **""Non-free"
 **"Non-free Updates"
  urpmi.addmedia --distrib --urpmi-root /mnt/chroot/mageia ftp://ftp.yourftpmirrorofchoice.com/path/to/the/Cauldron/arch-dir/
  
  • Install your Mageia system. In order to install a fully functional Mageia system, you'll have to install the following packages:
 ** basesystem (required)
 ** urpmi (recommended)
 ** locales-<XX> (optional): where <XX> stands for the ISO code of the locale you usually use within your running system. In our example, we will install the Template:Pkg package. 
 **Any additional package/s you want (optional)... Here we want to install a complete GNOME environment in the chroot by using the Template:Pkg 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/mageia basesystem urpmi locales-en task-gnome
  
  • Check that your chrooted Mageia system is fully functional. You should be able to access your new system with the chroot command.
  chroot /mnt/chroot/mageia
  

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/mageia/etc/resolv.conf, the DNS IP-adress of your provider. You can simply copy your working /etc/resolv.conf into the chroot /mnt/chroot/mageia/etc/resolv.conf

  cp /etc/resolv.conf /mnt/chroot/mageia/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/mageia/proc
  

How to ...

Access your chrooted system via SSH

  • Enter into your chrooted system
  chroot /mnt/chroot/mageia
  
  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/mageia/var/cache
  

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

Access other 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

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 Template:Pkg
  • 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

  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

  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