Introduction to initramfs and initrd
_In the / boot directory, there is usually a / boot/initrd.img file or a / boot/initramfs.img file.
_There are two questions now. The first one is why you need initrd or initramfs? The answer is, to reduce the size of the Linux kernel (Kernel). The Linux kernel executes the init process after initialization, and the init process mounts the root file system, but since the init program is also on the root file system, this is a paradox.(You can see about the Linux boot process First in this series )Linux uses a two-step approach to solve this problem. Previous to Linux version 2.6, there was a separate initrd.img image file in addition to the kernel vmlinuz, which was actually a file system image. The Linux kernel initially mounts initrd.img as a temporary root file system, and the init process is in initrd.img, then the init process hangsLoad the real root file system, then u mount initrd.img. But the Linux 2.6 kernel does not implement the same way, although it does the same thing. Linux 2.6 uses initramfs. initramfs:init ram filesystem, which is a cpio-formatted memory file system.
_The second question is what format the initrd and initramfs files are and how to create and open them. In fact, in the history of Linux, the in-memory file systems used different technologies. In very old systems, a block of memory was emulated as a disk, called a disk.RamDisk, which is inefficient because after emulating memory as a disk, you still need to treat it like a disk, create a file system with a specific format for it, use the kernel's cache system when reading or writing files, and have two (nests) of the same data in memory.The initrd file used in the old system is actually a mirror of a disk, so to read or write its contents, you need to hang it on the system and then read and write it. As mentioned above, on Linux 2.6, initrd has been initramfsInstead, although initrd.img is still used as the filename in many systems, it is actually the initramfs technology. The initramfs technology does not use RamDisk, but uses tempfs, which reuses the cache system in the kernel, so TEMPFSOnly one part of the content in memory exists, that is, in the kernel cache, not only saves memory overhead, but also improves efficiency.
_After GRUB gives control to the kernel, the usual step is to start the kernel first, then mount initrd.img in the kernel, execute the init process in initrd.img, hang it on the real root file system, and then execute/sbin/init. Without initrd.img, the first process (/sbin/init) cannot start when the computer starts.
Open Watch initramfs File
_initramfs files are saved in the compressed CPIO format in the system and opened with cat initramfs.img | cpio-imd with the following folder structure:whichrpm
_Found that there are only a few files, but the size of the unzipped file is much smaller than that of the original file, so guess that the unzipped file is not completely unzipped.
_The articles on the Internet are all copies of.img with cp and a suffix of.gz, then gunzip to decompress the file, and then cpio-imd to decompress the.img file, but the decompression result is the same as above, it is not completely decompressed!!!
_I tried to use which mkinitramfs to discover that ubuntu has this mkinitramfs directive, so its kernel file should have been created with this directive, so I tried to unmkinitramfs to unzip this.img file, but found that ubuntu does not have this directive.
_Trying to find a way on the Internet, I see a similar problem in an article. Netizen's Fedora 21 system uses the latest Early User Space technology, which prevents CPIO from fully extracting files. So he can use the lsinitrd tool provided in the dracut package to view the contents of initramfs and find that it needs a skipcpio program to skip initramfsAfter the header of the file, unpack the rest as a compressed CPIO file. Finally, use the sudo/usr/lib/dracut/skipcpio initramfs.img | zcat | cpio-imd directive to complete the decompression. But I am ubuntu16.04 and do not have this directive either.
Ultimately, I found the ubuntu version of the pot. I upgraded from 16.04 to 18.04 and then had the unmkinitramfs command!
_The complete folder structure after decompression is as follows:
initrdramfs/ ├── early │ └── kernel │ └── x86 │ └── microcode │ └── AuthenticAMD.bin └── main ├── bin │ ├── [ │ ├── [[ │ ├── acpid │ ├── ash │ ├── awk │ ├── basename │ ├── blockdev │ ├── busybox │ ├── cat │ ├── chmod │ ├── chroot │ ├── chvt │ ├── clear │ ├── cmp │ ├── cp │ ├── cpio │ ├── cut │ ├── date │ ├── dd │ ├── deallocvt │ ├── devmem │ ├── df │ ├── dmesg │ ├── dnsdomainname │ ├── du │ ├── dumpkmap │ ├── echo │ ├── egrep │ ├── env │ ├── expr │ ├── false │ ├── fbset │ ├── fdflush │ ├── fgrep │ ├── find │ ├── fstrim │ ├── fstype │ ├── grep │ ├── gunzip │ ├── gzip │ ├── halt │ ├── hostname │ ├── hwclock │ ├── ifconfig │ ├── ip │ ├── ipconfig │ ├── kbd_mode │ ├── kill │ ├── kmod │ ├── ln │ ├── loadfont │ ├── loadkeys │ ├── loadkmap │ ├── losetup │ ├── ls │ ├── lzop │ ├── lzopcat │ ├── minips │ ├── mkdir │ ├── mkfifo │ ├── mknod │ ├── mkswap │ ├── mktemp │ ├── modinfo │ ├── more │ ├── mount │ ├── mv │ ├── nfsmount │ ├── ntfs-3g │ ├── nuke │ ├── openvt │ ├── pidof │ ├── pivot_root │ ├── plymouth │ ├── poweroff │ ├── printf │ ├── ps │ ├── pwd │ ├── readlink │ ├── reboot │ ├── reset │ ├── resume │ ├── rm │ ├── rmdir │ ├── run-init │ ├── run-parts │ ├── sed │ ├── seq │ ├── setfont │ ├── setkeycodes │ ├── sh │ ├── sleep │ ├── sort │ ├── stat │ ├── static-sh │ ├── stty │ ├── switch_root │ ├── sync │ ├── tail │ ├── tee │ ├── test │ ├── touch │ ├── tr │ ├── true │ ├── tty │ ├── udevadm │ ├── umount │ ├── uname │ ├── uniq │ ├── unlzop │ ├── wc │ ├── wget │ ├── which │ ├── yes │ └── zcat ├── conf │ ├── arch.conf │ ├── conf.d │ │ └── resume │ └── initramfs.conf ├── etc │ ├── console-setup │ │ ├── cached.kmap.gz │ │ └── Uni2-Fixed16.psf.gz │ ├── default │ │ ├── console-setup │ │ └── keyboard │ ├── dhcp │ │ ├── dhclient.conf │ │ └── dhclient-enter-hooks.d │ │ └── config │ ├── e2fsck.conf │ ├── fonts │ │ ├── conf.d │ │ │ └── 60-latin.conf │ │ └── fonts.conf │ ├── fstab │ ├── ld.so.cache │ ├── ld.so.conf │ ├── ld.so.conf.d │ │ ├── fakeroot-x86_64-linux-gnu.conf │ │ ├── libc.conf │ │ ├── vmware-tools-libraries.conf │ │ ├── x86_64-linux-gnu.conf │ │ ├── x86_64-linux-gnu_EGL.conf -> /etc/alternatives/x86_64-linux-gnu_egl_conf │ │ └── x86_64-linux-gnu_GL.conf -> /etc/alternatives/x86_64-linux-gnu_gl_conf │ ├── lvm │ │ └── lvm.conf │ ├── modprobe.d │ │ ├── alsa-base.conf │ │ ├── amd64-microcode-blacklist.conf │ │ ├── blacklist-ath_pci.conf │ │ ├── blacklist.conf │ │ ├── blacklist-firewire.conf │ │ ├── blacklist-framebuffer.conf │ │ ├── blacklist-modem.conf │ │ ├── blacklist-oss.conf -> /lib/linux-sound-base/noOSS.modprobe.conf │ │ ├── blacklist-rare-network.conf │ │ ├── blacklist-watchdog.conf │ │ ├── fbdev-blacklist.conf │ │ ├── intel-microcode-blacklist.conf │ │ ├── iwlwifi.conf │ │ └── mlx4.conf │ ├── mtab -> /proc/mounts │ ├── nsswitch.conf │ ├── os-release │ ├── passwd │ ├── plymouth │ └── udev │ └── udev.conf ├── init ├── lib │ ├── brltty │ │ └── brltty.sh │ ├── klibc-k3La8MUnuzHQ0_kG8hokcGAC0PA.so │ ├── libnss_files-2.23.so │ ├── libnss_files.so.2 -> libnss_files-2.23.so │ ├── modprobe.d │ │ ├── aliases.conf │ │ ├── blacklist_linux-hwe_4.15.0-112-generic.conf │ │ └── blacklist_linux-hwe_4.15.0-142-generic.conf │ ├── modules │ │ └── initramfs.img-0.1 │ ├── systemd │ │ ├── network │ │ │ └── 99-default.link │ │ └── systemd-udevd │ ├── udev │ │ ├── ata_id │ │ ├── rules.d │ │ │ ├── 50-firmware.rules │ │ │ ├── 50-udev-default.rules │ │ │ ├── 55-dm.rules │ │ │ ├── 56-lvm.rules │ │ │ ├── 60-persistent-storage-dm.rules │ │ │ ├── 60-persistent-storage.rules │ │ │ ├── 61-persistent-storage-android.rules │ │ │ ├── 69-lvm-metad.rules │ │ │ ├── 70-snap.core.rules │ │ │ ├── 73-special-net-names.rules │ │ │ ├── 73-usb-net-by-mac.rules │ │ │ ├── 75-net-description.rules │ │ │ ├── 80-drivers.rules │ │ │ ├── 80-net-setup-link.rules │ │ │ └── 99-vmware-scsi-udev.rules │ │ └── scsi_id │ └── x86_64-linux-gnu │ ├── ld-2.23.so │ ├── ld-linux-x86-64.so.2 -> ld-2.23.so │ ├── libacl.so.1 -> libacl.so.1.1.0 │ ├── libacl.so.1.1.0 │ ├── libattr.so.1 -> libattr.so.1.1.0 │ ├── libattr.so.1.1.0 │ ├── libaudit.so.1 -> libaudit.so.1.0.0 │ ├── libaudit.so.1.0.0 │ ├── libblkid.so.1 -> libblkid.so.1.1.0 │ ├── libblkid.so.1.1.0 │ ├── libc-2.23.so │ ├── libcom_err.so.2 -> libcom_err.so.2.1 │ ├── libcom_err.so.2.1 │ ├── libc.so.6 -> libc-2.23.so │ ├── libdevmapper-event.so.1.02.1 │ ├── libdevmapper.so.1.02.1 │ ├── libdl-2.23.so │ ├── libdl.so.2 -> libdl-2.23.so │ ├── libdns-export.so.162 -> libdns-export.so.162.1.3 │ ├── libdns-export.so.162.1.3 │ ├── libe2p.so.2 -> libe2p.so.2.3 │ ├── libe2p.so.2.3 │ ├── libexpat.so.1 -> libexpat.so.1.6.0 │ ├── libexpat.so.1.6.0 │ ├── libext2fs.so.2 -> libext2fs.so.2.4 │ ├── libext2fs.so.2.4 │ ├── libglib-2.0.so.0 -> libglib-2.0.so.0.4800.2 │ ├── libglib-2.0.so.0.4800.2 │ ├── libisc-export.so.160 -> libisc-export.so.160.0.0 │ ├── libisc-export.so.160.0.0 │ ├── libkmod.so.2 -> libkmod.so.2.3.0 │ ├── libkmod.so.2.3.0 │ ├── libm-2.23.so │ ├── libmount.so.1 -> libmount.so.1.1.0 │ ├── libmount.so.1.1.0 │ ├── libm.so.6 -> libm-2.23.so │ ├── libnss_files-2.23.so │ ├── libnss_files.so.2 -> libnss_files-2.23.so │ ├── libntfs-3g.so.861 -> libntfs-3g.so.861.0.0 │ ├── libntfs-3g.so.861.0.0 │ ├── libpcre.so.3 -> libpcre.so.3.13.2 │ ├── libpcre.so.3.13.2 │ ├── libply.so.4 -> libply.so.4.0.0 │ ├── libply.so.4.0.0 │ ├── libply-splash-core.so.4 -> libply-splash-core.so.4.0.0 │ ├── libply-splash-core.so.4.0.0 │ ├── libply-splash-graphics.so.4 -> libply-splash-graphics.so.4.0.0 │ ├── libply-splash-graphics.so.4.0.0 │ ├── libpng12.so.0 -> libpng12.so.0.54.0 │ ├── libpng12.so.0.54.0 │ ├── libpthread-2.23.so │ ├── libpthread.so.0 -> libpthread-2.23.so │ ├── libreadline.so.5 -> libreadline.so.5.2 │ ├── libreadline.so.5.2 │ ├── librt-2.23.so │ ├── librt.so.1 -> librt-2.23.so │ ├── libselinux.so.1 │ ├── libtinfo.so.5 -> libtinfo.so.5.9 │ ├── libtinfo.so.5.9 │ ├── libudev.so.1 -> libudev.so.1.6.4 │ ├── libudev.so.1.6.4 │ ├── libuuid.so.1 -> libuuid.so.1.3.0 │ ├── libuuid.so.1.3.0 │ ├── libz.so.1 -> libz.so.1.2.8 │ └── libz.so.1.2.8 ├── lib64 │ └── ld-linux-x86-64.so.2 -> ../lib/x86_64-linux-gnu/ld-2.23.so ├── run ├── sbin │ ├── blkid │ ├── brltty-setup │ ├── dhclient │ ├── dhclient-script │ ├── dmsetup │ ├── dumpe2fs │ ├── e2fsck │ ├── fsck │ ├── fsck.ext4 -> e2fsck │ ├── hwclock │ ├── logsave │ ├── lvm │ ├── modprobe -> /bin/kmod │ ├── mount.fuse │ ├── mount.ntfs -> /bin/ntfs-3g │ ├── mount.ntfs-3g -> /bin/ntfs-3g │ ├── plymouthd │ ├── rmmod -> /bin/kmod │ ├── udevadm -> /bin/udevadm │ ├── vgchange -> lvm │ └── wait-for-root ├── scripts │ ├── functions │ ├── init-bottom │ │ ├── lvm2 │ │ ├── ORDER │ │ ├── plymouth │ │ └── udev │ ├── init-premount │ │ ├── brltty │ │ ├── lvm2 │ │ ├── ORDER │ │ └── plymouth │ ├── init-top │ │ ├── all_generic_ide │ │ ├── blacklist │ │ ├── brltty │ │ ├── console_setup │ │ ├── framebuffer │ │ ├── keymap │ │ ├── ORDER │ │ └── udev │ ├── local │ ├── local-block │ │ ├── cryptroot │ │ ├── lvm2 │ │ └── ORDER │ ├── local-bottom │ │ ├── cryptopensc │ │ ├── ntfs_3g │ │ └── ORDER │ ├── local-premount │ │ ├── fixrtc │ │ ├── ntfs_3g │ │ ├── ORDER │ │ └── resume │ ├── local-top │ │ ├── cryptopensc │ │ ├── cryptroot │ │ ├── lvm2 │ │ └── ORDER │ ├── nfs │ └── panic │ ├── console_setup │ ├── keymap │ ├── ORDER │ └── plymouth ├── usr │ ├── lib │ │ └── x86_64-linux-gnu │ │ ├── libcairo.so.2 -> libcairo.so.2.11400.6 │ │ ├── libcairo.so.2.11400.6 │ │ ├── libdatrie.so.1 -> libdatrie.so.1.3.3 │ │ ├── libdatrie.so.1.3.3 │ │ ├── libdrm.so.2 -> libdrm.so.2.4.0 │ │ ├── libdrm.so.2.4.0 │ │ ├── libffi.so.6 -> libffi.so.6.0.4 │ │ ├── libffi.so.6.0.4 │ │ ├── libfontconfig.so.1 -> libfontconfig.so.1.9.0 │ │ ├── libfontconfig.so.1.9.0 │ │ ├── libfreetype.so.6 -> libfreetype.so.6.12.1 │ │ ├── libfreetype.so.6.12.1 │ │ ├── libgobject-2.0.so.0 -> libgobject-2.0.so.0.4800.2 │ │ ├── libgobject-2.0.so.0.4800.2 │ │ ├── libgraphite2.so.3 -> libgraphite2.so.3.0.1 │ │ ├── libgraphite2.so.3.0.1 │ │ ├── libharfbuzz.so.0 -> libharfbuzz.so.0.10000.1 │ │ ├── libharfbuzz.so.0.10000.1 │ │ ├── libpango-1.0.so.0 -> libpango-1.0.so.0.3800.1 │ │ ├── libpango-1.0.so.0.3800.1 │ │ ├── libpangocairo-1.0.so.0 -> libpangocairo-1.0.so.0.3800.1 │ │ ├── libpangocairo-1.0.so.0.3800.1 │ │ ├── libpangoft2-1.0.so.0 -> libpangoft2-1.0.so.0.3800.1 │ │ ├── libpangoft2-1.0.so.0.3800.1 │ │ ├── libpixman-1.so.0 -> libpixman-1.so.0.33.6 │ │ ├── libpixman-1.so.0.33.6 │ │ ├── libthai.so.0 -> libthai.so.0.2.4 │ │ ├── libthai.so.0.2.4 │ │ ├── libX11.so.6 -> libX11.so.6.3.0 │ │ ├── libX11.so.6.3.0 │ │ ├── libXau.so.6 -> libXau.so.6.0.0 │ │ ├── libXau.so.6.0.0 │ │ ├── libxcb-render.so.0 -> libxcb-render.so.0.0.0 │ │ ├── libxcb-render.so.0.0.0 │ │ ├── libxcb-shm.so.0 -> libxcb-shm.so.0.0.0 │ │ ├── libxcb-shm.so.0.0.0 │ │ ├── libxcb.so.1 -> libxcb.so.1.1.0 │ │ ├── libxcb.so.1.1.0 │ │ ├── libXdmcp.so.6 -> libXdmcp.so.6.0.0 │ │ ├── libXdmcp.so.6.0.0 │ │ ├── libXext.so.6 -> libXext.so.6.4.0 │ │ ├── libXext.so.6.4.0 │ │ ├── libXrender.so.1 -> libXrender.so.1.3.0 │ │ ├── libXrender.so.1.3.0 │ │ └── plymouth │ │ ├── details.so │ │ ├── label.so │ │ ├── renderers │ │ │ ├── drm.so │ │ │ └── frame-buffer.so │ │ ├── script.so │ │ ├── text.so │ │ └── ubuntu-text.so │ └── share │ ├── fonts │ │ └── truetype │ │ └── dejavu │ │ ├── DejaVuSans.ttf │ │ └── DejaVuSerif.ttf │ └── plymouth │ ├── themes │ │ ├── default.plymouth -> /usr/share/plymouth/themes/ubuntu-logo/ubuntu-logo.plymouth │ │ ├── details │ │ │ └── details.plymouth │ │ ├── text.plymouth -> /usr/share/plymouth/themes/ubuntu-text/ubuntu-text.plymouth │ │ ├── ubuntu-logo │ │ │ ├── password-field16.png │ │ │ ├── password-field.png │ │ │ ├── progress-dot-off16.png │ │ │ ├── progress-dot-off.png │ │ │ ├── progress-dot-on16.png │ │ │ ├── progress-dot-on.png │ │ │ ├── ubuntu-logo16.png │ │ │ ├── ubuntu-logo.grub │ │ │ ├── ubuntu-logo.plymouth │ │ │ ├── ubuntu-logo.png │ │ │ ├── ubuntu-logo-scale-2.plymouth │ │ │ ├── ubuntu-logo-scale-2.script │ │ │ └── ubuntu-logo.script │ │ └── ubuntu-text │ │ ├── ubuntu-text.plymouth │ │ └── ubuntu-text.plymouth.in │ └── ubuntu-logo.png └── var ├── cache │ └── fontconfig └── lib └── dhcp 61 directories, 380 files