A chroot environment is commonly used for development-related work and is basically an install of build-related software. It is always a good idea to do development work in a chroot environment, as it often requires the installation of development packages (whose main purpose is for building packages). An example is when a certain application requires the headers and development version of a library to build (e.g. libabc-dev). A normal user would not require the development version of libabc. Thus it is better to install such development packages in a chroot, leaving the normal operating environment clean and uncluttered. First, install the required packages:


sudo apt-get install dchroot debootstrap
  • attachment:UbuntuPackagingGuideJa/conventions/important.png Make sure to install at least the version of debootstrap that is from the Ubuntu release for which you are trying to create the chroot. You may have to download it from packages.ubuntu.com and manually install it with dpkg -i.

  • attachment:UbuntuPackagingGuideJa/conventions/important.png debootstrapは、作成しようとしているリリースのchroot環境になるよう、最新のバージョンを取得し、インストールするようにしてください。packages.ubuntu.comからパッケージをダウンロードし、dpkg -iを使って手動でインストールすると良いでしょう。

The next steps are to create, configure, and enter the chroot environment.


sudo mkdir /var/chroot
echo "mychroot /var/chroot" | sudo tee -a /etc/dchroot.conf
sudo debootstrap --variant=buildd edgy /var/chroot/ http://archive.ubuntu.com/ubuntu/
  • attachment:UbuntuPackagingGuideJa/conventions/note.png Creating a chroot environment will take some time as debootstrap downloads and configures a minimal Ubuntu installation.

  • attachment:UbuntuPackagingGuideJa/conventions/note.png debootstrapがUbuntuの最小環境をダウンロードし設定を行うために、chroot環境の作成が完了するまでにしばらく時間がかかるかもしれません。

sudo cp /etc/resolv.conf /var/chroot/etc/resolv.conf
sudo chroot /var/chroot/ /bin/bash

In order to be able to use apt in the chroot, add Ubuntu sources to the chroot's apt sources. For the moment, ignore any warnings about package authentication:


echo "deb     http://archive.ubuntu.com/ubuntu edgy main restricted \
        universe multiverse" > /etc/apt/sources.list
echo "deb-src http://archive.ubuntu.com/ubuntu edgy main restricted \
        universe multiverse" >> /etc/apt/sources.list
apt-get update
apt-get install build-essential dh-make automake pbuilder gnupg lintian \
        wget debconf devscripts gnupg sudo

Run the following command to configure locales:


apt-get update
apt-get install dialog language-pack-en
  • attachment:UbuntuPackagingGuideJa/conventions/note.png If you want support for a language other than English replace en in language-pack-en with the appropriate language code.

  • attachment:UbuntuPackagingGuideJa/conventions/note.png 英語以外の言語サポートが欲しい場合は、language-pack-enenの部分を、適切な言語コードに変えてください。

Next, fix the user and root passwords for the chroot environment. The last line below is to avoid sudo warnings when resolving in the chroot environment:


sudo cp /etc/passwd /var/chroot/etc/
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/

To enable sudo, set up your root password and the first sudo user in the admin group (for the chroot environment). In the following commands, substitute "<user>" with the username that will be used in the chroot environment:


sudo cp /etc/sudoers /var/chroot/etc/
sudo chroot /var/chroot/
dpkg-reconfigure passwd
passwd <user>

The system fstab needs to be modified so that the chroot environment will have access to the system home directories, temp directory, etc. Note that the actual system home directory is used in the chroot environment.


sudo editor /etc/fstab

Add these lines:


/home           /var/chroot/home        none    bind            0       0
/tmp            /var/chroot/tmp         none    bind            0       0 
proc-chroot     /var/chroot/proc        proc    defaults        0       0 
devpts-chroot   /var/chroot/dev/pts     devpts  defaults        0       0 

Mount the new fstab entries


sudo mount -a

The default bash profile includes chroot information in the prompt. To make this visible:


sudo chroot /var/chroot/
echo mychroot > /etc/debian_chroot

Now use your chroot (you may omit the -c mychroot if there's only one or you just want the first one in /etc/dchroot.conf). The -d parameter means that your environment will be preserved. This parameter is generally useful if you want chrooted applications to seamlessly use your X server, your session manager, etc.

では、chrootを利用します(もしchroot環境が一つしかなかったり、/etc/dchroot.confで一番最初に書かれている環境を利用したい場合は、-c mychrootを省いても良いでしょう)。-d パラメータはその環境が保護されることを意味します。Xサーバやセッションマネージャで、chroot環境のアプリケーションをシームレスに使いたい場合に便利でしょう。

dchroot -c mychroot -d

UbuntuJapaneseWiki: UbuntuPackagingGuideJa/appendix-chroot (最終更新日時 2012-01-10 11:49:23 更新者 匿名)