Linux operating system initrd Overview

Source: Internet
Author: User
Tags gz file

Linux operating system initrd overview initrd is initial ramdisk, which is a temporary root file system mounted during system boot. the file system to be loaded to activate the system. next, let's take a look at the process from kernel to initrd: When grub loads the kernel, the kernel will create a rootfs in the memory as a temporary space for the system to use. Next, kernel will regard initrd as a system and mount it to rootfs to start. this file is very important because it is responsible for loading modules that cannot be provided by the kernel during startup. after initrd is loaded, in order to allow users to access the file system, the module of the file system is required, which is equivalent to the driver. in addition, additional modules must be pre-loaded. next let's take a look at how to enable initrd. Here I am using debian5 OS 1. create a directory named/boot/initrd. the img-2.6.18-6-amd64 is copied to this directory. 1root@192.168.30.68: Tmp # mkdir initrd2root@192.168.30.68: tmp # cd initrd/3root@192.168.30.68: initrd # ls4root@192.168.30.68: initrd # cp/boot/initrd. img-2.6.18-6-amd64. 5root@192.168.30.68: initrd # ls6initrd.img-2.6.18-6-amd642.change initrdfile name to .gz file and decompress it. 1root@192.168.30.68: initrd # file initrd. img-2.6.18-6-amd64 # Found this file is a gzip compressed file 2initrd. img-2.6.18-6-amd64: gzip compressed data, from Unix, last modified: Thu Sep 24 18: 21: 40 20093root@192.168.30.68: initrd # mv initrd. img-2.6.18-6-amd64 initrd.img-2.6.18-6-amd64.gz4root@192.168.30.68: initrd # file initrd.img-2.6.18-6-amd64.gz5initrd.img-2.6.18-6-amd64.gz: gzip compressed data, from Unix, last modified: Thu Sep 24 18:21:40 20096root@192.168.30.68: initrd # gunzip initrd.img-2.6.18-6-amd64.gz 3. the decompressed file is found to be in the cpid format, a backup format, using cpio, the 'I' parameter indicates that the first directory is automatically created when needed. 01 root @ 192.168.30.68: initrd # file initrd. img-2.6.18-6-amd6402initrd.img-2.6.18-6-amd64: ASCII cpio archive (SVR4 with no CRC) 03root@192.168.30.68: initrd # cpio-id <initrd. img-2.6.18-6-amd640432912 blocks05root@192.168.30.68: initrd # ls06bin conf etc init initrd. img-2.6.18-6-amd64 lib lib64 sbin scripts07root@192.168.30.68: initrd # rm initrd. img-2.6.18-6-amd6408rm: remove regular file 'initrd. img-2.6.18-6 -Amd64 '? Y09root@192.168.30.68: initrd # ls10bin conf etc init lib lib64 sbin scripts can also be directly through zcat to read the gzip format file, and then read the results of the pipeline to cpio to unlock the 1root@192.168.30.68: initrd # zcat initrd. img-2.6.18-6-amd64 | cpio-id232912 blocks3root@192.168.30.68: initrd # ls4bin conf etc init initrd. img-2.6.18-6-amd64 lib lib64 sbin scripts and above is the directory architecture after the initrd file is opened, when the kernel starts to load initrd, there is no directory architecture of any system, at this time, the directory provided by initrd is regarded as the temporary directory of the system. there is a lib directory: which stores Multiple modules, that is, all the modules in the system. This indicates that all the modules in the directory are required to be loaded upon startup. for example, after the kernel loads Initrd, initrd will add the corresponding network module driver so that we can access the operating system to identify the NIC. 1root@192.168.30.68: initrd # lsmod | grep bnx2 # native network drive 2bnx2 183048 03root@192.168.30.68: initrd # find. -name 'bnx2 * '# Module 4 corresponding to bnx2 in initrd. /lib/modules/2.6.18-6-amd64/kernel/drivers/net/bnx2.ko5. // lib/firmware/bnx2-09-4.0.5.fw6. /lib/firmware/bnx2-06-4.0.5.fw if temporary and added a new network card, you want to load at boot, then as long as you modify the content of the initrd file in the package Yes, it is much easier than re-compiling the kernel or installing the operating system. the following describes how to repackage the modified initrd file. 1. in the modified file directory, use find to list all the files, and then use pipeline to submit all the lists to the cpio command. the parameter 'C' used by cpio indicates that the new SVR4 portable format is used. 'O' indicates creating a file. finally, use gzip to compress with the best compression efficiency '-9' (default:-6) and use'> 'to export. 1root@192.168.30.68: initrd # ls2bin conf etc init lib lib64 sbin scripts3root@192.168.30.68: initrd # find | cpio-co | gzip-9> initrd. img-2.6.18-6-amd64432884 blocks5root@192.168.30.68: initrd # ls6bin conf etc I Nit initrd. img-2.6.18-6-amd64 lib lib64 sbin scripts7root@192.168.30.68: initrd # file initrd. img-2.6.18-6-amd648initrd.img-2.6.18-6-amd64: gzip compressed data, from Unix, last modified: Tue May 14 13:50:26 2013, max compression2. copy the file to/boot. restart the machine to take effect. in addition, the boot process after initrd is loaded by the kernel is based on an init file in the initrd file, and the script provided by it is executed step by step, this file also provides the actual operating system for loading physical hard disks. 01root@192.168.30.68: initrd # ls02bin conf etc init lib l Ib64 sbin scripts03root@192.168.30.68: initrd # cat init04 #! /Bin/sh05 06 echo "Loading, please wait... "07 08 [-d/dev] | mkdir-m 0755/dev09 [-d/root] | mkdir-m 0700/root10 [-d/sys] | mkdir /sys11 [-d/proc] | mkdir/proc12 [-d/tmp] | mkdir/tmp13mkdir-p/var/lock14mount-t sysfs-o nodev, noexec, nosuid none/sys15mount-t proc-o nodev, noexec, nosuid none/proc16 17 # Note that this only becomes/dev on the real filesystem if udev's scripts18 # are used; which they will be, but it's worth pointing out19tmpfs_size = "10 M" 20if [-e/etc/udev. conf]; then21. /etc/udev. conf22fi23mount-t tmpfs-o size = $ tmpfs_size, mode = 0755 udev/dev24 [-e/dev/console] | mknod-m 0600/dev/console c 5 125 [-e/dev/null] | mknod/dev /null c 1 326>/dev /. initramfs-tools27mkdir/dev /. initramfs28 29 # Export the dpkg ubunture30export DPKG_ARCH = 31. /conf/arch. conf32 33 # Set modprobe env34export MODPROBE_OPTIONS = "-qb" 35 36 # Export relevant export ROOT = 38 export ROOTDELAY = 39 export ROOTFLAGS = 40 export ROOTFSTYPE = 41 export break = 42 Export init = /sbin/init43export quiet = n44export readonly = y45 .....

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.