Linux operating system overview built using chroot

Source: Internet
Author: User

 

Author:North South
From:Linuxsir. org
Abstract:In the existing Linux operating system, to install another open-source operating system, we usually build the basic chroot environment of the new operating system first, and then chroot enters the new operating system environment to install and configure. This method of building and installing the operating system is important for us to learn and study the operating system structure and principles. This article provides a simple example. Based on Fedora Core 5.0, chroot is used to build slackware 10.2;


Directory

1. Purpose and purpose of installing the operating system using the chroot method;
2. The system environment required for installing the operating system through the chroot method;
3. Install the Operating System Using chroot;
4. Media description of the installation destination of the operating system;
5. To be honest, install slackware 10.2 In fedora;

    5.1 install slackware 10.2 through chroot to a hard disk physical partition;
    5.2 install slackware 10.2 in an image file through chroot;

6. Extraction of software packages such as rpm, tgz, And Deb;

    6.1 Extract files from the RPM software package;
    6.2 extraction of file.tgz1_file.tar.gzand file.tar.bz2;
    6.3 extraction of file. Deb;
    6.4 extraction of file. ISO files;
    6.5 file extraction references;

7. After chroot successfully enters the new operating system, the software installation problem is supplemented;
8. About this article;
9. references;
10. related documents;


++ ++
Body
++ ++


1. Purpose and purpose of installing the operating system using the chroot method;

The chroot tool is a tool available in Linux operating systems. On the surface, the chroot tool is from one/root to another/root. Installing another operating system in one Linux operating system is to take advantage of this feature of chroot. First, create the basic environment for chroot running, then use chroot to go to the new/root, and then use the corresponding software package management tool to install other software packages of the new operating system;

Almost all open-source operating systems can be installed using the chroot method. For example, Gentoo, LFS, and crux are commonly used as chroot; installing the Operating System Using chroot is like piling up wood, install the operating system one by one, so Gentoo and LFS fans have a special sense of accomplishment. Oh, It is also said that the operating system is all created manually, and the sense of accomplishment is naturally self-evident;

What can we learn when installing the Operating System Using chroot? It is mainly to know the minimum number of components required by an operating system that can be "Moved", and to understand the basic necessary "components" required by an operating system ", this is important for developing your own Linux-based operating system and understanding the composition and Principles of the operating system;


2. The system environment required for installing the operating system through the chroot method;

The most fundamental environment is to have a Linux operating system or a livecd on your machine;


3. Install the Operating System Using chroot;

The following steps are required:

1. plan hard disk partitions or create image files. For details, refer to: How to Use fdisk for instance explanation
Ii. Create a file system; storage device partition operations and file system management overview
3. mount a file system; detailed procedures for creating a file system and mounting a file system in Linux
4. Install the basic system. It is mainly implemented by extracting the software package;
5. modify the configuration file of the new system, such as/etc/fstab in the new system.
6. Resolve dependencies and install software package management tools;
7. Use chroot to enter the new system;
8. install other software packages through the new system software package my management tool;
9. Handle boot problems, such as GRUB boot. System Boot manager grub is a beginner's guide.


4. Media description of the installation destination of the operating system;

An operating system can be installed on a physical hard disk or an image file. How can I understand the installation in an image file? For example, is the virtual installation of the Operating System Through vmware installed in a file? Yes, it is similar to this. Besides, swap can be a file, and xen can be installed in a file image;

The operating system installed in the image file can be used for learning and accessed through chroot, or virtual by xen ...... it can also be made into a file. stores files in ISO format;


5. To be honest, install slackware 10.2 In fedora;

In this example, slackware 5.0 is installed through chroot in Fedora Core 10.2. There are two types of media for installation destination: physical hard disk and image file. You can use the grub or lilo Boot manager to install it on a physical hard disk. The images can be accessed by chroot or run by xen;


5.1 install slackware 10.2 through chroot to a hard disk physical partition;

This process seems redundant, but it is good to write it. This is common for installation of most open-source operating systems and the most primitive and effective method, that is to say, install another operating system in an existing operating system environment;

First, you must understand how to plan your partition. For details, refer to: How to Use fdisk for instance explanation.
Second, you also need to know how to create a file system. For details, see storage device partition operations and file system management overview.
Third, you need to know how to mount a file system. For details, see: Linux File System creation and file system mounting process.

Mount a file system by means of mount;

# Mount storage device mount point

Example:

For example, my hard disk/dev/hda5 is a blank partition, and I want to create/dev/hda5 as an ext3 file system and mount it to the/mnt/slack directory, then use chroot to install slackware 10.2;

Step 1: Use the partition tool fdisk or parted to plan your partition. This step is omitted;

Please refer to: How to Use fdisk for instance explanation


Step 2: create a file system;

[Root @ localhost ~] # Mkdir/mnt/slack
[Root @ localhost ~] # Mkfs. ext3/dev/hda5 Note: format/dev/hda5 as the ext3 file system;


Step 3: mount the file system;
[Root @ localhost ~] # Mount/dev/hda5/mnt/slack Note: Mount/dev/hda5 to the/mnt/slack directory;


Step 4: mount the first slackware 10.2 disc and install the basic system;
[root@localhost ~]# mount -o loop slackware-10.2-install-d1.iso /mnt/cdrom/

We can first create a package storage directory in the/mnt/slack directory to store all the content in the slackware-10.2-install-d1.iso;

[root@localhost ~]#mkdir /mnt/slack/pack
[root@localhost ~]# cp -rp /mnt/cdrom/* /mnt/slack/pack

Decompress all the packages in directory A in the slackware directory on the first slackware disk, and decompress the packages starting with glibc in the d directory, zlib and zsh in the d directory, for example, all directories such as/usr, etc, and Lib are copied to/mnt/slack;

Step 5: Resolve the dependency;

If the following command prompts that the/bin/bash file is not available, we need to solve the dependency. by solving the dependency, we will also find the necessary basic software package required to run chroot;

[root@localhost ~]# chroot /mnt/slack

If some files are missing, we can determine which packages are missing. When we enter the/mnt/slack/bin directory, we find that there is indeed no bash file, so we need to copy a bash file;

[root@localhost ~]# cd /mnt/slack/bin
[root@localhost bin]# cp bash2.new bash

In this case, we need to determine the library files on which bash depends;

[root@localhost bin]# ldd  bash

Most of the dependencies are glibc. glibc is installed in the/mnt/slack/lib/TLS directory. we can link them one by one as prompted. The link for what you do with nothing. You need to check whether there is a glibc file in/mnt/slack/lib, and then do the link. If it is stored in the TLS directory, it must also be linked to/mnt/slack/lib. The link must use a relative path instead of an absolute path;
Creating a link file is similar to creating a shortcut in Windows. Use the ln command;

# Ln-s new original file name

What solves the bash dependency? The chroot/MT/slack operation is successful;

Step 6: log on to the slackware system after the chroot operation is successful;

After chroot is successful, we can access the slackware system and install other software packages, such as the kernel, through pkgtool or installpkg;

[root@localhost ~]# chroot /mnt/slack


Step 7; change the/etc/fstab file;

If you want to run an operating system independently, you have to write the/etc/fstab file. For details, refer to the following example;

/dev/hda7        swap             swap        defaults         0   0
/dev/hda6        /                reiserfs    defaults         1   1
/dev/hda1        /mnt/winc        ntfs        ro               1   0
/dev/hda3        /mnt/wind        vfat        defaults         1   0
/dev/cdrom       /mnt/cdrom       auto        noauto,owner,ro  0   0
/dev/fd0         /mnt/floppy      auto        noauto,owner     0   0
devpts           /dev/pts         devpts      gid=5,mode=620   0   0
proc             /proc            proc        defaults         0   0
none            /sys            sysfs           defaults        0   0


Step 8: guide the system;

You need to use grub or lilo Boot manager to guide slackware. For more information, see grub System Boot manager for beginners.


5.2 install slackware 10.2 in an image file through chroot;


Step 1: create an image file;

For example, if we create an image file named slack. IMG with a size of 2 GB, we can use the following command. BS is the size of 1 MB for each block and we will create 2000 blocks;

[Root @ localhost ~] # Dd If =/dev/Zero of = slack. img bs = 1 m COUNT = 2000 seek = 1024

Step 2: create a file system;

You can create a file system such as ext3, FAT32, or reiserfs. For more information, see storage device partition operations and file system management overview.

[root@localhost ~]# /sbin/mkfs.ext3 slack.img
mke2fs 1.38 (30-Jun-2005)
slack.img is not a block special device.
Proceed anyway? (y,n) y


Step 3: mount the Formatted Image File;

[root@localhost ~]# mkdir /mnt/slack
[root@localhost ~]# mount -o loop slack.img  /mnt/slack/


After step 4, the operations are basically the same as those on the physical hard disk;


6. Extraction of software packages such as rpm, tgz, And Deb;

The release version has a certain package format, such as file. RPM file.debor file.tgzor file.tar.gz. rpm-format packages are generally developed based on Redhat or fedora. Because chroot installs the operating system, the first thing to do is to extract files from a software package and then copy them to the file system. Therefore, the file Extraction Tool also has to be explained;

6.1 Extract files from the RPM software package;

The premise for the operation is to have the RPM management tool, that is, the RPM and other related commands;


Command Format: rpm2cpio file. RPM | cpio-Div

Example:

[root@localhost RPMS]# rpm2cpio gaim-1.3.0-1.fc4.i386.rpm |cpio -div

The extracted files are stored in USR and etc;

In fact, it is better to specify the installation directory to install software. You can also Extract files;

Specify the installation directory for the package: add the-Relocate parameter; the example below is to specify the gaim-1.3.0-1.fc4.i386.rpm to install in the/opt/Gaim directory;

[root@localhost RPMS]# rpm -ivh --relocate /=/opt/gaim gaim-1.3.0-1.fc4.i386.rpm
Preparing... ########################################### [100%]
   1:gaim ########################################### [100%]
[root@localhost RPMS]# ls /opt/
gaim

In this way, all Gaim files are installed in/opt/Gaim. We just back up the Gaim Directory, which is actually a bit of file extraction usage;


6.2 extraction of file.tgz1_file.tar.gzand file.tar.bz2;

[root@localhost ~]# tar zxvf file.tgz
[root@localhost ~]# tar zxvf file.tar.gz
[root@localhost ~]# tar jxvf file.tar.bz2


6.3 extraction of file. Deb;

[root@localhost ~]# ar x file.deb
[root@localhost ~]# tar zxvf data.tar.gz

File. Deb unpacks through ar X, and then unpacks data.tar.gz to see the related directories and files;


6.4 extraction of file. ISO files;

In Linux, such files are mainly mounted through Mount-o loop file. ISO; for example;

[root@localhost ~]# mount -o loop slackware-10.2-install-d1.iso /mnt/cdrom/


6.5 file extraction references;

File decompression
Introduction and Application of RPM
Http://debian.linuxsir.org
Http://slack.linuxsir.org


7. After chroot successfully enters the new operating system, the software installation problem is supplemented;

If chroot can be used to access the newly installed operating system, we can install other software packages using the new operating system software package management tool. For example, slackware uses pkgtool or installpkg; fedora uses rpm and other tools. Most of the tools used in the release are different. Refer to the release version;


8. About this article;

I wanted to write this article last year. With the passage of time, I may have forgotten about what I think of today, so I want to write it when I use chroot, if you cannot use it, you can throw the document writing event to one side. Today, I wrote a document about xen, And I just used the chroot method to install the new operating system. Although the function of chroot is a little less involved, it is almost the same as that of chroot. Maybe the name of this article is a bit inconsistent, and I do not know what naming titles are not good. Slowly correcting ......


9. references;

How to Use fdisk for instance explanation
Storage Device partitioning and file system management overview
How to create a file system and mount a file system in Linux
File decompression
Introduction and Application of RPM
Http://debian.linuxsir.org
Http://slack.linuxsir.org
Http://fedora.linuxsir.org

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.