Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Debian GNU/Linux Reference Guide
Prev Home Next

8.6.35 chroot

The chroot program, chroot(8), enables us to run different instances of the GNU/Linux environment on a single system simultaneously without rebooting.

One may also run a resource hungry program such as apt-get or dselect under the chroot of a fast host machine while NFS-mounting a slow satellite machine to the host as r/w and the chroot point being the mount point of the satellite machine.


8.6.35.1 Run a different Debian distribution with chroot

A chroot Debian environment can easily be created by the debootstrap command in Sarge. For post-Sarge distributions, you may use cdebootstrap command instead with appropriate option. For example, to create a Sid chroot on /sid-root while having fast Internet access:

     main # cd / ; mkdir /sid-root
     main # debootstrap sid /sid-root https://ftp.debian.org/debian/
     ... watch it download the whole system
     main # echo "proc-sid /sid-root/proc proc none 0 0" >> /etc/fstab
     main # mount proc-sid /sid-root/proc -t proc
     main # cp /etc/hosts /sid-root/etc/hosts
     main # chroot /sid-root /bin/bash
     chroot # cd /dev; /sbin/MAKEDEV generic ; cd -
     chroot # apt-setup # set-up /etc/apt/sources.list
     chroot # vi /etc/apt/sources.list # point the source to unstable
     chroot # dselect  # you may use aptitude, install mc and vim :-)

At this point you should have a fully working Debian system, where you can play around without fear of affecting your main Debian installation.

This debootstrap trick can also be used to install Debian to a system without using a Debian install disk, but instead one for another GNU/Linux distribution. See https://www.debian.org/releases/stable/i386/apcs04.html.en.


8.6.35.2 Setting up login for chroot

Typing chroot /sid-root /bin/bash is easy, but it retains all sorts of environment variables that you may not want, and has other issues. A much better approach is to run another login process on a separate virtual terminal where you can log in to the chroot directly.

Since on default Debian systems tty1 to tty6 run Linux consoles and tty7 runs the X Window System, let's set up tty8 for a chrooted console as an example. After creating a chroot system as described in Run a different Debian distribution with chroot, Section 8.6.35.1, type from the root shell of the main system:

     main # echo "8:23:respawn:/usr/sbin/chroot /sid-root "\
            "/sbin/getty 38400 tty8"  >> /etc/inittab
     main # init q    # reload init

8.6.35.3 Setting up X for chroot

You want to run the latest X and GNOME safely in your chroot? That's entirely possible! The following example will make GDM run on virtual terminal vt9.

First install a chroot system using the method described in Run a different Debian distribution with chroot, Section 8.6.35.1. From the root of the main system, copy key configuration files to the chroot system.

     main # cp /etc/X11/XF86Config-4 /sid-root/etc/X11/XF86Config-4
     main # chroot /sid-root # or use chroot console
     chroot # cd /dev; /sbin/MAKEDEV generic ; cd -
     chroot # apt-get install gdm gnome x-window-system
     chroot # vi /etc/gdm/gdm.conf # do s/vt7/vt9/ in [servers] section
     chroot # /etc/init.d/gdm start

Here, /etc/gdm/gdm.conf was edited to change the first virtual console from vt7 to vt9.

Now you can easily switch back and forth between full X environments in your chroot and your main system just by switching between Linux virtual terminals; e.g. by using Ctrl-Alt-F7 and Ctrl-Alt-F9. Have fun!

[FIXME] Add a comment and link to the init script of the chrooted gdm.


8.6.35.4 Run other distributions with chroot

A chroot environment for another Linux distribution can easily be created. You install a system into separate partitions using the installer of the other distribution. If its root partition is in /dev/hda9:

     main # cd / ; mkdir /other-dist
     main # mount -t ext3 /dev/hda9 /other-dist
     main # chroot /other-dist /bin/bash

Then proceed as in Run a different Debian distribution with chroot, Section 8.6.35.1, Setting up login for chroot, Section 8.6.35.2, and Setting up X for chroot, Section 8.6.35.3.


8.6.35.5 Build a package with chroot

There is a more specialized chroot package, pbuilder, which constructs a chroot system and builds a package inside the chroot. It is an ideal system to use to check that a package's build-dependencies are correct, and to be sure that unnecessary and wrong build dependencies will not exist in the resulting package.


Debian GNU/Linux Reference Guide
Prev Home Next

 
 
  Published under the terms of the GNU General Public License Design by Interspire