The reference documentation for the INITRD is visible:
1) Linux initial RAM disk (INITRD) Overview, http://www.ibm.com/developerworks/linux/library/l-initrd/index.html
2) Nttdocomo-openstack/baremetal-initrd-builder, Https://github.com/NTTdocomo-openstack/baremetal-initrd-builder
2.1, Nash Command (a small file, built-in some practical instructions)
2,2 mount the main file system and build the file system required for the device file
Mount-t Proc/proc/proc
Mount-t Sysfs/sys/sys
2.2.1,PROCFS maps a virtual directory in memory that provides real-time information about the hardware and processes that can be changed at any time. Linux is guaranteed to be stable and does not allow access to files under/proc, and the root user is no exception.
2.2.2, SYSFS also maps a virtual directory in memory for the classification of hardware information, and each file in the SYS directory has only one character for the content to switch.
2.2.3, TMPFS also maps a virtual directory in memory, in-memory file system. If you want to be fast, you can choose to build the TMPFS type of file system in memory as it will be built into memory.
For example, a TMPFS partition is established in memory and mounted to the/MNT/TMPFS directory: mount-t tmpfs-o size=50m tmpfs/mnt/tmpfs/
[Email protected] proc]# df-h
Filesystem Size used Avail use% mounted on
Tmpfs 50M 0 50M 0%/mnt/tmpfs
2.2.4,/DEV/SHM, is a variant of TMPFS, TMPFS all of the content is in memory, and/DEV/SHM has a mapping in memory to the file system, both hard drives and memory.
Fast enough to store files larger than memory, but after rebooting, the content disappears.
The following shows the comparison of the speed at which files are built in/dev/shm with those in the common Ext4 file system:
[[Email protected] proc]# time DD If=/dev/zero of=/dev/shm/test.file bs=1m count=100
100+0 Records in
100+0 Records out
104857600 bytes (MB) copied, 0.0395221 S, 2.7 GB/s
Real 0m0.075s
User 0m0.001s
SYS 0m0.041s
[[Email protected] proc]# time DD If=/dev/zero of=/bak/test.file bs=1m count=100
100+0 Records in
100+0 Records out
104857600 bytes (MB) copied, 0.0647526 s, 1.6 GB/s
Real 0m0.090s
User 0m0.001s
SYS 0m0.066s
2.2.5,DEVFS, all devices will create a corresponding device file in the/dev directory.
The disadvantage is that, for example, even if the printer is not connected to the computer, the/dev/printer file will exist, which will cause too many devices in the INTRD phase, so DEVFS is being replaced by Udev.
For example, to use an optical drive, you need to associate it with the mount/dev/cdrom/mnt/command between Linux and the CD drive.
2.2.6, Udev, Udev can be placed in the/sys directory, do not need to all unused files to establish device files, no longer need to major number and minor number, when the hardware is loaded when the user set script executable.
For example, if/dev/cdrom was created by Udev, not DEVFS, the/dev/cdrom file disappears when the optical drive is removed.
2.2.7,/proc/pid file, the first process will correspond to a leap file
The 2.2.8,/proc/partitions is used to represent the detected hard disk information, and the major field represents the partition ID of the SCSI controller's slot Id,minor field.
#[[email protected] proc]# cat/proc/partitions
Major Minor #blocks name
8 0 488386584 SDA
8 1 82051956 sda1
2.2.9,/sys/block, block equipment
#[[email protected] proc]# cat/sys/block/
loop0/loop1/sda/sr0/
2.2.10,/dev/pts (pseudo terminal slave) sub-virtual terminal, its directory files are generated by the PTMX (primary virtual terminal), they are the parent-child relationship. When SSH is online to the localhost local side, it is
A file called "0" is produced in the/dev/pts directory and "1" appears when other consoles are using SSH to connect to the machine.
[[email protected] proc]# ps-ef|grep SSH
Hua 11186 3068 0 16:01 pts/0 00:00:00 ssh [email protected]
Hua 11195 11187 0 16:01? 00:00:00 sshd: [Email PROTECTED]/3
As above, when a user is logged in with SSH, the user is assigned a PTS resource (PTS/3) given by PTMX, so SSH uses a virtual terminal, not a real TTY interface. Telnet uses a true TTY interface.
2.2.11,/dev/mapper, if the use of LVM, Linux to deal with the hard disk is no longer directly using the hard disk device/proc/partitions, but use the device under/dev/mapper to relay.
# ls-l/dev/mapper/*
BRW-RW----1 root disk 253, 0 Jan 16.16/dev/mapper/vg0-lv0
# cat/proc/partitions
Major Minor #blocks name
8 0 17528 SDA
253 0 1111 dm-0
3. Create the device files you need to use initially
The device file is established using the MKNOD directive, which is used to establish a character (character) or block file (Mknod).
Example: Mknod/dev/tty1c41, set up a device file called Tty1, C is a character file, major=4, minor=1
4, loading the relevant modules
5, cut into the physical operating system on the hard drive indicated by image. (Rescue mode is a virtual operating system that loads the INITRD directly into the simple memory boot via the kernel)
5.1, mkrootdev-t ext4-o defaults.ro hda1, that is, the Nash command will be in the GRUB device root=xxx the XXX path First established
5.2, Mount/sysroot, mount the root path in grub to the/sysroot in INITRD.
5.3, Switchroot this Nash command switches the/sysroot file system in INITRD to/rootfs, thus switching to the file system on the hard disk.
Initramfs Workflow of Linux Systems