Setting up a Ubuntu chroot Environment using debootstrap tool.

Reading Time: 3 minutes

Welcome to this blog. You might be aware about today’s topic but before taking deep dive into setting up environment using debootstrap tool. Let us first understand about Chroot.

In Simplified terms chroot is command to change a particular directory to be the root directory. So once you’re inside this space you cannot access any directory above it. This also locks the access to any program aside from this space.

So it allows you to have a temporary system for development and testing without using virtual machine. his modified environment is known as “chroot jail” or “jailed directory”

what is debootstrap ?

Debootstrap can be used to install Debian in a system without using an installation disk but can also be used to run a different Debian flavor in a chroot environment. A full minimal Debian installation can can be done for testing purposes.

Debootstrap can only use one repository for its packages. If you need to merge packages from different repositories (the way apt does) to make a rootfs, or you need to automatically customise the rootfs, then use Multistrap.

When you do debootstrap –help, You can see this

Now let’s create the environment

Firstly Update apt‘s package repository.

sudo apt update

Now Install debootstrap using apt.

sudo apt install debootstrap

Create a new separate directory.

mkdir newchroot-ubuntu

Now Since everything is ready , lets create a base Ubuntu system using debootstrap on this directory

we will mount proc, sys and dev filesystem on to the base system.

sudo mount -t proc /proc newchroot-ubuntu/proc
sudo mount --rbind /sys newchroot-ubuntu/sys
sudo mount --rbind /dev newchroot-ubuntu/dev

chroot to the folder

sudo chroot newchroot-ubuntu /bin/bash

as you can see your environment is ready. do whatever you want to do here after this you can also Unmount the mounted procsys and dev filesystem and also delete this folder.

To Unmount the mounted procsys and dev use this

sudo umount newchroot-ubuntu/proc newchroot-ubuntu/sys newchroot-ubuntu/dev 

Remove the chroot folder if you want

 sudo rm -rf newchroot-ubuntu

Conclusion:

This was all about how to create a chroot environment using debootstrap tool. If you liked this article please do comment and share. to learn about more about chroot visit this blog.

References:

Ref1 Ref2

Written by 

Passionate about Technology and always Interested to Upskill myself in new technology, Working in the field of DevOps

Leave a Reply