Table of Contents

Debian Unstable inside a Chroot (LEGACY!)

Before you start!

WARNING: We do not recommend following this tutorial. This tutorial exists for historical purposes. What you probably want is to use a Container instead of creating a chroot.

The tutorial

sudo apt-get install dchroot debootstrap
sudo su
mkdir -p /var/sid-amd64-chroot
debootstrap --arch amd64 sid /var/sid-amd64-chroot http://ftp.us.debian.org/debian/
exit
#!/bin/bash
CHROOT_DIR=/var
CHROOT_NAME=`basename $0 .sh` 

if [ ! -e /var/run/$CHROOT_NAME ]
then
    sudo touch /var/run/$CHROOT_NAME
    sudo bash -c "echo 1 > /var/run/$CHROOT_NAME"
else
    sudo bash -c "echo `expr 1 + \`cat /var/run/$CHROOT_NAME\`` > /var/run/$CHROOT_NAME"
fi

if [ `cat /var/run/$CHROOT_NAME` -eq 1 ]
then
    echo "First chroot invocation. Mounting host system directories"
    sudo mkdir -p $CHROOT_DIR/$CHROOT_NAME/hostfs
    #mount -o bind /home/ $CHROOT_DIR/$CHROOT_NAME/home
    sudo mount proc -t proc $CHROOT_DIR/$CHROOT_NAME/proc
    sudo mount -o bind /dev $CHROOT_DIR/$CHROOT_NAME/dev
    sudo mount sys -t sysfs $CHROOT_DIR/$CHROOT_NAME/sys
    sudo mount none -t devpts $CHROOT_DIR/$CHROOT_NAME/dev/pts
    sudo mount -o bind / $CHROOT_DIR/$CHROOT_NAME/hostfs
    sudo mount -o bind /run/shm $CHROOT_DIR/$CHROOT_NAME/run/shm
fi

echo "Starting chroot."
#dchroot -c $CHROOT_NAME
sudo chroot $CHROOT_DIR/$CHROOT_NAME su - $USER
echo "Chroot closed."

if [ `cat /var/run/$CHROOT_NAME` -eq 1 ]
then
    echo "Closing last invocation. Unmounting host system directories"
    for i in dev/pts hostfs proc dev sys run/shm
    do
  sudo umount $CHROOT_DIR/$CHROOT_NAME/$i
        sleep 0.5
    done
fi

sudo bash -c "echo `expr \`cat /var/run/$CHROOT_NAME\` - 1` > /var/run/$CHROOT_NAME"

if [ `cat /var/run/$CHROOT_NAME` -eq 0 ]
then
    sudo rm /var/run/$CHROOT_NAME
fi
[sid-amd64-chroot]
description=Debian sid (unstable)
directory=/var/sid-amd64-chroot
users=memeruiz
#groups=sbuild                                                                  
root-groups=root
aliases=unstable,default   
preserve-environment=true

Now you are done. With:

sid-amd64-chroot.sh

You will get your chroot running. (this will not work because you don't have your same user in chroot yet, look down)

Some things to do initially

sudo sid-amd64-chroot.sh
adduser username
apt-get install emacs joe mc locales sudo bash-completion less python
deb http://snapshot.debian.org/archive/debian/20130225T093150Z sid main contrib non-free
deb http://snapshot.debian.org/archive/debian/20130225T093150Z testing main contrib non-free
deb http://snapshot.debian.org/archive/debian/20130225T093150Z unstable main contrib non-free
deb http://snapshot.debian.org/archive/debian/20130225T093150Z experimental main contrib non-free
sudo sid-amd64-chroot.sh
apt-get install locales
dpkg-reconfigure locales
HISTSIZE=1000000
HISTFILESIZE=2000000

Some notes

Using fstab instead of the script

# sid-amd64 chroot
#/home           /var/sid-amd64-chroot/home none   bind            0       0
none           /var/sid-amd64-chroot/proc proc   defaults        0       0
/dev            /var/sid-amd64-chroot/dev  none   bind            0       0
none            /var/sid-amd64-chroot/sys  sysfs   defaults            0       0
none            /var/sid-amd64-chroot/dev/pts  devpts   defaults            0       0
sudo mount -a

Using the same users and home directory of the host computer

  1. Remember that this may not be what you really need…
  2. If you erase something in chroot home it gets erased in the host computer also.
  3. If you have different versions of the same programs in the chroot and the host computer, the local home configurations may not work properly or could get corrupted.

W: Failed to change to directory ....

This happens because the chroot doesn't have any users initially (unless you followed the instructions to use the users from the host computer), only root You can fix this problem by first logging as root in the chroot and then adding a user with the same name and id of your user in the host computer.

sudo sid-amd64-chroot.sh
adduser --uid <user number in host computer> <username of host computer>

Then you can logging with no errors.

If you are using some snapshots.debian.org mirrors

When you do apt-get update you may get an error like this:

E: Release file for http://snapshot.debian.org/archive/debian/20130225T093150Z/dists/sid/InRelease is expired (invalid since 3d 17h 44min 46s). Updates for this repository will not be applied.

You can still update the the mirror if you use this command instead:

apt-get -o Acquire::Check-Valid-Until=false update

chroot and unionfs: Base installation and multiple setups

You can do a base installation and setup to chroot directory: /chroot/base and then unionfs mount this directory to other directories using cow (copy on write), to create specific application chroots. You may save disk space by not replicating the base system several times, and time by not having to install and configure multiple times.

unionfs-fuse -o cow  -o default_permissions -o use_ino -o suid -o noinitgroups -o allow_other -o nonempty /chroot/base=RO:/chroot/specific_chroot.union=RW /chroot/specific_chroot

~~DISCUSSION~~