Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure chroot environment in Ubuntu system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to configure chroot environment in Ubuntu system", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "How to configure chroot environment in Ubuntu system"!

Chroot environment

A chroot environment is a system call that temporarily turns a local directory into a root directory. The system root is generally referred to as the mount point "/," however, after using the chroot command, you can use other directories as root directories.

In principle, any application running in a chroot environment cannot access other information on the system. However, applications running in chroot can access information outside the environment through the sysfs file system, so there is a "in principle" modifier here.

Use of Chroot Environment

Testing an unstable application service does not affect the entire host system.

Even if you do something wrong with root privileges and mess up the chroot environment, it will not affect the host system.

You can run another operating system on your system.

For example, you can compile, install, and test software in a chroot environment without touching the real system. You can also chroot a 32-bit environment in a 64-bit environment and run a 32-bit program.

However, for security reasons, chroot environments impose very strict restrictions on non-privileged users rather than providing a complete security policy. If you need an isolation solution with a sound security policy, consider LXC, Docker, vservers, etc.

Debootstrap and Schroot

Using chroot requires installing debootstrap and schroot, both of which are in Ubuntu's mirror source. Schroot is used to create chroot environments.

Debootstrap allows you to install any Debian (or Debian-based) system from an image source, and the installed system contains the most basic commands.

The Schroot command allows users to create chroot environments using the same mechanism, but with permission checks when accessing chroot environments, and allows users to make additional automatic settings, such as mounting some file systems.

On Ubuntu 14.04 LTS, we can do this in two steps:

1. installation package

First, install debootstrap and schroot on the Ubuntu 14.04 LTS host system:

The code is as follows:

$ sudo apt-get install debootstrap

$ sudo apt-get install schroot

2. Configure Schroot

Now that we have the tools in hand, we need to specify a directory as our chroot environment. Create a directory here:

The code is as follows:

sudo mkdir /linoxide

Edit schroot's profile:

The code is as follows:

sudo nano /etc/schroot/schroot.conf

Again, we are currently on Ubuntu 14.04 LTS. If we want to test whether a package runs on Ubuntu 13.10 (codenamed "Saucy Salamander"), we can add the following to the configuration file:

The code is as follows:

[saucy]

description=Ubuntu Saucy

location=/linoxide

priority=3

users=arun

root-groups=root

Adjust the configuration information above according to your system requirements.

3. Install 32-bit Ubuntu with debootstrap

Debootstrap will download and install a minimal system in your chroot environment. You can install any Debian-based system version as long as you have access to the mirror source.

We have created the/linoxide directory for chroot environment, now we can run debootstrap in this directory:

The code is as follows:

cd /linoxide

sudo debootstrap --variant=buildd --arch amd64 saucy /linoxide/ http://archive.ubuntu.com/ubuntu/

sudo chroot /linoxide /debootstrap/debootstrap --second-stage

You can replace the--arch argument with i386 or any other architecture, as long as there is a mirror source for that architecture. You can also change the mirror source http://archive.ubuntu.com/ubuntu/ to the mirror source closest to you, see the Ubuntu official mirror homepage for details.

Note: If you are creating a 32-bit system on a 64-bit system, you need to add the--foreign option to the command on line 3 above, just like the following command:

The code is as follows:

sudo debootstrap --variant=buildd --foreign --arch i386 saucy /linoxide/ http://archive.ubuntu.com/ubuntu/

Download takes a while, depending on your network bandwidth performance. The smallest system is about 500 megabytes.

4. Complete chroot environment

After installing the system, we need to do some finishing touches to make sure the system is working properly. First, make sure that the host fstab program is aware of the chroot environment:

The code is as follows:

sudo nano /etc/fstab

Add the following configuration at the end of the file:

The code is as follows:

proc /linoxide/proc proc defaults 0 0

sysfs /linoxide/sys sysfs defaults 0 0

Save and close the file.

Mount some file systems into the chroot environment:

The code is as follows:

$ sudo mount proc /linoxide/proc -t proc

$ sudo mount sysfs /linoxide/sys -t sysfs

Copy the/etc/hosts file to the chroot environment so that the chroot environment can use the network:

The code is as follows:

$ sudo cp /etc/hosts /linoxide/etc/hosts

Finally, use the schroot -l command to list all chroot environments on the system:

The code is as follows:

$ schroot -l

Enter the chroot environment using the following command:

The code is as follows:

$ sudo chroot /linoxide/ /bin/bash

Test installed version:

The code is as follows:

# lsb_release -a

# uname -a

To use the GUI in chroot environment, you need to set the DISPLAY environment variable:

The code is as follows:

$ DISPLAY=:0.0 ./ apps

So far, I have successfully installed Ubuntu 13.10 on Ubuntu 14.04 LTS.

Exit chroot environment:

The code is as follows:

# exit

Clean up and uninstall the file system:

The code is as follows:

$ sudo umount /test/proc

$ sudo umount /test/sys

At this point, I believe that everyone has a deeper understanding of "how to configure chroot environment in Ubuntu system", may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report