What is Chroot?
chroot, i.e.Change root directory (ChangeRootCatalogue). In theLinuxsystem, the system's default directory structure is `/`, which is the root(Root)the beginning. While in usechrootafter that, the system's directory structure will be the specified location as the `/` location.
Why use Chroot?
in passing chroot after that, the directories and files that the system reads will not be under the old system root but under the new root ( that is, the new location is specified ) the directory structure and file, so it brings the benefits of roughly the following 3 A:
1. Increase the security of the system, limiting the user's power;
in passing chroot after that, the root structure and files of the old system will not be accessed under the new root, thus enhancing the security of the system. This is generally used before login (login) to use chroot, so that users can not access some of the specific files.
2. establish a system directory structure isolated from the original system to facilitate user development;
Use chroot , the system reads the directories and files under the new root, which is a directory structure that is not related to the file under the original system root. In this new environment, it can be used to test the static compilation of software and some independent development that is unrelated to the system.
3.< /span> toggle system root directory location, boot Linux system start-up and first aid system, etc. ;
chroot RAM disk (INITRD) Toggle the root position of the system and execute the real init In addition, we can also use the chroot to switch to a temporary system.
Chroot use 1. Create a root directory after chroot. mkdir /var/chroot 2. Using jail+chroot mode, compile and install jail. From http://www.jmcresearch.com/ Static/dwn/projects/jail/jail.tar.gz can be downloaded to the latest version of jail, which is made by jail in http://www.jmcresearch.com/projects/jail/ Developed by the Chroot project team. The package contains C programs, Perl programs, and bash scripts that help automate the creation of Chroot "jail". First place the jail.tar.gz in any directory and then execute the command: tar xzf jail.tar.gz && cd jail/ SRC modifies the makefile file, in particular the installation path (the default installation path is/tmp/jail), the architecture (jail support for Linux, FreeBSD, IRIX, and Solaris), and the compilation options. Final execution command: Make && make install3. Create a chroot environment using the jail per program script/tmp/jail/mkjailenv /var/ The Chrootjail package provides several Perl scripts as their core commands, including Mkjailenv, Addjailuser, and &NBSP;ADDJAILSW. such as ADDJAILSW will copy the binary executable and other related files (including library files, auxiliary files and device files) from the real file system to the "prison" . 4. Add common commands for the chroot environment, such as LS, cat, cp , etc./usr/local/bin/addjailsw /var/chroot Note: If it is centos 7 Children's shoes Please install this software or the above command will be error strace 5. It's not going to go into the chroot environment, because without bash, you need to copy the local bash to the chroot environment ldd /bin/bash linux-vdso.so.1 => (0x00007ffdbd3e5000) libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f23337da000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f23335d6000) libc.so.6 => /lib64/libc.so.6 (0x00007f2333214000) /lib64/ ld-linux-x86-64.so.2 (0x00007f2333a0a000) cd /var/chroot/cp /lib64/{libtinfo.so.5,libdl.so.2, libc.so.6,ld-linux-x86-64.so.2} ./lib64/cp /bin/bash ./bin ------------------------ Gorgeous split line---------------------------------- How to use yum 1 in a chroot environment. Create an RPM directory mkdir –p /var/chroot/ Var/lib/rpm 2. Specify the rpm rebuild directory rpm --rebuilddb --root=/var/chroot 3. Download Centos7 yum Source wget http://mirror.centos.org/centos/7/os/x86_64/packages/ Centos-release-7-2.1511.el7.centos.2.10.x86_64.rpm 4. Installing Centos7 yum source rpm -ivh --root=/var/ chroot --nodepscentos-release-7-2.1511.el7.centos.2.10.x86_64.rpm 5. Install yumyum --installroot=/var/chroot install -y rpm-build yum 6 inside the chroot environment. Copy native parsing files to chroot environment cp /etc/resolv.conf /var/chroot/etc/ 7. Enter Chroot Environment Chroot /var/tmp/chroot /bin/bash –l
This article is from the "Attitude decides everything" blog, please make sure to keep this source http://sangh.blog.51cto.com/6892345/1752251
Chroot Change the World