LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2007, 01:24 AM   #1
kkpal
Member
 
Registered: Oct 2007
Posts: 101

Rep: Reputation: 15
Question initrd.gz


How to I create initrd.gz file ? I wrote a init script, how can I convert that script in to initrd.gz file ?
 
Old 11-22-2007, 02:03 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The initrd file is either a compressed filesystem or a compressed cpio archive. It depends on the distro. You probaly have a "mkinitrd" script that your disto used to create it. Read it's manpage.

Given an intrd.gz file, use zcat to copy it uncompressed somewhere. Then check out what file says. If it is a filesystem, file will tell you what filesystem is used. Ext2 I think. My distro creates a cpio archive. Here is how I would access the contents:
Code:
mkdir ~/initrd
zcat boot/initrd-2.6.22.12-0.1-default >~/initrd-2.6.22.12-0.1-default.cpio
cd ~/initrd
cpio -idv <../initrd-2.6.22.12-0.1-default.cpio
Now the contents of initrd will be extracted and I can inspect and modify files there.
Reversing the process:
Code:
find . | cpio --quiet -c -o | gzip -9 -n > /boot/imagefile.img
If your system uses a filesystem for initrd, then uncompress the initrd-<version>.gz file; create a directory to mount it on, and mount it with the "loop" option. Now you can cd into the directory you created and make changes. When you are finished, umount the file and compress it.

see:
man mkinitrd
man initrd
/usr/src/linux/Documentation/initrd.txt

Last edited by jschiwal; 11-22-2007 at 02:09 AM.
 
Old 11-22-2007, 02:25 AM   #3
kkpal
Member
 
Registered: Oct 2007
Posts: 101

Original Poster
Rep: Reputation: 15
Exclamation

Quote:
Originally Posted by jschiwal View Post
The initrd file is either a compressed filesystem or a compressed cpio archive. It depends on the distro. You probaly have a "mkinitrd" script that your disto used to create it. Read it's manpage.

Given an intrd.gz file, use zcat to copy it uncompressed somewhere. Then check out what file says. If it is a filesystem, file will tell you what filesystem is used. Ext2 I think. My distro creates a cpio archive. Here is how I would access the contents:
Code:
mkdir ~/initrd
zcat boot/initrd-2.6.22.12-0.1-default >~/initrd-2.6.22.12-0.1-default.cpio
cd ~/initrd
cpio -idv <../initrd-2.6.22.12-0.1-default.cpio
Now the contents of initrd will be extracted and I can inspect and modify files there.
Reversing the process:
Code:
find . | cpio --quiet -c -o | gzip -9 -n > /boot/imagefile.img
If your system uses a filesystem for initrd, then uncompress the initrd-<version>.gz file; create a directory to mount it on, and mount it with the "loop" option. Now you can cd into the directory you created and make changes. When you are finished, umount the file and compress it.

see:
man mkinitrd
man initrd
/usr/src/linux/Documentation/initrd.txt



You are not understand my problem. I do not have initrd.gz. I want to create initrd.gz file. I wrote a script and i have to compress that script to make it an initrd.gz file.
 
Old 11-22-2007, 03:14 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The initrd ram disk should contain an entire filesystem. It needs more in it than just an init file.

Did you just compile a kernel? If so you need to run "make modules_install" and "make bzImage".

If you already have a kernel, your distro probably has a "mkinitrd" script that will create an initrd file adding needed modules. You can take that initrd file and modify it's /sbin/init script.

You may want to read the kernel source's "initrd.txt" file.
 
Old 11-22-2007, 04:41 AM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
We need to know which kernel you are using and then whether certain options are compiled into the kernel. If you are using a fairly new kernel from the 2.6 series, then it can only use initrd files which are a cpio archive. If it is an older 2.6 kernel or any 2.4 kernel then it can use an initrd which is a filesystem image -usually ext2, but it can also be cramfs.
Either way, the initrd must contain a couple of things -usually the initial script (or binary) which is run is called linuxrc. If it is a script then your initrd musr contain a shell which can execute the script and the initrd must also contain whaever programs are called by the script. The initrd must also contain at least one device file (/dev/console).
As mentioned, your distro probably includes a script for creating initrd's called mkinitrd. The best way to start is to create an initrd using that script and then tear it apart to see what's in there. Then you can change the contents however you like.
What kernel version are you running?
 
Old 11-22-2007, 05:10 AM   #6
kkpal
Member
 
Registered: Oct 2007
Posts: 101

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by gnashley View Post
We need to know which kernel you are using and then whether certain options are compiled into the kernel. If you are using a fairly new kernel from the 2.6 series, then it can only use initrd files which are a cpio archive. If it is an older 2.6 kernel or any 2.4 kernel then it can use an initrd which is a filesystem image -usually ext2, but it can also be cramfs.
Either way, the initrd must contain a couple of things -usually the initial script (or binary) which is run is called linuxrc. If it is a script then your initrd musr contain a shell which can execute the script and the initrd must also contain whaever programs are called by the script. The initrd must also contain at least one device file (/dev/console).
As mentioned, your distro probably includes a script for creating initrd's called mkinitrd. The best way to start is to create an initrd using that script and then tear it apart to see what's in there. Then you can change the contents however you like.
What kernel version are you running?

I am running kernel version 2.6.18-1.2798.fc6
 
Old 11-22-2007, 05:39 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you are using Fedora Core 6, the initrd file will be a compressed cpio archive.

There will be a nash script "init" in the root directory of initrd. There will also be a number of other files (~ 53) which may be needed as well. You might want to study this file and modify it to fit your needs.
 
Old 11-22-2007, 05:56 AM   #8
kkpal
Member
 
Registered: Oct 2007
Posts: 101

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
If you are using Fedora Core 6, the initrd file will be a compressed cpio archive.

There will be a nash script "init" in the root directory of initrd. There will also be a number of other files (~ 53) which may be needed as well. You might want to study this file and modify it to fit your needs.


I wrote init script for some other linux device. and I want to create initrd.gz file from my init script for that device.
 
Old 11-22-2007, 11:06 AM   #9
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
i presume you have that devices initrd.gz. you can copy that initrd.gz, extract and edit.
 
  


Reply



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
Failed to symbolic-link boot/initrd.img-2.6.18-4-486 to initrd.img Scotteh Linux - Software 8 06-01-2007 11:24 PM
initrd ashlesha Linux - Software 1 12-01-2006 04:57 PM
Initrd????? rm6990 Linux - Software 5 10-15-2004 03:32 AM
initrd tekbuz Debian 2 08-04-2004 12:34 PM
using initrd? e1000 Linux - General 4 02-19-2004 07:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:43 PM.

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
Open Source Consulting | Domain Registration