DebootstrapChroot

Differences between revisions 17 and 18
Revision 17 as of 2005-12-25 23:05:41
Size: 5998
Editor: a84-230-91-132
Comment:
Revision 18 as of 2005-12-27 09:53:49
Size: 7271
Editor: 203
Comment: Major reorganization; emphasize distros; use latest dapper debootstrap
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
You can work anywhere - this howto will assume you're using /var/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.
Line 5: Line 5:
If you are running warty and want a hoary chroot you will need to install the debootstrap package from hoary http://higgs.djpig.de/ubuntu/www/hoary/admin/debootstrap You can work anywhere - this Howto will assume you're using {{{/var/chroot}}} .
Line 7: Line 7:
If you are running hoary and want a breezy chroot you will need this debootstrap package or recompile debootstrap from breezy yourself:
http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.1.4ubuntu4_all.deb
== Getting and installing debootstrap ==
Line 10: Line 9:
If you are running breezy and want a dapper chroot you will need the dapper debootstrap package from here:
http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.1.6ubuntu1_all.deb
For the least pain and gnashing of teeth, please get the Ubuntu binary packages ''manually'':

 * http://packages.ubuntu.com/hoary/admin/debootstrap - If you are running ''warty'' and want a ''hoary'' chroot
 * http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.1.4ubuntu4_all.deb - If you are running ''hoary'' and want a ''breezy'' chroot
 * http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu1_all.deb - If you are running ''breezy'' and want a ''dapper'' chroot

Example: {{{wget}}}-ing and installing the latest Dapper debootstrap:
Line 14: Line 18:
 sudo apt-get install dchroot debootstrap
 sudo mkdir /var/chroot
 wget http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu1_all.deb
 sudo dpkg --install debootstrap_0.3.3.0ubuntu1_all.deb
}}}

== Installing and configuring 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 {{{dchroot -c dapper -d}}} ;)

To get it {{{dchroot}}} working in your system, just do:

{{{
 sudo apt-get install dchroot
 sudo mkdir /var/chroot # Remember, we assume our chroot is here
Line 18: Line 33:
Append this line
Then a
ppend this line
Line 23: Line 39:
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 or hoary, or leave as is for hoary chroot.
in {{{/etc/dchroot.conf}}} .

== Setting up your 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.
Line 36: Line 57:
 tzconfig # Configure and use our local time instead of UTC
Line 39: Line 61:
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. 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 ;)
Line 41: Line 63:
Fix the user and root password == Setting up a dchroot (non-root) environment ==

Fix the user and root password:
Line 48: Line 73:
To enable sudo and setup your passwords for root and the first sudo user in the `admin` group:
E
nable sudo and setup your passwords for root and the first sudo user in the `admin` group:
Line 55: Line 82:
Next, we have to install sudo package to be able to use it being in chroot:
Next, we have to install {{{sudo}}} package to be able to use it being in chroot:
Line 62: Line 91:
Line 65: Line 95:
Line 66: Line 97:
Line 73: Line 105:
Line 74: Line 107:
Line 77: Line 111:
Line 78: Line 113:
Line 83: Line 119:
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.
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.
Line 87: Line 125:

== Notes ==

DebootstrapChroot

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 Wink ;) 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 /var/chroot .

Getting and installing debootstrap

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

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

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

Installing and configuring 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 dchroot -c dapper -d Wink ;)

To get it dchroot working in your system, just do:

 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

 mychroot /var/chroot

in /etc/dchroot.conf .

Setting up your 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.

 sudo debootstrap [--variant=buildd] [--arch i386] breezy /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 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 Wink ;)

Setting up a dchroot (non-root) environment

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

Enable sudo and setup your passwords for root and the first sudo user in the admin group:

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

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

 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)

 /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 -a

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

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.

 dchroot -c mychroot -d

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

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: <20050513092244+0100@www.ubuntulinux.org>

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: <20050515000659+0100@www.ubuntulinux.org>

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.

DebootstrapChroot (last edited 2013-10-21 17:41:47 by mail)