Pages

Monday, June 5, 2017

What is VMLINUZ and Difference between VMLINUZ and INITRD

Difference between initrd and vmlinuz


vmlinuz:

vmlinuz is the name of the Linux kernel executable. vmlinuz is a compressed Linux kernel, and it loads the OS into memory so that the server becomes usable.

vmlinuz = Virtual Memory LINUx gZip = Compressed  Bootable Linux kernel Executable
vmlinux = Virtual Memory LINUX = Non-compressed Non-Bootable Linux Kernel Executable

At the head of the kernel image (vmlinuz) is a routine that does some minimal amount of hardware setup and then decompresses the kernel contained within the kernel image and places it into high memory. 

If an initial RAM disk image (initrd) is present, this routine moves it into memory (or we can say extract the compressed ramdisk image in to the real memory) and notes it for later use. The routine then calls the kernel and the kernel boot begins.



vmlinuz is located in the /boot directory, which is the directory that contains the files needed to begin booting the system. The file named vmlinuz might be the actual kernel executable itself, or it could be a link to the kernel executable, which might bear a name such as /boot/vmlinuz-2.4.18-19.8.0 (i.e., the name of the specific version of the kernel). This can be easily determined by using the ls command (whose purpose is to list the contents of a specified directory) with its -l option (which tells ls to provide detailed information about each object in the specified directory) as follows:

ls -l /boot

If vmlinuz is an ordinary file (including an executable), the information about it in the first column will begin with a hyphen. If it is a link, it will begin with the letter l.

The Linux kernel is compiled by issuing the following command:

make bzImage

This results in the creation of a file named bzImage in a directory such as /usr/src/linux/arch/i386/linux/boot/.

Compilation is the conversion the kernel's source code (i.e., the original form in which the kernel is written by a human) into object code (which is understandable directly by a computer's processor). It is performed by a specialized program called a compiler, usually one in the GCC (GNU Compiler Collection).

bzImage is then copied using the cp (i.e., copy) command to the /boot directory and simultaneously renamed vmlinuz with a command such as

cp /usr/src/linux/arch/i386/linux/boot/bzImage /boot/vmlinuz

vmlinuz is the name of the Linux kernel executable.

A kernel is a program that constitutes the central core of a computer operating system. It is the first thing that is loaded into memory (which physically consists of RAM chips) when a computer is booted up (i.e., started), and it remains in memory for the entire time that the computer is in operation. An executable, also called an executable file, is a file that can be run as a program.

vmlinux is generally just an intermediate step to producing vmlinuz.

initrd:

The initial RAM disk (initrd) is an initial root file system that is mounted prior to when the real rootfile system is available. The initrd is bound to the kernel and loaded as part of the kernel boot procedure. The kernel then mounts this initrd as part of the two-stage boot process to load the modules to make the real file systems available and get at the real root file system.

The initrd contains a minimal set of directories and executables to achieve this, such as the insmod tool to install kernel modules into the kernel.

Anatomy of the initrd:

The initrd image contains the necessary executables and system files to support the second-stageboot of a Linux system. Let see what inside the initrd image file:

Copy initrd image file into test directory & rename it as zip file & unzip that file.

Extract the uncompress initrd image file using cpio command:

Now you will have all the directory structure in the test directory looks like a root (/) file system.

Anatomy of the vmlinuz:

The vmlinuz itself is an executable binary file. Here we use readelf & objdump command to display information about BFD library, Object Header info etc. 
The vmlinuz file contains other things besides the gzipped content, so you need to find out where the gzipped content starts. To do that, use:
image
We are looking for 1f 8b 08 00, which can be found from character 12 onwards, or, at 0013920 + 12 (start counting from 0) = 13932.

Now that we know where the gzipped content starts (at position 13932)  you can use dd to extract that gzipped content and ungzip it.

No comments:

Post a Comment