How to configure the chroot environment in Ubuntu14.04

Source: Internet
Author: User
Tags virtual private server
You may have many reasons to isolate an application, user, or environment from your Linux system. Different operating systems have different implementation methods. In Linux, a typical method is the chroot environment. In this tutorial, I will step by step guide you how to use the chroot command to configure an independent environment separated from the real system. This function is mainly used for testing projects. The following steps are performed on Ubuntu14.04 virtual private server (VPS. Learning

You may have many reasons to isolate an application, user, or environment from your Linux system. Different operating systems have different implementation methods. In Linux, a typical method is the chroot environment.

In this tutorial, I will step by step guide you how to use the chroot command to configure an independent environment separated from the real system. This function can be used to test projects.Ubuntu 14.04Run the command on the virtual private server (VPS.

Learning to quickly build a simple chroot environment is a very practical skill, and most system administrators can benefit from it.

Chroot environment

A chroot environment is called by the system to temporarily change a local directory to the root directory. Generally, the system root directory is the mount point "/". However, after using the chroot command, you can use other directories as the root directory.

In principle, any application running in the chroot environment cannot access other information in the system, applications running in the directory can only access files in the local directory, but cannot access files outside the directory. However, applications running in the chroot environment can access information outside the environment through the sysfs file system. Therefore, there is a "principle" modifier here ).

Use of the Chroot environment
  • Testing an unstable application service does not affect the entire host system.

  • Even if the root permission is used for some improper operations, the chroot environment will not be affected.

  • You can run another operating system in your system.

For example, you can compile, install, and test software in the chroot environment without moving the real system. You can alsoCreate a 32-bit environment using chroot in a 64-bit environment, and then run a 32-bit program(LCTT ze Note: If your real environment is 32-bit, you cannot chroot a 64-bit environment ).

However, for the sake of security, the chroot environment imposes very strict restrictions on non-privileged users, rather than providing complete security policies. If you need a comprehensive security policy isolation solution, consider LXC, Docker, vservers, and so on.

Debootstrap and Schroot

Installation is required to use the chroot environmentDebootstrapAndSchrootBoth software are in the Ubuntu image source. Schroot is used to create a chroot environment.

DebootstrapYou can install any Debian (or Debian-based) system through the image source. The installed system contains the most basic commands.

SchrootCommand allows you to use the same mechanism to create a chroot environment, but some permission checks are performed when you access the chroot environment, and some additional automatic settings are allowed, such as mounting some file systems.

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

1. install the software package

Step 1: Install debootstrap and schroot on the Ubuntu 14.04 LTS host system:

  1. $ Sudo apt-get install debootstrap
  2. $ Sudo apt-get install schroot
2. Configure Schroot

Now that we have a tool in hand, we need to specify a directory as our chroot environment. Create a directory first:

  1. Sudo mkdir/linoxide

Edit the configuration file of schroot:

  1. Sudo nano/etc/schroot. conf

Again, we are now on the Ubuntu 14.04 LTS system. If you want to test whether a software package can run on Ubuntu 13.10 (codenamed "Saucy Salamander"), you can add the following content to the configuration file:

  1. [Saucy]
  2. Description = polictusaucy
  3. Location =/linoxide
  4. Priority = 3
  5. Users = arun
  6. Root-groups = root

Adjust the preceding configuration according to your system requirements.

3. Use debootstrap to install a 32-bit Ubuntu System

The Debootstrap command willChroot environmentDownload and install a minimum system. As long as you can access the image source, you can install any Debian-based system version.

We have created/LinoxideThe directory is used to place the chroot environment. Now we can run debootstrap in this directory:

  1. Cd/linoxide
  2. Sudo debootstrap -- variant = buildd -- arch amd64 saucy/linoxide/http://archive.ubuntu.com/ubuntu/
  3. Sudo chroot/linoxide/debootstrap -- second-stage

You can change the -- arch parameter to i386 or another architecture, as long as there is an image source for this architecture. You can also replace the image source http://archive.ubuntu.com/ubuntu/ with the image source closest to you. For details, refer to the official Ubuntu image home page.

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

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

It may take some time to download your network bandwidth. The minimum system size is approximately 500 mb.

4. Complete the chroot environment

After installing the system, we need to finish some work to ensure that the system runs normally. First, ensure that the fstab program of the host is aware of the existence of the chroot environment:

  1. Sudo nano/etc/fstab

Add the following configuration at the end of the file:

  1. Proc/linoxide/proc defaults 00
  2. Sysfs/linoxide/sys sysfs ults 00

Save and close the file.

Mount some file systems to the chroot environment:

  1. $ Sudo mount proc/linoxide/proc-t proc
  2. $ Sudo mount sysfs/linoxide/sys-t sysfs

Copy the/etc/hosts file to the chroot environment so that the network can be used in the chroot environment:

  1. $ Sudo cp/etc/hosts/linoxide/etc/hosts

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

  1. $ Schroot-l

Run the following command to enter the chroot environment:

  1. $ Sudo chroot/linoxide // bin/bash

Version of the test and installation:

  1. # Lsb_release-
  2. # Uname-

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

  1. $ Show =: 0.0./apps

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

Exit the chroot environment:

  1. # Exit

Clean up and uninstall the file system:

  1. $ Sudo umount/test/proc
  2. $ Sudo umount/test/sys

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-02/113975.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.