Patch to support initrd with dynamic ramdisks.

G.W. Wettstein (greg@wind.enjellic.com)
Thu, 5 Dec 1996 13:18:02 +0000


Good day to everyone on the linux-kernel mailing list. I really hate
to divert everyone's attention from kernel header dependency
generation and the proper API for hardware resources. Hopefully the
following will serve as a useful interlude... :-)

First of all thanks to Paul Gortmaker for his work on dynamic and
compressed ramdisk support. I am finding that his work makes single
boot/root/rescue disks once again feasible. Also thanks to Werner
Almesberger and Hans Lermen for their work on the initrd system. It
in combination with the dynamic ramdisk support has been very useful
in generating single disk starter systems.

As I was developing our starter disk system last week I ran into what
appears to be some inconsistencies between the initrd code and the
dynamic ramdisk code. After reviewing the sources it would appear
that the inconsistencies may have developed from the
dynamic/compressed ramdisk code developing on a parallel track from
the initrd code.

More specifically the stock kernels (2.0.27 tested) fail to recognize
and execute the /linuxrc configuration script when the kernels are
compiled with both ramdisk and initrd support. The following patch
seems to enable proper operation with minimalistic intervention:

Cut here to remove patch. -------------------------------------------------
diff -u --recursive --new-file v2.0.27/linux/init/main.c linux/init/main.c
--- v2.0.27/linux/init/main.c Mon Dec 2 10:18:20 1996
+++ linux/init/main.c Mon Dec 2 10:20:46 1996
@@ -926,7 +926,9 @@
real_root_dev = ROOT_DEV;
real_root_mountflags = root_mountflags;
if (initrd_start && mount_initrd) root_mountflags &= ~MS_RDONLY;
- else mount_initrd =0;
+ /* else mount_initrd =0;*/
+ else if ( !(mount_initrd && rd_doload) )
+ mount_initrd = 0;
#endif
setup();

@@ -959,6 +961,8 @@
if (mount_initrd && ROOT_DEV != real_root_dev && ROOT_DEV == MKDEV(RAMDISK_MAJOR,0)) {
int error;

+ if ( rd_doload )
+ real_root_dev = ROOT_DEV;
pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
if (pid>0)
while (pid != wait(&i));
Cut here to complete patch removal. ---------------------------------------

With this patch installed a kernel compiled with initrd support and
booted from a single floppy with a compressed ramdisk 'tagged' on the
end properly executes the /linuxrc configuration script. When the
linuxrc script exits the ramdisk remains mounted as root. The kernel
can be instructed to mount an alternate root by having the linuxrc
script write the major/minor number of the new root device to the
/proc/sys/kernel/real-root-dev pseudo-file.

There is a very real chance that this whole patch is borne from
operator error by my lack of understanding of the whole initrd
sequence. I have read the initrd and ramdisk documentation files
quite thoroughly and am convinced (in my mind) that the kernels
without this patch do not conform to the documentation.

As I noted above the patch correcting this is rather minimalistic and
conformant with the 'disturb as little as possible' philosophy of the
2.0.x series of kernels. I reviewed the kernel sources thoroughly in
working out this problem and it would appear that the initrd code
still has some major assumptions that the ramdisk will be allocated as
a fixed memory segment. A more complete solution to the problem that
I encountered may come from a review of both the initrd and ramdisk
code.

As I noted above I am far from an expert at these things and will
leave more extensive changes to Paul and Werner. I would also
appreciate any pointers if the above patch was borne out of a
misunderstanding of the workings of ramdisks and initrd.

With that said I am heading off for a cross-country ski with my golden
retriever. I hope that everyone has a pleasant end of the week.

Greg

As always,
Dr. G.W. Wettstein Velocity, LLC - Specialists in leveraging
4206 N. 19th Ave. inter-networking technology for enterprise groups.
Fargo, ND 58102
Phone: 701-281-1686 INTERNET: greg@wind.enjellic.com
------------------------------------------------------------------------------
"Attendants at a service station in Eunice, Louisiana, handed more than
$100 to a naked man who claimed to have a gun in his pocket."
-- Unknown