How Do I Make an initrd image?
Posted by ajt on Sun 13 Nov 2005 at 21:32
I have a Debian "sid" box installed onto a root partition on LVM2, boot is on hda. When I set it up originally everything went in well and it boots perfectly. The inital initrd created during install has all the right bits in and it boots and finds the root partition on the LVM2 without a problem. This works fine for both 2.4 and 2.6 family kernels.
Since installing it I've upgraded to the latest stock 2.6 "sid" kernel. When I try and boot from that kernel it dies with a kernel panic very quickly. I've tried creating an initrd with the standard mkinitrd tool and with that tool it boots a lot further, but still dies complaining about being unable to mount devfs.
What is the correct procedure to make a functioning initrd? It was able to make one during installation, why can't I make one now?
(I've done a Google search, but most of the hits are about LVM2+RAID, which I'm not doing.)
As ever, thanks in advance.
#336724 = http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=336724
#336418 = http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=336418
[ Parent | Reply to this comment ]
Okay, excluding the bug, how do I make an initrd then? Or will aptitude automatically build a proper one when it installs the kernel?
(For some reason my title line got mangled too, sorry for that as well - it looked okay in preview)
--
"It's Not Magic, It's Work"
Adam
[ Parent | Reply to this comment ]
cat <<eof>/etc/mkinitrd/scripts/include_hda.sh
#!/bin/sh
echo copying device files corresponding to lvm partitions
# actually copying all files associated with hard drive
cp -av /dev/hda* ${INITRDDIR}/dev/
echo done
EOF
chmod 755 /etc/mkinitrd/scripts/include_hda_devs.sh
my exact problem was that mkinitrd expects devfs to be used (and tries to mount devfs which fails), so no dev files are included in the initrd. but vgscan and vgchange need the dev files to "discover" your lvm physical volumes.
also, by default mkinitrd uses cramfs for the initrd, but historically the stock kernel (maybe just 2.4) didn't include cramfs. you can build an initrd of a specific filesystem type by setting MKIMAGE to the proper command within /etc/mkinitrd/mkinitrd.conf.
if that doesn't solve your problem, then you can do the following to enable further investigation:
apt-get install busybox
# set MODULES=ALL, DELAY=10, BUSYBOX=yes
editor /etc/mkinitrd/mkinitrd.conf
cat <<eof>/etc/mkinitrd/scripts/include_lvm_utils.sh
#!/bin/bash -xv
rm -f ${INITRDDIR}/sbin/{vgscan,vgchange}
cp {,${INITRDDIR}}/sbin/lvmiopversion
for FILE in /lib/lvm-10/*; do
cp ${FILE} ${INITRDDIR}/${FILE}
ln -s lvmiopversion ${INITRDDIR}/sbin/$(basename ${FILE})
done
EOF
chmod 755 /etc/mkinitrd/scripts/include_lvm_utils.sh
mkinitrd -k -o /boot/initrd.img-<version> <version>
-k is useful because if you want to inspect the contents of the initrd it is much easier to peruse the build directory than loop-mounting the initrd image.
for me version = 2.4.27-11+1-686 as that was the version of the corresponding kernel-image package i built with make-kpkg. (i really recommend make-kpkg though i've only ever used it to compile kernel-source packages, not stock kernels.)
when booting the initrd it should print a message similar to "pausing to allow user to interrupt the boot process by pressing enter". press enter. now start probing around the system. if your initrd is cramfs, which is read-only, and you want/need to create files, then you'll need to "mount tmpfs tmpfs /blah" to give you a writable directory (and lvm needs a writable /etc).
that worked for me, maybe it'll help you.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
"Strange. I've fixed it for the moment, but I'm not 100% sure what went wrong. I'll experiment, thanks for letting me know.
Steve"
[ Parent | Reply to this comment ]
root# make-kpkg clean && make-kpkg --initrd --revision=custom.1.0 kernel_image
after its finished with no errors, dpkg -i <kernel>.deb
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
below line at end of kernel argument in grub like...
----------------------------------------------------------------- -----------------
kernel /boot/vmlinuz-2.6.13 root=/dev/hda1 ro vga=791 splash=verbose
devfs=nomount
^^^^^^^^^^^^^
----------------------------------------------------------------- -----------------
Cheers,
Hardik Dalwadi.
[ Parent | Reply to this comment ]
you need that with kernel 2.6.12 and higer.
apt-get install udev
not long ago i did a dist-upgrade from sarge to sid
but because i did'nt had 2.6.12 or higer kernel
and no udev installed my system went crazy
i at last did a reinstall
and did you configure the files /etc/mkinird/
[ Parent | Reply to this comment ]
case in point: i have a sarge AMD64 server that i've tested with linux-source-2.6.12 from ubuntu's breezy. udev is not installed, but initrd-tools boots my raid1+lvm2 setup just fine with 2.6.12. devfs is enabled in the kernel (default ubuntu kernel config), but i have a static /dev as i don't use devfs (and i'm regretting using udev on my etch desktop as it's a pain to learn udev's configuration file format and it never seems to work "just right").
side note: why use ubuntu's 2.6.12 kernel? debian sarge's 2.6.8 kernel-image doesn't contain ata pass-through for sata drives to enable smart, but ubuntu's 2.6.12 does and ubuntu provides security support for it (and will continue for a minimum of 18 months).
[ Parent | Reply to this comment ]
if you do not use devfs, then the kernel has every right to expect dev to be already populate. but mkinitrd is expecting devfs, so /dev is minimally populated (with some symlinks to /devfs where i assume devfs would be mounted).
[ Parent | Reply to this comment ]
I am describing my Sarge setup; it has been running stably for long enough that some of the details are a bit fuzzy in my mind, but I'll try not to forget anything:
if you're using the make-kpkg, --initrd will do the right thing if you have configured a couple of non-obvious things first.
the contents of my /etc/kernel-img.conf:
do_initrd=yes
postinst_hook=/sbin/update-grub
postrm_hook=/sbin/update-grub
do_bootloader=no
mkimage=/usr/sbin/mkcramfs %s %s # very important
you are going to need the cramfsprogs, kernel-package, initrd-tools.
module-init-tools is required for 2.6 kernels (The first problem I had involved this; the error messages were not at all informative at that time, since maybe fixed)
udev is a REALLY good idea in my experience.
Remember, the initrd is created at kernel-image-xxx.deb install time.
In my experience, any errors at that stage tend to mean that the mkimage command didn't work or one of the initrd builder pieces is missing. For this step, dependencies don't help you, as the needed packages vary based on your /etc/kernel-img.conf.
So, get kernel ready for compile,
make-kpkg --initrd --append-to-version .example.001 buildpackage
wait a while
dpkg -i ../kernel-*{yourversion}.example.001*deb
Ignore a couple of scary prompts, if you haven't overridden them in the kernel-img.conf (modern kernels can handle cramfs, and depending on what kernel you're running right now you might possibly get a whole stack of missing symbol errors when depmod tries to match up the new modules with the currently-running kernel)
if it all looked like it worked, boot your computer and test it...
[ Parent | Reply to this comment ]
I was fighting with the same problem...
[ Parent | Reply to this comment ]
I finally installed "mkinitramfs" from the backports repository (http://www.backports.org). However, I had to force the installation after manually downloading the package as this version has some dependencies that can not be resolved even by using the backports.org repository. After this forced install I regenerated the initrd with "mkinitramfs" and everything went smoothly.
What I would do now and I think would completely solve the problem would be to first upgrade Sarge (3.1) to Etch (4.0) and then use the provided tools to upgrade the kernel ("mkinitramfs" comes with Etch). Depending on your setup this may or may not be applicable, however.
As always, YMMV.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
initramfs -o name_of_initrd kernel_version. That's all. Good Luck.
[ Parent | Reply to this comment ]