Hi friends, today i'll tell you how to setup a chroot environment.


First of all:

What is chroot?

A chroot on UNIX OS is an operation that changes the apparent distribution root directory for the current running process and its children. A program that is re-rooted to another directory cannot access or name files outside that directory and the directory is called “chroot jail”. (this might seem a bit confusing first, just carry on and when u'll enter the chroot, you'll understand everything :) ).


Why is this environment useful?

This is evironment provides very good base for performing experiments you want to do with linux kernel. All the fiddling you want to do at the terminal and scared of loosing or modifying some important files, you can do here.

Chroot Jail signifies that you are jailing you root into a particular directory and all the operations, installations and experimentations will stay into that root folder only. You can use any empty directory on a native linux file system. No operation perform inside the chroot can access or modify any file outside that directory.


I'll tell you how to setup roots for debian environments.


For that we will use a tool called debootstrap. You can install this tool from the repository by the following command:


sudo apt-get install debootstrap


NOW ENOUGH OF THEORIES, LET BEGIN ;)


STEP 1: Install debootstrap.


Note: if you want to check whether debootstrap is installed into your system or not run the following command:


aptitude show debootstrap | grep State


by aptitude show you can check any package, just make sure that 'S' of 'State' is capital.


STEP 2: You can install schroot also: it is a tool by which you can conveniently manage chroot environments, but i prefer using chroot itself (use of schroot will be my other post).


sudo apt-get install schroot


STEP 3: Make a directory into a drive with native linux file systems (ext2/3/4). I'll make this environment into /var/chroot/lucid ( we are building the evironment for lucid, you can build for maverick, natty or for anyother version, just use their codename on the place of lucid).


sudo mkdir /var/chroot


STEP 4: Setting up the chroot with debootstrap.


Sudo debootstrap –-variant=buildd –-arch i386 lucid /var/chroot/lucid http://archive.ubuntu.com/ubuntu/


Lets explain this command a bit:

sudo is for running the command as power user.

debootstrap is the tool we are going to use for setting up chroot environment.

--variant=buildd is going to install all the build-essential packages, you can also skip this and later execute 'sudo apt-get install build-essential' later after getting into chroot environment.

--arch i386 is representing the architecture you want to use into the environment. You can replace i386 with any architecture, just check whether the architecture you are using is supported by the version whose chroot environment you are going to set.

lucid is code name of the version whose chroot you are going to set.


Http://archi***/ubuntu/ the url from where all the essential files will be downloaded.


Congrats!! you successfully build a chroot environment for lucid.


But to actually make it work you need to provide the name of the repositories you are going to use for downloading ( in simple words provide the network support to grab the essential packages).



STEP 5: We will use sources.list file from you original distribution.


  • First copy the sources.list into your home folder by following command

    sudo cp /etc/apt/sources.list ~/

  • Then open the file into your favourite text editor, and replace all the occurences of with lucid.

  • Now copy or move the edited sources.list file from your home folder to the chroot environment folder.

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


STEP 6: (Final Step) To lock to new chroot environment.


sudo chroot /var/chroot/lucid



its all done :) by default you'll log in with root account.

You can create new user account there and login into it, or use this chroot environment with root account.

The beauty about whole thing is whenever you want to remove this chroot environment just delete the folder :).


My next post will be how to install GNOME into this and make a virtual screen and use this environment as an separate operating system, inside your previous operating system. :) So stay tuned.

© 2015 Techie's House. Designed by Bloggertheme9