A preliminary study on INITRD image files under Linux __linux

Source: Internet
Author: User

When we install a new kernel, we usually edit lilo.conf and grub.conf.
File. There is a "initrd=/boot/initrd-***.img" (the version number of the kernel) that we rarely notice, and sometimes we find this
One line does not boot properly. So what exactly is this initrd***.img for?
In fact, initrd***.img is a mirrored file, similar to RAMDisk, a piece of program packaged into the IMG, and then in the boot time in memory to open up a section of the area, is generally
2m, release
Put there to run, are some initialization of the program, such as Sisc_mod, Ext3, Sd_mod and other modules and Insmod, Nash and other commands. Different cores, the initialization of the IMG can
To the same, can also be different, if not, you can add no initrd in the grub.conf, it will skip the initrd detection and implementation, as if there was no before, later.
Its function is in the absence of Mount
/partitions before, the system would perform some operations, such as mounting a SCSI driver, which would release initrd into memory, make a virtual/, and then execute a script under its root directory
"LINUXRC", run Insmod and Nash command Mount module. Why is it that there are times when we do not join a LILO or grub configuration file to boot up the line properly? This is because
For our general PC machine does not use SCSI hard drives and so on need to load its drive device, so even if there is no initrd***.img can be normal boot. But if we're going to be on the server
To compile a new kernel for it then be sure not to forget to create a new INITRD file for it.
[color= "#ff3f00"] OK, let's see how to view the contents of initrd***.img and how to create a new initrd.img file for your new kernel.
[color= #a300a3] View initrd.img:
initrd***.img Although the suffix is "img", but in fact it is a file in GZ format, we can first unpack it, and then load mount to the directory:
1, CP initrd.img initrd.gz
2, Guzip initrd.gz
3, Mount-o Loop initrd/mnt/floppy
Entering the/mnt/floppy directory, we can see the initrd***.img file of the truth.
[color= "#a300a3"] make INITRD files
When we compile a new kernel, don't forget to do a new INITRD image for our SCSI device:
Grammar:
Directory name of MKINITRD filename kernel
Example:
MKINITRD initrd-2.4.19.img 2.4.19
The initrd-2.4.19.img file is arbitrary, but it is best to correspond to its own kernel version number.
2.4.19 is the directory name in the/lib/modules, corresponding to the kernel version.
Of course, we can also add a module directly to the/lib directory after the initrd***.img file is mounted, and then modify the LINUXRC script to mount it. But you must have the ability to have a certain shell script.
IBM Reference Documentation:

Http://www-128.ibm.com/developerworks/cn/linux/l-k26initrd/index.html


A preliminary study of INITRD image files under Linux Wu Zhangjin Creation in 2015/06/18 comments/sharing

Introduction by Falcon of TINYLAB.ORG2008/04/19 1

If you've made an embedded Linux file system, you should be more aware of what the INITRD image file is. INITRD that initial RAM disk, after the kernel decompression, after the real root filesystem is started, it is loaded into memory, do some system initialization operations, such as loading kernel modules, mount a new root file system.

The INITRD itself is a file that can be expanded into a file system when the kernel starts.

Prior to the 2.6 version of the kernel, INITRD was based on a special loop device that needed to be mounted through a loop device before it was launched into a file system, because it involved mount operations that involved some operational permissions. However, after the 2.6 version of the kernel appeared Initramfs, it and INITRD to achieve the same function, but it is based on a cpio file, without mount can be launched into a filesystem, thus eliminating the relevant permissions, the automation is more convenient.

A particularly interesting application of INITRD is a live CD, such as Knoppix, which launches an initialized file system via INITRD, and then mounts a special compressed file through a Cloop device and expands to a new Root file system so that a 700M of light Disk will be able to install a few G things, including most of the software and the corresponding kernel modules, and thus support a variety of functions. 2 Initrd/initramfs Production

The following is a brief introduction to the production process of these two initialization file systems (INITRD and INITRAMFS).

Prepare a test directory first.

        
        
         
         $ cd/tmp
         
         $ mkdir initrd
         
         $ mkdir initrd/loop Initrd/cpio
        
        
2.1 initrd (via a loop device)

A file of a specified size is generated first through the DD command. To calculate the size first, for example, to produce a 1M size file, you can set the file block size of 1024kbyte, and then get 1024 pieces.

        
        
         
         $ dd If=/dev/zero of=ramdisk bs=1024 count=1024
         
         $ ls-lh ramdisk
         
         -rw-r--r--1 Falcon Falcon 1.0M 2008-04-19 14:59 RAMDisk
         
         $ file RAMDisk
         
         Ramdisk:data
        
        

By getting such a file, you can format the file system as ext3 or as a ext2 file system.

        
        
         
         $ mkfs.ext2 ramdisk
         
         $ file RAMDisk
         
         Ramdisk:linux Rev 1.0 ext2 FileSystem data
        
        

If you want to add content to the filesystem (such as creating something automatically with BusyBox, or using the Linux root file system to manually create one from scratch) then you need to mount it through the Loop device.

However, when you need to mount the root user, so if you do not have the rights of the root user, it is inconvenient to do this job, from here you can see the benefits of the INITRAMFS introduced.

 $ mount ramdisk/mnt/-O loop 

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.