个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{From|https://help.ubuntu.com/community/DebootstrapChroot}} {{Languages|UbuntuHelp:DebootstrapChroot}} == DebootstrapChroot == This article shows you how...)
 
 
第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]] ==
+
== [[UbuntuHelp:DebootstrapChroot|使用  Debootstrap 构建 Chroot 环境]] ==
 +
 
 
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.
 
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.
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]].
+
 
=== Getting and installing debootstrap ===
+
这是一篇向您展示如何使用 [http://packages.ubuntu.com/debootstrap debootstrap] 来构建一个 ''chroot 环境'',您可以用它来尝试最新(甚至最老)的 Ubuntu 版本 ,可以用它来运行 [http://www.debian.org Debian] 版本,甚至还可以用它来做为创建软件包的环境。
 +
 
 +
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 BreezyBadger chroot; if you are going to use other Ubuntu releases, replace ''breezy'' below with ''warty'' for WartyWarthog, ''hoary'' for HoaryHedgehog, or ''dapper'' for DapperDrake.
 +
 
 +
您可以在任何目录下运行-本指南假定你使用的是<code><nowiki>/var/chroot</nowiki></code> ,同时它还将指定您想安装的是 BreezyBadger chroot 环境;如果您打算使用 别的 Ubuntu 版本 ,请将''breezy'' 替换成''warty'' 用于安装  WartyWarthog、替换成 ''hoary'' 用于安装 HoaryHedgehog或者替换成 ''dapper'' 用于安装 DapperDrake.
 +
 
 +
=== Getting and installing debootstrap 获得并安装 DebootStrap ===
 +
 
 +
 
 
For the least pain and gnashing of teeth, please get the Ubuntu binary packages ''manually'':
 
For the least pain and gnashing of teeth, please get the Ubuntu binary packages ''manually'':
 +
 
* http://packages.ubuntu.com/hoary/admin/debootstrap - If you want a ''hoary'' chroot
 
* http://packages.ubuntu.com/hoary/admin/debootstrap - If you want a ''hoary'' chroot
 
* http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.1.4ubuntu4_all.deb - If you want a ''breezy'' chroot
 
* http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.1.4ubuntu4_all.deb - If you want a ''breezy'' chroot
* http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu5~dapper1_all.deb - If you want a ''dapper'' chroot
+
* http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu2_all.deb - If you want a ''dapper'' chroot
* http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu7_all.deb - If you want a ''edgy'' chroot
+
 
* 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)
+
Example: Terminal session <code><nowiki>wget</nowiki></code>-ing and installing the latest Dapper debootstrap:
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
+
wget http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu2_all.deb
sudo dpkg --install debootstrap_0.3.3.2ubuntu3_all.deb
+
sudo dpkg --install debootstrap_0.3.3.0ubuntu2_all.deb
 
</nowiki></pre>
 
</nowiki></pre>
=== Installing and configuring dchroot ===
+
 
 +
=== Installing and configuring dchroot 安装配置 Dchroot ===
 +
 
 
[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> ;)
 
[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:
 
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 dchroot
sudo mkdir /var/chroot # Remember, we assume our chroot is here
+
sudo mkdir /var/chroot # Remember, we assume our chroot is here
sudo editor /etc/dchroot.conf
+
sudo editor /etc/dchroot.conf
 
</nowiki></pre>
 
</nowiki></pre>
 +
 
Then append this line in <code><nowiki>/etc/dchroot.conf</nowiki></code>:
 
Then append this line in <code><nowiki>/etc/dchroot.conf</nowiki></code>:
 +
 
<pre><nowiki>
 
<pre><nowiki>
mychroot /var/chroot
+
mychroot /var/chroot
 
</nowiki></pre>
 
</nowiki></pre>
=== Setting up your chroot with debootstrap ===
+
 
 +
=== Setting up your chroot with debootstrap 使用 DebootStrap 来设置您的 Chroot ===
 +
 
 
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.
 
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.
 +
 +
如果您想在 AMD64上模拟 32 位的 Chroot 环境的话,添加 <code><nowiki>--arch i386</nowiki></code>  参数。如果您使用 chroot 环境编译该包的话,添加 <code><nowiki>--variant=buildd</nowiki></code> 参数。将''breezy''按您的需要替换成 ''warty''、''hoary'' 或 ''dapper'',或保留它以创建  ''breezy'' chroot 环境。
 +
 
To actually install the base chroot, open a Terminal and do:
 
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/
+
sudo debootstrap --variant=buildd --arch i386 breezy /var/chroot/ http://archive.ubuntu.com/ubuntu/
 
</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.
+
 
 +
<code><nowiki>debootstrap</nowiki></code> will then build a 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.
 +
 
 
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 interesting.  To 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>:
 
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 interesting.  To 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>:
 +
 
<pre><nowiki>
 
<pre><nowiki>
sudo cp /etc/resolv.conf /var/chroot/etc/resolv.conf
+
sudo cp /etc/resolv.conf /var/chroot/etc/resolv.conf
sudo cp /etc/apt/sources.list /var/chroot/etc/apt/
+
sudo cp /etc/apt/sources.list /var/chroot/etc/apt/
sudo sed -i s/dapper/breezy/g /var/chroot/etc/apt/sources.list #point apt-get to the right release
+
sudo sed -i s/dapper/breezy/g /var/chroot/etc/apt/sources.list #point apt-get to the right release
sudo chroot /var/chroot/
+
sudo chroot /var/chroot/
mount /proc
+
apt-get update
apt-get update
+
apt-get install wget debconf devscripts gnupg  #For package-building
apt-get install wget debconf devscripts gnupg nano #For package-building
+
apt-get update  #clean the gpg error message
apt-get update  #clean the gpg error message
+
apt-get install locales dialog  #If you don't talk en_US  
apt-get install locales dialog  #If you don't talk en_US  
+
dpkg-reconfigure locales
locale-gen en_GB.UTF-8  # or your preferred locale
+
tzconfig #Configure and use our local time instead of UTC
tzselect; TZ='Continent/Country'; export TZ #Configure and use our local time instead of UTC; save in .profile
+
exit
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 ;)
 
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 ;)
 +
 
If you want to build a Debian chroot on an Ubuntu system you need to point it at a Debian archive:
 
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 i386 sid sid/ http://ftp.uk.debian.org/debian/
 
</nowiki></pre>
 
</nowiki></pre>
 +
 
=== Setting up a dchroot (non-root) environment ===
 
=== Setting up a dchroot (non-root) environment ===
<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.
+
 
 +
<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.
 +
 
 +
即使普通用户也可以用dchroot来使用新建立的chroot环境。你甚至可以把你现在的/home目录设为chroot里的/home目录,令home目录间的转换、以及创建与测试软件包更加便利。
 +
 
 
To do this, first fix the user and root password:
 
To do this, first fix the user and root password:
<pre><nowiki>
+
 
sudo cp /etc/passwd /var/chroot/etc/
+
修改用户和根用户密码
sudo sed 's/\([^:]*\):[^:]*:/\1:*:/' /etc/shadow | sudo tee /var/chroot/etc/shadow
+
<pre>sudo cp /etc/passwd /var/chroot/etc/
sudo cp /etc/group /var/chroot/etc/
+
sudo sed 's/\([&lt;sup&gt;:]*\):[&lt;/sup&gt;:]*:/\1:*:/' /etc/shadow | sudo tee /var/chroot/etc/shadow
sudo cp /etc/hosts /var/chroot/etc/ # avoid sudo warnings when it tries to resolve the chroot's hostname
+
sudo cp /etc/group /var/chroot/etc/
</nowiki></pre>
+
sudo cp /etc/hosts /var/chroot/etc/ # avoid sudo warnings when it tries to resolve the chroot's hostname
 +
</pre>  
 
Then enable sudo and setup your passwords for root and the first sudo user in the `admin` group:
 
Then enable sudo and setup your passwords for root and the first sudo user in the `admin` group:
<pre><nowiki>
+
 
sudo cp /etc/sudoers /var/chroot/etc/
+
为了能sudo和在admin组中第一个sudo用户和根用户设置密码
sudo chroot /var/chroot/
+
<pre>sudo cp /etc/sudoers /var/chroot/etc/
dpkg-reconfigure passwd
+
sudo chroot /var/chroot/
passwd <your first ubuntu user in the admin group>
+
dpkg-reconfigure passwd
</nowiki></pre>
+
passwd &lt;your first ubuntu user in the admin group&gt;
 +
</pre>  
 
Next, install the [http://packages.ubuntu.com/sudo sudo] package to be able to use it being in chroot:
 
Next, install the [http://packages.ubuntu.com/sudo sudo] package to be able to use it being in chroot:
<pre><nowiki>
+
 
apt-get install sudo
+
FIXME 翻译以上部分
exit
+
<pre>apt-get install sudo
</nowiki></pre>
+
exit
 +
</pre>  
 
Finish things up:
 
Finish things up:
<pre><nowiki>
+
 
sudo editor /etc/fstab
+
最后:
</nowiki></pre>
+
<pre>sudo editor /etc/fstab
 +
</pre>  
 
Add these lines: (/media/cdrom is optional, of course, and you might have to create the dir in the chroot)
 
Add these lines: (/media/cdrom is optional, of course, and you might have to create the dir in the chroot)
<pre><nowiki>
+
 
/home           /var/chroot/home       none   bind           0       0
+
添加下列行:(/media/cdrom当然是可选项) FIXME 补完此处的翻译
/tmp           /var/chroot/tmp         none   bind           0       0
+
<pre>/home /var/chroot/home none bind 0 0
/media/cdrom   /var/chroot/media/cdrom none   bind           0       0
+
/tmp /var/chroot/tmp none bind 0 0
/dev           /var/chroot/dev         none   bind           0       0  
+
/media/cdrom /var/chroot/media/cdrom none bind 0 0
proc-chroot     /var/chroot/proc       proc   defaults       0       0
+
/dev /var/chroot/dev none bind 0 0  
devpts-chroot   /var/chroot/dev/pts     devpts defaults       0       0
+
proc-chroot /var/chroot/proc proc defaults 0 0
</nowiki></pre>
+
devpts-chroot /var/chroot/dev/pts devpts defaults 0 0
 +
</pre>  
 
Mount them:
 
Mount them:
<pre><nowiki>
+
 
sudo mount -a
+
挂载它们:
</nowiki></pre>
+
<pre>sudo mount -a
The default bash path includes chroot information. To make this visible:
+
</pre>  
<pre><nowiki>
+
The default bash path includes chroot information. To make this visible:
sudo chroot /var/chroot/
+
 
echo mychroot > etc/debian_chroot
+
缺省Bash目录包含了Chroot信息,为了使之可见:
 +
<pre>sudo chroot /var/chroot/
 +
echo mychroot &gt; etc/debian_chroot
 
exit
 
exit
</nowiki></pre>
+
</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.
 
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.
<pre><nowiki>
+
 
dchroot -c mychroot -d
+
现在当你想使用你的Chroot环境时(你可以忽略-c mychroot参数,如果你只有一个或只想使用文件中的第一个时)。-d参数意味着你的环境将被保留,当你想你的Chroot环境中的应用程序想无缝地使用你的X服务器、会话管理器时,这通常是有用的。
</nowiki></pre>
+
<pre>dchroot -c mychroot -d
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!
+
</pre>  
 +
FIXME 翻译以下部分
 +
 
 +
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!
 +
 
 +
<br>
 +
 
 
==== Shortcuts / Usage ====
 
==== Shortcuts / Usage ====
 +
 
you can type dchroot -d "command" and it executes that command in the chroot.
 
you can type dchroot -d "command" and it executes that command in the chroot.
 +
 
I have this script do_chroot in /usr/local/bin:
 
I have this script do_chroot in /usr/local/bin:
<pre><nowiki>
+
<pre>#!/bin/sh
#!/bin/sh
+
 
/usr/bin/dchroot -d "`echo $0 | sed 's|^.*/||'` $*"
 
/usr/bin/dchroot -d "`echo $0 | sed 's|^.*/||'` $*"
</nowiki></pre>
+
</pre>  
''I had trouble with quoting in the above script.  This one works better for me. ~JPKotta''
+
<pre><nowiki>
+
args=""
+
for i in "$@" ; do
+
    args="$args '$i'"
+
done
+
 
+
/usr/bin/dchroot -d -- "$0" "$args"
+
</nowiki></pre>
+
 
Then I create a symbolic link from that to the command I want to execute in the chroot, e.g.:
 
Then I create a symbolic link from that to the command I want to execute in the chroot, e.g.:
<pre><nowiki>
+
<pre>ln -s /usr/local/bin/do_chroot /usr/local/bin/firefox
ln -s /usr/local/bin/do_chroot /usr/local/bin/firefox
+
</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.
 
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.:
 
Instead if you want you can just create a script for launching the 32bit firefox e.g.:
<pre><nowiki>
+
<pre>#!/bin/bash
#!/bin/bash
+
 
dchroot -d "firefox"
 
dchroot -d "firefox"
</nowiki></pre>
+
</pre>  
 
put it in /usr/local/bin and add it to the gnome menu.
 
put it in /usr/local/bin and add it to the gnome menu.
 +
 
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.
 
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 ===
 
=== Notes ===
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 unknown Sun Apr 17 05:43:14 +0100 2005
 
From:  
 
From:  
第139行: 第178行:
 
Subject: Using symlinks for passwd, groups, shadow, etc..?
 
Subject: Using symlinks for passwd, groups, shadow, etc..?
 
Message-ID: <20050417054314+0100@https://www.ubuntulinux.org>
 
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?
 
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?
 
Like /etc/hosts? Would it work with /etc/passwd and the like?
 +
 
From MichaelShigorin Sun Apr 17 13:42:38 +0100 2005
 
From MichaelShigorin Sun Apr 17 13:42:38 +0100 2005
 
From: Michael Shigorin
 
From: Michael Shigorin
第146行: 第187行:
 
Subject: nope
 
Subject: nope
 
Message-ID: <20050417134238+0100@https://www.ubuntulinux.org>
 
Message-ID: <20050417134238+0100@https://www.ubuntulinux.org>
 +
 
...but you can mount --bind them one be one. :)
 
...but you can mount --bind them one be one. :)
 +
 
From goofrider Thu May 12 19:26:45 +0100 2005
 
From goofrider Thu May 12 19:26:45 +0100 2005
 
From: goofrider
 
From: goofrider
第152行: 第195行:
 
Subject: chroot and symlinks
 
Subject: chroot and symlinks
 
Message-ID: <20050512192645+0100@https://www.ubuntulinux.org>
 
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
 
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 Fri May 13 09:22:44 +0100 2005
 
From: Sam
 
From: Sam
第158行: 第203行:
 
Subject: mount -a
 
Subject: mount -a
 
Message-ID: <[email protected]>
 
Message-ID: <[email protected]>
 +
 
You can use
 
You can use
 
$ sudo mount -a
 
$ sudo mount -a
 
for mounting all the entries in fstab instead of mounting them one by one.
 
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 LukaszStelmach Sun May 15 00:06:59 +0100 2005
 
From: Lukasz Stelmach
 
From: Lukasz Stelmach
第166行: 第213行:
 
Subject: Using symlinks
 
Subject: Using symlinks
 
Message-ID: <[email protected]>
 
Message-ID: <[email protected]>
 +
 
You can make hardlink to files (but only when your chroot dir is on te same partition):
 
You can make hardlink to files (but only when your chroot dir is on te same partition):
 +
 
ln /etc/passwd /var/chroot/etc/
 
ln /etc/passwd /var/chroot/etc/
 +
 
From: Elmo, 21.12.05
 
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.
 
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)
 
libGL error: InitDriver failed" (glxinfo)
 
I'd really like to get doom3 working on my amd64 install.
 
I'd really like to get doom3 working on my amd64 install.
 +
 
26.12.05, Elmo:
 
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=)
 
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:
 
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.
 
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.
 
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]]

2013年4月14日 (日) 00:40的最新版本

使用 Debootstrap 构建 Chroot 环境

This article shows you how to use 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 Debian releases, to utilizing the chroot as a package building environment.

这是一篇向您展示如何使用 debootstrap 来构建一个 chroot 环境,您可以用它来尝试最新(甚至最老)的 Ubuntu 版本 ,可以用它来运行 Debian 版本,甚至还可以用它来做为创建软件包的环境。

You can work anywhere - this Howto will assume you're using /var/chroot . It will also assume that you want to install a BreezyBadger chroot; if you are going to use other Ubuntu releases, replace breezy below with warty for WartyWarthog, hoary for HoaryHedgehog, or dapper for DapperDrake.

您可以在任何目录下运行-本指南假定你使用的是/var/chroot ,同时它还将指定您想安装的是 BreezyBadger chroot 环境;如果您打算使用 别的 Ubuntu 版本 ,请将breezy 替换成warty 用于安装 WartyWarthog、替换成 hoary 用于安装 HoaryHedgehog或者替换成 dapper 用于安装 DapperDrake.

Getting and installing debootstrap 获得并安装 DebootStrap

For the least pain and gnashing of teeth, please get the Ubuntu binary packages manually:

Example: Terminal session wget-ing and installing the latest Dapper debootstrap:

wget http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu2_all.deb
sudo dpkg --install debootstrap_0.3.3.0ubuntu2_all.deb

Installing and configuring dchroot 安装配置 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 dchroot -c dapper -d ;)

To get it dchroot working in your system, just do the following in a Terminal:

sudo apt-get install dchroot
sudo mkdir /var/chroot # Remember, we assume our chroot is here
sudo editor /etc/dchroot.conf

Then append this line in /etc/dchroot.conf:

mychroot /var/chroot

Setting up your chroot with debootstrap 使用 DebootStrap 来设置您的 Chroot

If you want a 32-bit chroot on amd64 add --arch i386 to this command line. If you use the chroot to build packages add --variant=buildd . Change breezy to according to your needs to warty, hoary, or dapper, or leave as is for breezy chroot.

如果您想在 AMD64上模拟 32 位的 Chroot 环境的话,添加 --arch i386 参数。如果您使用 chroot 环境编译该包的话,添加 --variant=buildd 参数。将breezy按您的需要替换成 wartyhoarydapper,或保留它以创建 breezy chroot 环境。

To actually install the base chroot, open a Terminal and do:

sudo debootstrap --variant=buildd --arch i386 breezy /var/chroot/ http://archive.ubuntu.com/ubuntu/

debootstrap will then build a BreezyBadger chroot in /var/chroot/, getting the base packages in http://archive.ubuntu.com/ubuntu/, and, depending on the given additional options (in square brackets,) debootstrap will build a chroot for the given architecture and variant.

If debootstrap finishes successfully, you'll be left with a base chroot in /var/chroot, which is, well, hardly suitable for anything very interesting. To actually get our chroot to work and be able to, say, grab packages from the network, do the following right after debootstrap:

sudo cp /etc/resolv.conf /var/chroot/etc/resolv.conf
sudo cp /etc/apt/sources.list /var/chroot/etc/apt/
sudo sed -i s/dapper/breezy/g /var/chroot/etc/apt/sources.list #point apt-get to the right release
sudo chroot /var/chroot/
apt-get update
apt-get install wget debconf devscripts gnupg  #For package-building
apt-get update  #clean the gpg error message
apt-get install locales dialog  #If you don't talk en_US 
dpkg-reconfigure locales
tzconfig  #Configure and use our local time instead of UTC
exit

You can stop here if you want and have a simple chroot that you use as root (sudo chroot /var/chroot). If you want to use your chroot as another user and have access to your normal /home etc inside the chroot, carry on ;)

If you want to build a Debian chroot on an Ubuntu system you need to point it at a Debian archive:

sudo debootstrap --arch i386 sid sid/ http://ftp.uk.debian.org/debian/

Setting up a dchroot (non-root) environment

dchroot 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 /home as the chroot's /home, thereby saving you some expensive moving in between homes, as well as making package building/testing a LOT more convenient.

即使普通用户也可以用dchroot来使用新建立的chroot环境。你甚至可以把你现在的/home目录设为chroot里的/home目录,令home目录间的转换、以及创建与测试软件包更加便利。

To do this, first fix the user and root password:

修改用户和根用户密码

sudo cp /etc/passwd /var/chroot/etc/
sudo sed 's/\([<sup>:]*\):[</sup>:]*:/\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

Then enable sudo and setup your passwords for root and the first sudo user in the `admin` group:

为了能sudo和在admin组中第一个sudo用户和根用户设置密码

sudo cp /etc/sudoers /var/chroot/etc/
sudo chroot /var/chroot/
dpkg-reconfigure passwd
passwd <your first ubuntu user in the admin group>

Next, install the sudo package to be able to use it being in chroot:

FIXME 翻译以上部分

apt-get install sudo
exit

Finish things up:

最后:

sudo editor /etc/fstab

Add these lines: (/media/cdrom is optional, of course, and you might have to create the dir in the chroot)

添加下列行:(/media/cdrom当然是可选项) FIXME 补完此处的翻译

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

Mount them:

挂载它们:

sudo mount -a

The default bash path includes chroot information. To make this visible:

缺省Bash目录包含了Chroot信息,为了使之可见:

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

Now when you want to use your chroot (you may omit the -c mychroot if there's only one, or you just want the first one in the file). The -d 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.

现在当你想使用你的Chroot环境时(你可以忽略-c mychroot参数,如果你只有一个或只想使用文件中的第一个时)。-d参数意味着你的环境将被保留,当你想你的Chroot环境中的应用程序想无缝地使用你的X服务器、会话管理器时,这通常是有用的。

dchroot -c mychroot -d

FIXME 翻译以下部分

Tada! Now you can switch to and from your main / and /var/chroot/, without even becoming root!


Shortcuts / Usage

you can type dchroot -d "command" and it executes that command in the chroot.

I have this script do_chroot in /usr/local/bin:

#!/bin/sh
/usr/bin/dchroot -d "`echo $0 | sed 's|^.*/||'` $*"

Then I create a symbolic link from that to the command I want to execute in the chroot, e.g.:

ln -s /usr/local/bin/do_chroot /usr/local/bin/firefox

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.:

#!/bin/bash
dchroot -d "firefox"

put it in /usr/local/bin and add it to the gnome menu.

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

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.