LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-21-2011, 03:03 AM   #1
samtoddler
Member
 
Registered: Jul 2011
Location: Delhi
Distribution: Cent OS/RHEL
Posts: 37

Rep: Reputation: Disabled
difference between initrd and vmlinuz images


Hi,

Can anyone tell me the difference between initrd images and vmlinuz images. I've gone through many documents,but didn't got an exact answer.

thanx
samtoddler
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 07-21-2011, 03:13 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296
Hello,

This post here at LQ explains it in very understandable terminology in my opinion: http://www.linuxquestions.org/questi...0/#post2920395.

Kind regards,

Eric
 
Old 07-21-2011, 03:25 AM   #3
samtoddler
Member
 
Registered: Jul 2011
Location: Delhi
Distribution: Cent OS/RHEL
Posts: 37

Original Poster
Rep: Reputation: Disabled
difference between initrd and vmlinuz images

Quote:
Originally Posted by EricTRA View Post
Hello,

This post here at LQ explains it in very understandable terminology in my opinion: http://www.linuxquestions.org/questi...0/#post2920395.

Kind regards,

Eric
thanx for comment
What if I've comipled all the modules required for the system in the kernel.Do I still need initird image.

thanx samtoddler
 
Old 07-21-2011, 04:00 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,207

Rep: Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951
No.
 
Old 07-21-2011, 04:07 AM   #5
samtoddler
Member
 
Registered: Jul 2011
Location: Delhi
Distribution: Cent OS/RHEL
Posts: 37

Original Poster
Rep: Reputation: Disabled
difference between initrd and vmlinuz images

Quote:
Originally Posted by syg00 View Post
No.
can you please tell me in more detail why is it so.
as far sa I know initrd is must because kernel is not in memory so make it in memory initrd provide basic modules to access the
filesystem and then load the kernel.

thanx
samtoddler
 
Old 07-21-2011, 08:10 AM   #6
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947Reputation: 947
No, syg00 is absolutely correct.

vmlinuz files contain the Linux kernel proper.

initrd files are CPIO images, filesystem images.

The boot loader is responsible for loading both the kernel image and the initrd image into memory. They both will be in memory, before the boot loader hands control over to the kernel.

The kernel will receive the address where the initrd is in memory; it will just "interpret" it as if it were a full filesystem, in RAM. (The kernel does actually decompress it first. CPIO is used, because it is simple and robust to implement, requires not too much code, and has all the features needed.)

You can extract an initrd image into current directory using
Code:
zcat /boot/initrd... | cpio -i
You can generate an image from the contents of the current directory and all subdirectories using
Code:
find . | cpio -o | gzip -c > /tmp/new-initrd
The image must be somewhere other than the current directory or any subdirectories, because otherwise cpio may include a partial copy of itself.

An initrd image will contain a script (or program) called /init (I keep the / in front to highlight that it will be in the root directory of the initrd image). That is the only real process the Linux kernel will start, whether an initrd is used or not. It will be process ID 1. If the process ever exits or crashes, kernel will panic -- but it is so rare you are unlikely to ever see that happen. (Okay, the kernel can start [worker processes], and even run /sbin/modprobe to load modules to satisfy module dependencies, I think, but they don't count. They're just slaves working on specific tasks.)

/init is almost always a POSIX shell script, so feel free to extract an image and read it in your favourite text editor. (An initrd /init will later on exec (replace itself) with the normal init, used during normal operation. If you look at your process list, you will always see process 1, named init.)

The main purpose for an initrd image is to prepare the system for the actual operating system, for example to load the modules the kernel should use. These kernel modules are included as files in the initrd image, usually in /lib/modules/kernelversion/ (again, starting from the root of the initrd image). The initrd will then also contain /sbin/modprobe and/or bin/insmod , /lib/ld-linux.so.2 ,and /lib/libc.so.6 , so that the script can load any kernel module it deems necessary.

First, however, /init will create a few additional directories, and mount the special filesystems. These include /proc, /sys, and usually also /dev (using the devtmpfs filesystem). Then, /init will parse the kernel command line, /proc/cmdline. This is the string you can set in the boot loader, defining how you want to start up your system.

It can then check files and directories in /proc, /sys, and /dev to find out which hardware is present and load the appropriate modules, but we have something much better: udev. udev is a hotplug mechanism, where the kernel tells the userspace udev daemon about all the hardware it finds, and about all hardware events later on, like when you plug in or remove something. udev configuration is ordered as rules, usually in /lib/udev/rules.d/, and it takes care of not only loading the necessary kernel modules, but also creating the necessary symlinks and all that.

It is quite possible to have a DHCP client in an initrd, and use for example NFS for all other filesystems. It is often used for thin clients. The kernel command line may then contain the NFS server name and the name for the machine itself, so it can obtain the correct filesystems. As you can see, that requires only a little thought, and a rather simple initrd, to set up and maintain. (Of course, something like this is impossible with most common proprietary operating systems.)

In Linux, resuming from a suspend-to-disk image (usually called "hibernation") is also done in the initrd. If the initrd detects a suspended image, it will resume it instead of continuing with the normal boot. In fact, there is even an utility called kexec, which can start another kernel altogether, without a full reboot (a "warm reboot").

initrd is, for all intents and purposes, a very small operating system image. It has the singular purpose of preparing the system for the actual operating system you want to use. Typically, it will mount the true root filesystem (named in the kernel command line) -- it must contain basic binaries (/bin and /sbin), libraries (/lib and possibly /lib64), and of course configuration files (/etc). Finally, the /init will replace itself with /sbin/init on the actual system, which will continue with mounting the rest of the filesystems, and starting all the services.

Many distros do require an initrd image, even if your kernel has everything built in, and does not support modules at all. In those cases, the initrd is expected to handle all of the other stuff mentioned above -- for example, starting udev, or looking for a hibernation image.

On other distros, an initrd is not needed, and the init scripts can handle the boot from raw kernel (plus root filesystem) up. For example, you can look at Linux From Scratch to see what those init scripts then have to handle.

The Linux kernel really does not care whether you have an initrd, or if your root filesystem can handle the entire init by itself. It is more of a matter of versatility and ease of management; most distributions have automatic scripts which regenerate initrds when new kernels are installed. If you use Busybox, you can pack a quite usable system into an initrd and be done with it -- many routers actually do that, with the initrd stored on a built-in flash chip.

Does this clarify the difference between initrd and vmlinuz for you?
 
4 members found this post helpful.
Old 07-21-2011, 08:35 AM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,207

Rep: Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951Reputation: 2951
Very nice explanation - may cause some confusion with regard to the different init being discussed; the initrd one and the "real" one . It should perhaps be added that the only requirement of an initrd is to ensure that all the necessary resources (modules) are available so the kernel can mount the root filesystem.
If it's all compiled in, not an issue - other external issues (hibernation, PXE ...) ignored.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tiny multipurpose vmlinuz + initrd RaptorX Linux - General 0 07-10-2009 03:18 PM
/vmlinuz /initrd.img links ninj4fly Linux - Newbie 4 02-19-2008 09:33 AM
creating vmlinuz and initrd on distribution media tkmsr Linux - Kernel 4 10-24-2007 02:13 PM
how to encrypt initrd.img and decrypt in vmlinuz. AshesOfTime Programming 1 12-09-2004 04:48 PM
booting vmlinuz/initrd from a bootloader bob_man_uk Linux - General 4 04-07-2004 10:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration