Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to open the Initrd file system in Linux system

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In view of how to open the Initrd file system in the Linux system, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Initial RAM disk

The Linux initial RAM disk (initrd) is a temporary root file system mounted during the system boot process to support the two-stage boot process. The initrd file contains a variety of executables and drivers that can be used to mount the actual root file system, then unmount the initrd RAM disk and free memory. In many embedded Linux systems, initrd is the ultimate root file system. This article will explore 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 is bundled with the kernel and loaded as part of the kernel boot process. The kernel then loads the module with the initrd file as part of its two-phase boot process so that the real file system can be used later and the actual root file system can be mounted.

Initrd contains the minimum set of directories and executables needed to achieve this goal, such as the insmod tool used to load kernel modules into the kernel.

In desktop or server Linux systems, initrd is a temporary file system. Its life cycle is very short and will only be used as a bridge to the real file system. In an embedded system without a storage device, initrd is the permanent root file system. This paper will explore these two situations.

Initrd activation step

Let's take a look at how to open initrd, where I'm using the debian5 operating system.

1. Create a directory and copy / boot/initrd.img-2.6.18-6-amd64 to that 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

two。 Change the name of the initrd file to .gz file and extract it.

The code is as follows:

Root@192.168.30.68:initrd# file initrd.img-2.6.18-6-amd64 # found that the file is a gzip compressed file

Initrd.img-2.6.18-6-amd64: gzip compressed data, from Unix, last 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, last 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 to find that the unzipped file is a cpid format, is a backup format, using cpio, the parameter'i' represents unpacking and'd 'represents the automatic establishment of the first layer 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 也可以直接通过zcat读取gzip格式的文件,再将读出来的结果由pipeline交给cpio解开 代码如下: 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 以上就是initrd文件打开后的目录架构,当kernel启动加载initrd时,并没有任何系统的目录架构,这时会先以initrd所提供的目录当做是系统的暂时目录. 其中有个lib目录:里面存放着许多的模块,即现在系统所有的模块,这代表目录中所存放的模块都是开机所必须加载的模块.例如当kernel加载Initrd之后,initrd将会加相应的网络模块驱动,以便让我们进入操作系统能够识别到网卡. 代码如下: 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 假如临时又添加了一块最新的网卡,希望在开机时加载,这时只要修改initrd文件的内容在打个包就可以了,比起重新编译kernel或者安装操作系统要方便多了. 下面介绍如何让将修改后的initrd文件再重新打包起来. 1.在修改后的文件目录下,使用find将所有的文件列出来,再通过pipeline,把所有清单交给cpio指令.cpio用到的参数'c'代表用新的SVR4可移植格式.'o'代表建立文件.最后用gzip以最佳的压缩效率'-9'压缩(默认是-6),使用'>

'Export.

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, last modified: Tue May 14 13:50:26 2013, max compression

two。 Copy the file to / boot/. The restart of the machine takes effect.

In addition, the boot flow after the initrd is loaded by kernel is based on an init file in the initrd file, and the script provided by it is done step by step, 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:

# Note that this only becomes / dev on the real filesystem if udev's scripts

# are used; which they will 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

.

This is the answer to the question about how to open the Initrd file system in the Linux system. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report