How to Install the chroot in Debian 12

The chroot is the command utility operation used to change the process’s root directory. The chroot is the abbreviation of the “change root” in Linux. When the chroot changes the root directory, all the child processes, and the subdirectories are also shifted to some specified directory. 

The chroot is used for the testing during the software development and it is also used for repairing and recovering the system files. The chroot command comes preinstalled on Debian 12 and its usage has been explained with the following outline:

  1. How to Confirm the Pre Installation of chroot on Debian 12?
  2. How to Install chroot on Debian 12?
  3. How to Configure the chroot on Debian 12?
  4. How to Install the ssh on chroot?

Let’s start with the confirmation of the preinstallation of chroot on Debian 12.

How to Confirm the Pre Installation of chroot on Debian 12?

To confirm that the chroot is preinstalled on Debian 12, run the command:

$ which chroot

The output will show some path if the chroot command utility is preinstalled on the Debian 12. In our case, no output means that the chroot command utility is not installed on Debian 12. 

How to Install chroot Command on Debian Linux?

To install chroot on Debian 12, follow the steps explained below. 

Step 1: Update the Packages

Open the terminal and run the below-mentioned command to update all the packages:

$ sudo apt update

In the output above, one package needs to be upgraded which can be done by executing the command:

$ sudo apt upgrade -y

Step 2: Install debootstrap

After updating all the packages, install the debootstrap with the following command:

$ sudo apt install debootstrap -y

Step 3: Create a Directory

Now create a new directory with the mkdir command for the chroot environment:

$ sudo mkdir -p /mnt/chroot

Users can create a directory in some other location as well.

Step 4: Build the chroot

After the directory is created, download and install the new system files using the debootstrap command:

$ sudo debootstrap stable /mnt/chroot http://deb.debian.org/debian/

Step 5: Connect the Host proc

In this step, mount the newly created directory with the host proc system in order to access its hardware:

$ sudo mount -t proc proc /mnt/chroot/proc && sudo mount -t devpts devpts /mnt/chroot/dev/pts

Step 6: Enter the chroot Environment

To enter the chroot environment, it is recommended to use the “sudo” keyword:

$ sudo chroot /mnt/chroot

Now we are in the chroot environment after its successful installation on Debian 12. 

How to Configure the chroot on Debian 12?

The chroot can be configured on Debian 12 with the steps explained below. 

Step 1: Install the locale

First, install the locale package with the apt command:

# apt install locales

Step 2: Reconfigure the locale

After the installation is completed, reconfigure the installed locale with the dpkg command:

# dpkg-reconfigure locales

Click on “Ok” to proceed next option:

Choose the locale of your choice and then click on the “Ok” option:

The chroot has been successfully configured on Debian 12.

How to Install the SSH on chroot?

To install the SSH service on the chroot environment, first install the SSH with the following command:

# apt install ssh -y

For configuring SSH such that it listens on port 22, use the command:

# nano /etc/ssh/sshd_config

Uncomment the lines mentioned in the below figure:

Save the file and exit the nano text editor. When done, then restart the ssh service with the following command:

# /etc/init.d/ssh restart

Exit the root terminal:

# exit

Now login to the SSH service remotely with the following command:

$ itslinuxfoss@localhost -p 2222

This is all about the installation of the chroot on Debian 12. 

Conclusion

To install the chroot on Debian 12, install the package of the “debootstrap” with the execution of the “sudo apt install debootstrap -y” command. This will help to create the chroot environment and install the Debian system files in it. This blog has demonstrated the installation of the chroot with its configuration in the Debian 12. The SSH service is also installed and configured with the chroot environment.