DebootstrapChroot

Differences between revisions 16 and 17
Revision 16 as of 2005-12-25 22:00:28
Size: 5743
Editor: a84-230-91-132
Comment:
Revision 17 as of 2005-12-25 23:05:41
Size: 5998
Editor: a84-230-91-132
Comment:
Deletions are marked like this. Additions are marked like this.
Line 138: Line 138:
26.12.05 26.12.05, Elmo:
Line 140: Line 140:

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

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

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

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

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

 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. Change breezy to according to your needs to warty or hoary, or leave as is for hoary 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
 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.

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

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)