个人工具

“UbuntuHelp:DebootstrapChroot”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
 
(未显示同一用户的4个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/DebootstrapChroot}}
 
{{From|https://help.ubuntu.com/community/DebootstrapChroot}}
 
{{Languages|UbuntuHelp:DebootstrapChroot}}
 
{{Languages|UbuntuHelp:DebootstrapChroot}}
== [[UbuntuHelp:DebootstrapChroot|DebootstrapChroot]] ==
+
This article demonstrates a quick and easy way to create a ''chroot'' environment on an Ubuntu computer, which is like having a virtual system without the overhead of actual virtualization.
This article shows you how to use [http://packages.ubuntu.com/debootstrap debootstrap] to build a ''chroot environment'' that you can use for various needs, from trying out the latest (or even oldest ;) Ubuntu releases, or even working with [http://www.debian.org Debian] releases, to utilizing the chroot as a package building environment.
+
A ''chroot'' can be used for things like:
You can work anywhere - this Howto will assume you're using <code><nowiki>/var/chroot</nowiki></code> .  It will also assume that you want to install a [[UbuntuHelp:BreezyBadger|BreezyBadger]] chroot; if you are going to use other Ubuntu releases, replace ''breezy'' below with ''warty'' for [[UbuntuHelp:WartyWarthog|WartyWarthog]], ''hoary'' for [[UbuntuHelp:HoaryHedgehog|HoaryHedgehog]], ''dapper'' for [[UbuntuHelp:DapperDrake|DapperDrake]], ''edgy'' for [[UbuntuHelp:EdgyEft|EdgyEft]], or "feisty" for [[UbuntuHelp:FeistyFawn|FeistyFawn]].
+
* Running a 32-bit Firefox browser or a 32-bit Wine bottle on a 64-bit system.
=== Getting and installing debootstrap ===
+
* Trying an older or newer Ubuntu release without reinstalling the operating system.
For the least pain and gnashing of teeth, please get the Ubuntu binary packages ''manually'':
+
* Trying a [http://www.debian.org Debian] release or other distribution derived from Debian.
* http://packages.ubuntu.com/hoary/admin/debootstrap - If you want a ''hoary'' chroot
+
* Cross compiling and building packages for a different platform like [http://www.launchpad.net/ Launchpad] or [https://launchpad.net/soyuz/ Soyuz] does it.
* http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.1.4ubuntu4_all.deb - If you want a ''breezy'' chroot
+
=== Example Configuration ===
* http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu5~dapper1_all.deb - If you want a ''dapper'' chroot
+
In this example, we use a current Ubuntu 9.04 Jaunty system (the "host") to create a ''chroot'' for the older Ubuntu 8.04 Hardy release (the "target"). We are arbitrarily naming the new ''chroot'' environment '''hardy_i386''' and putting it in the /srv/chroot directory on the host system.
* http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu7_all.deb - If you want a ''edgy'' chroot
+
=== Step 1: Install packages on the host computer. ===
* http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.2ubuntu3_all.deb - If you want a ''feisty'' chroot (if that's not available go to http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/ and find the newest one)
+
First, install `debootstrap`, which is a utility that downloads and unpacks a basic Ubuntu system:
Example: Terminal session <code><nowiki>wget</nowiki></code>-ing and installing the latest Feisty debootstrap:
+
 
<pre><nowiki>
 
<pre><nowiki>
  wget http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.2ubuntu3_all.deb
+
  $ sudo apt-get install debootstrap
sudo dpkg --install debootstrap_0.3.3.2ubuntu3_all.deb
+
 
</nowiki></pre>
 
</nowiki></pre>
=== Installing and configuring dchroot ===
+
Second, install `schroot`, which is a utility that wraps the regular `chroot` program and automatically manages ''chroot'' environments:
[http://packages.ubuntu.com/dchroot dchroot] is a convenient means of managing chroot environments; with this tool you can have both Breezy, Dapper, and even Debian Sid chroots in your Ubuntu install, and using a chroot environment is a simple as <code><nowiki>dchroot -c dapper -d</nowiki></code> ;)
+
To get it <code><nowiki>dchroot</nowiki></code> working in your system, just do the following in a Terminal:
+
 
<pre><nowiki>
 
<pre><nowiki>
  sudo apt-get install dchroot
+
  $ sudo apt-get install schroot
sudo mkdir /var/chroot # Remember, we assume our chroot is here
+
sudo editor /etc/dchroot.conf
+
 
</nowiki></pre>
 
</nowiki></pre>
Then append this line in <code><nowiki>/etc/dchroot.conf</nowiki></code>:
+
Note: The `debootstrap` utility is usually backwards compatible with older releases, but it may be incompatible with newer releases.  For example, the `debootstrap` that is bundled with Jaunty can prepare a Hardy ''chroot'' like we are doing here, but the `debootstrap` that is bundled with Hardy cannot prepare a Jaunty ''chroot''.
 +
If you have any difficultly with a `debootstrap` version mismatch, then visit http://packages.ubuntu.com/ to manually download and install the [http://packages.ubuntu.com/search?keywords=debootstrap debootstrap package] on the host system from the repository for the target release.
 +
=== Step 2: Create a configuration file for schroot. ===
 +
Choose a short name for the ''chroot'', we use '''hardy_i386''' in this example, and create a configuration file for it like this:
 
<pre><nowiki>
 
<pre><nowiki>
mychroot /var/chroot
+
  sudo editor /etc/schroot/chroot.d/hardy_i386.conf
 
</nowiki></pre>
 
</nowiki></pre>
=== Setting up your chroot with debootstrap ===
+
Put this in the new file:
If you want a 32-bit chroot on amd64 add <code><nowiki>--arch i386</nowiki></code> to this command line.  If you use the chroot to build packages add <code><nowiki>--variant=buildd</nowiki></code> .  Change ''breezy'' to according to your needs to ''warty'', ''hoary'', or ''dapper'', or leave as is for ''breezy'' chroot.
+
To actually install the base chroot, open a Terminal and do:
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo debootstrap --variant=buildd --arch i386 breezy /var/chroot/ http://archive.ubuntu.com/ubuntu/
+
  [hardy_i386]
 +
  description=Ubuntu 8.04 Hardy for i386
 +
  location=/srv/chroot/hardy_i386
 +
  #personality=linux32
 +
  root-users=bob
 +
  run-setup-scripts=true
 +
  run-exec-scripts=true
 +
  type=directory
 +
  users=alice,bob,charlie
 
</nowiki></pre>
 
</nowiki></pre>
<code><nowiki>debootstrap</nowiki></code> will then build a [[UbuntuHelp:BreezyBadger|BreezyBadger]] chroot in <code><nowiki>/var/chroot/</nowiki></code>, getting the base packages in <code><nowiki>http://archive.ubuntu.com/ubuntu/</nowiki></code>, and, depending on the given additional options (in square brackets,) <code><nowiki>debootstrap</nowiki></code> will build a chroot for the given architecture and variant.
+
Note: if you copy this example to your clipboard, be careful to start each line in column 1 before you save the new file! If you forget, the command '''schroot -l''' will fail with an error, e.g. `E: /etc/schroot/chroot.d/hardy_i386.conf: line 0: Invalid line: “  [hardy_i386]”`.
If <code><nowiki>debootstrap</nowiki></code> finishes successfully, you'll be left with a base chroot in <code><nowiki>/var/chroot</nowiki></code>, which is, well, hardly suitable for anything very interestingTo actually get our chroot to work and be able to, say, grab packages from the network, do the following right after <code><nowiki>debootstrap</nowiki></code>:
+
Change these things in the example configuration file to fit your system:
 +
. '''location''':  This should be a directory that is outside of the /home tree.  The latest `schroot` documentation recommends /srv/chroot.
 +
. '''personality''':  Enable this line if the host system is 64-bit running on an amd64/x64 computer and the chroot is 32-bit for i386Otherwise, leave it disabled.
 +
. '''users''': These are users on the host system that can invoke the `schroot` program and get access to the ''chroot'' system.  Your username on the host system should be here.
 +
. '''root-users''': These are users on the host system that can invoke the `schroot` program and get direct access to the chroot system as the root user.
 +
Note: Do not put whitespace around the '=' character, and do not quote strings after the '=' character.
 +
=== Step 3: Run debootstrap. ===
 +
This will download and unpack a basic Ubuntu system to the chroot directory, similar to what the host system already has at the real root directory ("/").
 
<pre><nowiki>
 
<pre><nowiki>
  sudo cp /etc/resolv.conf /var/chroot/etc/resolv.conf
+
  $ sudo mkdir -p /srv/chroot/hardy_i386
  sudo cp /etc/apt/sources.list /var/chroot/etc/apt/
+
  $ sudo debootstrap --variant=buildd --arch i386 hardy /srv/chroot/hardy_i386 http://archive.ubuntu.com/ubuntu/
sudo sed -i s/dapper/breezy/g /var/chroot/etc/apt/sources.list #point apt-get to the right release
+
sudo chroot /var/chroot/
+
mount /proc
+
apt-get update
+
apt-get install wget debconf devscripts gnupg nano  #For package-building
+
apt-get update  #clean the gpg error message
+
apt-get install locales dialog  #If you don't talk en_US
+
locale-gen en_GB.UTF-8  # or your preferred locale
+
tzselect; TZ='Continent/Country'; export TZ  #Configure and use our local time instead of UTC; save in .profile
+
exit
+
 
</nowiki></pre>
 
</nowiki></pre>
You can stop here if you want and have a simple chroot that you use as root (<code><nowiki>sudo chroot /var/chroot</nowiki></code>)If you want to use your chroot as another user and have access to your normal /home etc inside the chroot, carry on ;)
+
This command should work for any distribution that is derived from Debian.  Substitute the architecture "i386", the release name "hardy", and the repository address "http://archive.ubuntu.com/ubuntu/" appropriatelyFor example, do this to get the 64-bit build of Hardy instead of the 32-bit build:
If you want to build a Debian chroot on an Ubuntu system you need to point it at a Debian archive:
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo debootstrap --arch i386 sid sid/ http://ftp.uk.debian.org/debian/
+
  $ sudo debootstrap --arch amd64 hardy /srv/chroot/hardy_amd64/ http://archive.ubuntu.com/ubuntu/
 
</nowiki></pre>
 
</nowiki></pre>
=== Setting up a dchroot (non-root) environment ===
+
Note: Remember to change all instances of '''hardy_i386''' to '''hardy_amd64''' in the configuration file and on the command line if you actually do this.
<code><nowiki>dchroot</nowiki></code> makes it possible to use your newly-built chroot even as a non-root user.  Hence, you can configure your chroot environment in such a way that you can even use your existing <code><nowiki>/home</nowiki></code> as the chroot's <code><nowiki>/home</nowiki></code>, thereby saving you some expensive moving in between homes, as well as making package building/testing a ''LOT'' more convenient.
+
Do something like this to get an upstream Debian release:
To do this, first fix the user and root password:
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo cp /etc/passwd /var/chroot/etc/
+
  $ sudo debootstrap --arch amd64 sid /srv/chroot/sid_amd64/ http://ftp.debian.org/debian/
sudo sed 's/\([^:]*\):[^:]*:/\1:*:/' /etc/shadow | sudo tee /var/chroot/etc/shadow
+
sudo cp /etc/group /var/chroot/etc/
+
sudo cp /etc/hosts /var/chroot/etc/ # avoid sudo warnings when it tries to resolve the chroot's hostname
+
 
</nowiki></pre>
 
</nowiki></pre>
Then enable sudo and setup your passwords for root and the first sudo user in the `admin` group:
+
=== Step 4: Check the chroot ===
 +
This command lists configured ''chroot''s:
 
<pre><nowiki>
 
<pre><nowiki>
sudo cp /etc/sudoers /var/chroot/etc/
+
  $ schroot -l
sudo chroot /var/chroot/
+
dpkg-reconfigure passwd
+
passwd <your first ubuntu user in the admin group>
+
 
</nowiki></pre>
 
</nowiki></pre>
Next, install the [http://packages.ubuntu.com/sudo sudo] package to be able to use it being in chroot:
+
If '''hardy_i386''' appears in the list, then run:
 
<pre><nowiki>
 
<pre><nowiki>
apt-get install sudo
+
  $ schroot -c hardy_i386 -u root
exit
+
 
</nowiki></pre>
 
</nowiki></pre>
Finish things up:
+
Note: This should work without using `sudo` to invoke the `schroot` program, and it should result in a root prompt in the ''chroot'' environment.
 +
Check that the root prompt is in a different system:
 
<pre><nowiki>
 
<pre><nowiki>
sudo editor /etc/fstab
+
  # lsb_release -a
 
</nowiki></pre>
 
</nowiki></pre>
Add these lines: (/media/cdrom is optional, of course, and you might have to create the dir in the chroot)
+
For the Hardy system that we just built, the `lsb_release` command should print:
 
<pre><nowiki>
 
<pre><nowiki>
/home          /var/chroot/home        none    bind            0      0
+
No LSB modules are available.
/tmp            /var/chroot/tmp        none    bind            0      0
+
Distributor ID: Ubuntu
/media/cdrom    /var/chroot/media/cdrom none    bind            0      0
+
Description: Ubuntu 8.04
/dev            /var/chroot/dev        none    bind            0      0
+
Release: 8.04
proc-chroot    /var/chroot/proc        proc    defaults        0      0
+
Codename: hardy
devpts-chroot  /var/chroot/dev/pts    devpts  defaults        0      0
+
 
</nowiki></pre>
 
</nowiki></pre>
Mount them:
+
We're done!
 +
== WARNING ==
 +
For convenience, the default `schroot` configuration rebinds the /home directory on the host system so that it appears in the ''chroot'' system.  This could be unexpected if you are familiar with the older `dchroot` program or the regular `chroot` program because it means that you can accidentally delete or otherwise damage things in /home on the host system.
 +
To change this behavior run:
 
<pre><nowiki>
 
<pre><nowiki>
sudo mount -a
+
  $ sudo editor /etc/schroot/mount-defaults
 
</nowiki></pre>
 
</nowiki></pre>
The default bash path includes chroot information.  To make this visible:
+
And disable the /home line so that the file reads:
 
<pre><nowiki>
 
<pre><nowiki>
sudo chroot /var/chroot/
+
  # mount.defaults: static file system information for chroots.
echo mychroot > etc/debian_chroot
+
  # Note that the mount point will be prefixed by the chroot path
exit
+
  # (CHROOT_PATH)
 +
  #
 +
  # <file system> <mount point>  <type>  <options>      <dump>  <pass>
 +
  proc            /proc          proc    defaults        0      0
 +
  /dev/pts        /dev/pts        none    rw,bind        0      0
 +
  tmpfs          /dev/shm        tmpfs  defaults        0      0
 +
  #/home          /home          none    rw,bind        0      0
 +
  /tmp            /tmp            none    rw,bind        0      0
 
</nowiki></pre>
 
</nowiki></pre>
Now when you want to use your chroot (you may omit the <code><nowiki>-c mychroot</nowiki></code> if there's only one, or you just want the first one in the file). The <code><nowiki>-d</nowiki></code> parameter means that your environment will be preserved, this is generally useful if you want chrooted applications to seamlessly use your X server, your session manager, etc.
+
The mount.defaults file is the /etc/fstab for ''chroot'' environments.
 +
== Hints ==
 +
Install the ubuntu-minimal package in a new ''chroot'' after you create it:
 
<pre><nowiki>
 
<pre><nowiki>
dchroot -c mychroot -d
+
  $ schroot -c hardy_i386 -u root
</nowiki></pre>
+
  # apt-get install ubuntu-minimal
Tada! Now you can switch to and from your main <code><nowiki>/</nowiki></code> and <code><nowiki>/var/chroot/</nowiki></code>, without even becoming root!
+
</nowiki></pre>   
==== Shortcuts / Usage ====
+
If you get locale warnings in the ''chroot'' like "'''Locale not supported by C library.'''" or '''"perl: warning: Setting locale failed."''' , then try one or more of these commands:
you can type dchroot -d "command" and it executes that command in the chroot.
+
I have this script do_chroot in /usr/local/bin:
+
<pre><nowiki>
+
#!/bin/sh
+
/usr/bin/dchroot -d "`echo $0 | sed 's|^.*/||'` $*"
+
</nowiki></pre>
+
''I had trouble with quoting in the above script. This one works better for me. ~JPKotta''
+
 
<pre><nowiki>
 
<pre><nowiki>
args=""
+
  $ sudo dpkg-reconfigure locales
for i in "$@" ; do
+
    args="$args '$i'"
+
done
+
 
+
/usr/bin/dchroot -d -- "$0" "$args"
+
 
</nowiki></pre>
 
</nowiki></pre>
Then I create a symbolic link from that to the command I want to execute in the chroot, e.g.:
 
 
<pre><nowiki>
 
<pre><nowiki>
ln -s /usr/local/bin/do_chroot /usr/local/bin/firefox
+
  $ sudo apt-get install language-pack-en
 
</nowiki></pre>
 
</nowiki></pre>
which will execute firefox in the chroot environment when I launch it in my normal 64 bit environment. To launch my amd64 firefox I can type /usr/bin/firefox.
 
Instead if you want you can just create a script for launching the 32bit firefox e.g.:
 
 
<pre><nowiki>
 
<pre><nowiki>
#!/bin/bash
+
  $ locale-gen en_US.UTF-8
dchroot -d "firefox"
+
 
</nowiki></pre>
 
</nowiki></pre>
put it in /usr/local/bin and add it to the gnome menu.
+
If your preferred language is not English, then change "-en" and "en_US" appropriately.
If you're going to start a program that only works in 32bit, first type dchroot -d and you'll be in the 32 bit environment.
+
----
=== Notes ===
+
[[category:CategoryDevelopment]]
Some missing points are covered on this external article: http://ornellas.apanela.com/dokuwiki/pub:multiarch.
+
From unknown Sun Apr 17 05:43:14 +0100 2005
+
From:
+
Date: Sun, 17 Apr 2005 05:43:14 +0100
+
Subject: Using symlinks for passwd, groups, shadow, etc..?
+
Message-ID: <20050417054314+0100@https://www.ubuntulinux.org>
+
Wouldn't it be possible to use symlinks for the files that get copied into the chroot?
+
Like /etc/hosts? Would it work with /etc/passwd and the like?
+
From MichaelShigorin Sun Apr 17 13:42:38 +0100 2005
+
From: Michael Shigorin
+
Date: Sun, 17 Apr 2005 13:42:38 +0100
+
Subject: nope
+
Message-ID: <20050417134238+0100@https://www.ubuntulinux.org>
+
...but you can mount --bind them one be one. :)
+
From goofrider Thu May 12 19:26:45 +0100 2005
+
From: goofrider
+
Date: Thu, 12 May 2005 19:26:45 +0100
+
Subject: chroot and symlinks
+
Message-ID: <20050512192645+0100@https://www.ubuntulinux.org>
+
You can't symlinks from inside the chroot to somewhere outside of it, because once you chroot into it, the new chroot will becomes `/`, and all symlinks will be resolved relative to this new `/`. Use `mount --bind` instead (though hard links should work too).  --GoofRider 2005-05-12
+
From Sam Fri May 13 09:22:44 +0100 2005
+
From: Sam
+
Date: Fri, 13 May 2005 09:22:44 +0100
+
Subject: mount -a
+
Message-ID: <[email protected]>
+
You can use
+
$ sudo mount -a
+
for mounting all the entries in fstab instead of mounting them one by one.
+
From LukaszStelmach Sun May 15 00:06:59 +0100 2005
+
From: Lukasz Stelmach
+
Date: Sun, 15 May 2005 00:06:59 +0100
+
Subject: Using symlinks
+
Message-ID: <[email protected]>
+
You can make hardlink to files (but only when your chroot dir is on te same partition):
+
ln /etc/passwd /var/chroot/etc/
+
From: Elmo, 21.12.05
+
Does anyone know howto enable DRI from inside a 32bit chroot, 'cause if I mount --bind /dev/dri chroot/dev/dri I get the following error: "DDX driver parameter mismatch: got 848 bytes, but expected 840 bytes.
+
libGL error: InitDriver failed" (glxinfo)
+
I'd really like to get doom3 working on my amd64 install.
+
26.12.05, Elmo:
+
I know, it should work natively, but I have problems with other games aswell, so getting dri working from a chroot would be great=)
+
26.12.05, Elmo:
+
At debian-amd64 list(http://lists.debian.org/debian-amd64/2005/02/msg00807.html), around February 05, is said that it's not possible at the moment. Got to find another way around my problem, will propably post to ubuntu forums.
+
10.06.06 Just a note from a person who ruined his system: After all this is done do not go and delete things from /var/chroot willy-nilly as it will delete the files from the linked directory as well. I found this out only after my entire /home directory was wiped out when I tried to free up some disk space by deleting the files from the chroot directory. Thanks to my foolishness I emptied root's trash before I realized what I'd done. It's been a while since my last backup so I lost everything from Documents, etc for the last year or so.
+
From: Murray Cumming 06.10.05:
+
I had to do "apt-get install language-pack-en" to avoid the "Locale not supported by C library." warnings. Even "sudo dpkg-reconfigure locales" gave a "perl: warning: Setting locale failed." error until I did this. And that was even after I did a whole "sudo apt-get ubuntu-desktop" in the chroot.
+
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2010年5月19日 (三) 21:59的最新版本


This article demonstrates a quick and easy way to create a chroot environment on an Ubuntu computer, which is like having a virtual system without the overhead of actual virtualization. A chroot can be used for things like:

  • Running a 32-bit Firefox browser or a 32-bit Wine bottle on a 64-bit system.
  • Trying an older or newer Ubuntu release without reinstalling the operating system.
  • Trying a Debian release or other distribution derived from Debian.
  • Cross compiling and building packages for a different platform like Launchpad or Soyuz does it.

Example Configuration

In this example, we use a current Ubuntu 9.04 Jaunty system (the "host") to create a chroot for the older Ubuntu 8.04 Hardy release (the "target"). We are arbitrarily naming the new chroot environment hardy_i386 and putting it in the /srv/chroot directory on the host system.

Step 1: Install packages on the host computer.

First, install `debootstrap`, which is a utility that downloads and unpacks a basic Ubuntu system:

 $ sudo apt-get install debootstrap

Second, install `schroot`, which is a utility that wraps the regular `chroot` program and automatically manages chroot environments:

 $ sudo apt-get install schroot

Note: The `debootstrap` utility is usually backwards compatible with older releases, but it may be incompatible with newer releases. For example, the `debootstrap` that is bundled with Jaunty can prepare a Hardy chroot like we are doing here, but the `debootstrap` that is bundled with Hardy cannot prepare a Jaunty chroot. If you have any difficultly with a `debootstrap` version mismatch, then visit http://packages.ubuntu.com/ to manually download and install the debootstrap package on the host system from the repository for the target release.

Step 2: Create a configuration file for schroot.

Choose a short name for the chroot, we use hardy_i386 in this example, and create a configuration file for it like this:

  sudo editor /etc/schroot/chroot.d/hardy_i386.conf

Put this in the new file:

  [hardy_i386]
  description=Ubuntu 8.04 Hardy for i386
  location=/srv/chroot/hardy_i386
  #personality=linux32
  root-users=bob
  run-setup-scripts=true
  run-exec-scripts=true
  type=directory
  users=alice,bob,charlie

Note: if you copy this example to your clipboard, be careful to start each line in column 1 before you save the new file! If you forget, the command schroot -l will fail with an error, e.g. `E: /etc/schroot/chroot.d/hardy_i386.conf: line 0: Invalid line: “ [hardy_i386]”`. Change these things in the example configuration file to fit your system: . location: This should be a directory that is outside of the /home tree. The latest `schroot` documentation recommends /srv/chroot. . personality: Enable this line if the host system is 64-bit running on an amd64/x64 computer and the chroot is 32-bit for i386. Otherwise, leave it disabled. . users: These are users on the host system that can invoke the `schroot` program and get access to the chroot system. Your username on the host system should be here. . root-users: These are users on the host system that can invoke the `schroot` program and get direct access to the chroot system as the root user. Note: Do not put whitespace around the '=' character, and do not quote strings after the '=' character.

Step 3: Run debootstrap.

This will download and unpack a basic Ubuntu system to the chroot directory, similar to what the host system already has at the real root directory ("/").

 $ sudo mkdir -p /srv/chroot/hardy_i386
 $ sudo debootstrap --variant=buildd --arch i386 hardy /srv/chroot/hardy_i386 http://archive.ubuntu.com/ubuntu/

This command should work for any distribution that is derived from Debian. Substitute the architecture "i386", the release name "hardy", and the repository address "http://archive.ubuntu.com/ubuntu/" appropriately. For example, do this to get the 64-bit build of Hardy instead of the 32-bit build:

  $ sudo debootstrap --arch amd64 hardy /srv/chroot/hardy_amd64/ http://archive.ubuntu.com/ubuntu/

Note: Remember to change all instances of hardy_i386 to hardy_amd64 in the configuration file and on the command line if you actually do this. Do something like this to get an upstream Debian release:

  $ sudo debootstrap --arch amd64 sid /srv/chroot/sid_amd64/ http://ftp.debian.org/debian/

Step 4: Check the chroot

This command lists configured chroots:

  $ schroot -l

If hardy_i386 appears in the list, then run:

  $ schroot -c hardy_i386 -u root

Note: This should work without using `sudo` to invoke the `schroot` program, and it should result in a root prompt in the chroot environment. Check that the root prompt is in a different system:

  # lsb_release -a

For the Hardy system that we just built, the `lsb_release` command should print:

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 8.04
Release:	8.04
Codename:	hardy

We're done!

WARNING

For convenience, the default `schroot` configuration rebinds the /home directory on the host system so that it appears in the chroot system. This could be unexpected if you are familiar with the older `dchroot` program or the regular `chroot` program because it means that you can accidentally delete or otherwise damage things in /home on the host system. To change this behavior run:

  $ sudo editor /etc/schroot/mount-defaults

And disable the /home line so that the file reads:

  # mount.defaults: static file system information for chroots.
  # Note that the mount point will be prefixed by the chroot path
  # (CHROOT_PATH)
  #
  # <file system> <mount point>   <type>  <options>       <dump>  <pass>
  proc            /proc           proc    defaults        0       0
  /dev/pts        /dev/pts        none    rw,bind         0       0
  tmpfs           /dev/shm        tmpfs   defaults        0       0
  #/home           /home           none    rw,bind         0       0
  /tmp            /tmp            none    rw,bind         0       0

The mount.defaults file is the /etc/fstab for chroot environments.

Hints

Install the ubuntu-minimal package in a new chroot after you create it:

  $ schroot -c hardy_i386 -u root
  # apt-get install ubuntu-minimal

If you get locale warnings in the chroot like "Locale not supported by C library." or "perl: warning: Setting locale failed." , then try one or more of these commands:

  $ sudo dpkg-reconfigure locales
  $ sudo apt-get install language-pack-en
  $ locale-gen en_US.UTF-8

If your preferred language is not English, then change "-en" and "en_US" appropriately.