How to open a Initrd file system on a Linux system

Source: Internet
Author: User
Tags gz file mkdir

Initial RAM Disk

The Linux initial RAM disk (INITRD) is a temporary root file system that is mounted during system boot to support two-stage boot processes. The Initrd file contains various executables and drivers that can be used to mount the actual root file system and then uninstall the INITRD RAM disk and free up memory. In many embedded Linux systems, INITRD is the ultimate root file system. This article explores the initial RAM disk for Linux 2.6, including how to create and use it in the Linux kernel.
What is the initial RAM disk

The initial RAM disk (INITRD) is an initial root file system that is mounted to the system before the actual root file system is available. Initrd are bound to the kernel and loaded as part of the kernel boot process. The kernel then loads the Initrd file as part of its two-phase boot process to later use the real file system and mount the actual root file system.
The INITRD contains the smallest set of directories and executable programs needed to achieve this goal, such as the Insmod tool used to load kernel modules into the kernel.
In a desktop or server Linux system, INITRD is a temporary file system. Its survival cycle is very short and will only be used as a bridge to real-world file systems. In an embedded system without a storage device, INITRD is a permanent root file system. In this paper, we will explore these two kinds of situations.

INITRD opening steps

Now let's look at how to open initrd, where I'm using the DEBIAN5 operating system

1. Create a directory, copy/boot/initrd.img-2.6.18-6-amd64 to the directory.

The code is as follows:
root@192.168.30.68:tmp# mkdir INITRD
root@192.168.30.68:tmp# CD initrd/
root@192.168.30.68:initrd# ls
root@192.168.30.68:initrd# Cp/boot/initrd.img-2.6.18-6-amd64.
root@192.168.30.68:initrd# ls
Initrd.img-2.6.18-6-amd64

2. Replace the INITRD file name with the. gz file and unzip it.

The code is as follows:
root@192.168.30.68:initrd# file Initrd.img-2.6.18-6-amd64 #发现该文件是一个gzip压缩过的文件
Initrd.img-2.6.18-6-amd64:gzip compressed data, from Unix, Modified:thu Sep 24 18:21:40 2009
root@192.168.30.68:initrd# MV Initrd.img-2.6.18-6-amd64 initrd.img-2.6.18-6-amd64.gz
root@192.168.30.68:initrd# file initrd.img-2.6.18-6-amd64.gz
Initrd.img-2.6.18-6-amd64.gz:gzip compressed data, from Unix, Modified:thu Sep 24 18:21:40 2009
root@192.168.30.68:initrd# Gunzip initrd.img-2.6.18-6-amd64.gz

3. Using file discovery The extracted file is a cpid format, is a backup format, using CPIO, the parameter ' I ' stands for Che Bao and ' d ' representatives to automatically create the first level directory when needed.

The code is as follows:
root@192.168.30.68:initrd# file Initrd.img-2.6.18-6-amd64
Initrd.img-2.6.18-6-amd64:ascii Cpio Archive (SVR4 with no CRC)
root@192.168.30.68:initrd# Cpio-id < INITRD.IMG-2.6.18-6-AMD64
32912 blocks
root@192.168.30.68:initrd# ls
Bin conf etc Init initrd.img-2.6.18-6-amd64 lib lib64 sbin scripts
root@192.168.30.68:initrd# RM initrd.img-2.6.18-6-amd64
Rm:remove regular file ' Initrd.img-2.6.18-6-amd64 '? Y
root@192.168.30.68:initrd# ls
Bin conf etc init lib lib64 sbin scripts

You can also read GZIP-formatted files directly through Zcat, and then read the results from pipeline to Cpio to unlock

The code is as follows:
root@192.168.30.68:initrd# Zcat Initrd.img-2.6.18-6-amd64 | Cpio-id
32912 blocks
root@192.168.30.68:initrd# ls
Bin conf etc Init initrd.img-2.6.18-6-amd64 lib lib64 sbin scripts

The above is the INITRD file Open Directory schema, when the kernel started loading initrd, there is no directory schema of any system, then the directory provided by INITRD as a temporary directory of the system.

There is a Lib directory: there are many modules, that is now all the modules of the system, which represents the storage module in the directory must be loaded on the module. For example, when kernel loads INITRD, INITRD will add the corresponding network module driver, So that we can get into the operating system to recognize the NIC.

The code is as follows:
root@192.168.30.68:initrd# Lsmod | grep bnx2 #本机网络驱动
Bnx2 183048 0
root@192.168.30.68:initrd# find. -name ' bnx2* ' #initrd里bnx2对应的模块
./lib/modules/2.6.18-6-amd64/kernel/drivers/net/bnx2.ko
./LIB/FIRMWARE/BNX2-09-4.0.5.FW
./LIB/FIRMWARE/BNX2-06-4.0.5.FW

If temporarily added a piece of the latest network card, I hope to load when the boot, then as long as the contents of the modified INITRD file in a pack on it, compared to recompile kernel or install the operating system is more convenient.

Here's how to get the modified INITRD file to be repackaged again.

1. In the revised file directory, use Find to list all the files, and then through pipeline, all the listings to the Cpio instructions. The cpio parameter ' C ' is used to represent the new SVR4 portable format. ' O ' represents the creation of documents. Finally use gzip to optimize compression efficiency '-9 ' compression (default is-6), export using ' > '.

The code is as follows:
root@192.168.30.68:initrd# ls
Bin conf etc init lib lib64 sbin scripts
root@192.168.30.68:initrd# Find | Cpio-co | gzip-9 > Initrd.img-2.6.18-6-amd64
32884 blocks
root@192.168.30.68:initrd# ls
Bin conf etc Init initrd.img-2.6.18-6-amd64 lib lib64 sbin scripts
root@192.168.30.68:initrd# file Initrd.img-2.6.18-6-amd64
Initrd.img-2.6.18-6-amd64:gzip compressed data, from Unix, Modified:tue 13:50:26 2013, max compression

2. Copy the file to/boot/. Restart the machine for effective.

In addition, the boot process after the INITRD is kernel loaded is followed by an init file in the Initrd file, which is provided by the script that it provides step-by-step down, including the physical hard disk loading the actual operating system is also provided by this file.

The code is as follows:
root@192.168.30.68:initrd# ls
Bin conf etc init lib lib64 sbin scripts
root@192.168.30.68:initrd# Cat Init
#!/bin/sh

The code is as follows:

echo "Loading, please wait ..."

The code is as follows:

[-d/dev] | | Mkdir-m 0755/dev
[-d/root] | | Mkdir-m 0700/root
[-d/sys] | | Mkdir/sys
[-d/proc] | | Mkdir/proc
[-d/tmp] | | Mkdir/tmp
Mkdir-p/var/lock
Mount-t Sysfs-o Nodev,noexec,nosuid None/sys
Mount-t Proc-o Nodev,noexec,nosuid None/proc

The code is as follows:

# This is the Becomes/dev on the real filesystem if Udev ' s scripts
# are used; Which they would be, but it ' s worth pointing out
Tmpfs_size= "10M"
if [-e/etc/udev/udev.conf]; Then
. /etc/udev/udev.conf
Fi
Mount-t tmpfs-o size= $tmpfs _size,mode=0755 Udev/dev
[-e/dev/console] | | Mknod-m 0600/dev/console C 5 1
[-e/dev/null] | | Mknod/dev/null C 1 3
>/dev/.initramfs-tools
Mkdir/dev/.initramfs

The code is as follows:

# Export The dpkg architecture
Export dpkg_arch=
. /conf/arch.conf

The code is as follows:

# Set Modprobe Env
Export modprobe_options= "-QB"

The code is as follows:

# Export Relevant variables
Export root=
Export rootdelay=
Export rootflags=
Export rootfstype=
Export break=
Export Init=/sbin/init
Export Quiet=n
Export Readonly=y
.....

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.