ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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
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:
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.
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.
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?
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.