DebootstrapChroot

You can work anywhere - this howto will assume you're using /var/chroot

你可以在任何地方工作-本指南假定你使用的是/var/chroot

If you are running warty and want a hoary chroot you will need to install the debootstrap package from hoary [WWW] http://higgs.djpig.de/ubuntu/www/hoary/admin/debootstrap

如果你使用的是Warty并需要一个HoaryChroot环境的话,可以从http://higgs.djpig.de/ubuntu/www/hoary/admin/debootstrap中安装HoaryDebootstrap包。

If you are running hoary and want a breezy chroot you will need this debootstrap package or recompile debootstrap from breezy yourself: [WWW] http://dev.kubuntu.org.uk/~jr/debootstrap_0.2.45ubuntu36_i386.deb [WWW] http://dev.kubuntu.org.uk/~jr/debootstrap_0.2.45ubuntu35_amd64.deb

如果你使用的是Hoary而需要一个BreezyChroot环境的话,可以安装下面的Debootstrap包或重新编译下面BreezyDebootstrap包:[url] http://dev.kubuntu.org.uk/~jr/debootstrap_0.2.45ubuntu36_i386.deb [/url][url] http://dev.kubuntu.org.uk/~jr/debootstrap_0.2.45ubuntu35_amd64.deb[/url]

代码:

 sudo apt-get install dchroot debootstrap

 sudo mkdir /var/chroot

 sudo editor /etc/dchroot.conf

Append this line

添加该行

代码:

 mychroot /var/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

如果你想在amd64上模拟32-bitChroot环境的话,添加--arch i386参数。如果你使用chroot环境编译该包的话,添加--variant=buildd参数

代码:

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

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

 sudo cp /etc/apt/sources.list /var/chroot/etc/apt/

 sudo chroot /var/chroot/

 apt-get update

 apt-get install wget debconf devscripts gnupg  #For package-building

 apt-get install locales dialog  #If you don't talk en_US

 dpkg-reconfigure locales

 exit

Fix the user and root password

修改用户和根用户密码

代码:

 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/ # avoid sudo warnings when it will resolvin chroot

To 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>

 exit

Finish things up:

最后:

代码:

 sudo editor /etc/fstab

Add these lines: (/media/cdrom is optional, of course)

添加下列行:(/media/cdrom当然是可选项)

代码:

 /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

 proc-chroot     /var/chroot/proc        proc    defaults        0       0

 devpts-chroot   /var/chroot/dev/pts     devpts  defaults        0       0

Mount them:

挂载它们:

代码:

sudo mount /var/chroot/home

sudo mount /var/chroot/tmp

sudo mount /var/chroot/media/cdrom

sudo mount /var/chroot/proc

sudo mount /var/chroot/dev/pts

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