Removing bootsplash support since it hasn't been in a kernel we've supported for...
[genkernel.git] / gen_initrd.sh
index 1bfbf56407b776830238fbfe66402842a3f66ce7..005f5da204876deb418e5e540350d6b296aedd91 100644 (file)
@@ -3,23 +3,32 @@
 # create_initrd_loop(size)
 create_initrd_loop() {
        local inodes
-       [ "$#" -ne "1" ] && gen_die "invalid use of create_initrd_loop"
-       mkdir -p ${TEMP}/initrd-mount || gen_die "could not create loopback mount dir"
-       dd if=/dev/zero of=${TEMP}/initrd-loop bs=1k count=${1} >> "${DEBUGFILE}" 2>&1 || gen_die "could not zero initrd-loop"
-       mke2fs -F -N500 -q "${TEMP}/initrd-loop" >> "${DEBUGFILE}" 2>&1 || gen_die "could not format initrd-loop"
-       mount -t ext2 -o loop "${TEMP}/initrd-loop" "${TEMP}/initrd-mount" >> "${DEBUGFILE}" 2>&1 || gen_die "could not mount initrd filesystem"
+       [ "$#" -ne '1' ] && gen_die 'create_initrd_loop(): Not enough arguments!'
+       mkdir -p ${TEMP}/initrd-mount ||
+               gen_die 'Could not create loopback mount directory!'
+       dd if=/dev/zero of=${TMPDIR}/initrd-${KV} bs=1k count=${1} >> "${DEBUGFILE}" 2>&1 ||
+               gen_die "Could not zero initrd-${KV}"
+       mke2fs -F -N750 -q "${TMPDIR}/initrd-${KV}" >> "${DEBUGFILE}" 2>&1 ||
+               gen_die "Could not format initrd-${KV}!"
+       mount -t ext2 -o loop "${TMPDIR}/initrd-${KV}" "${TEMP}/initrd-mount" >> "${DEBUGFILE}" 2>&1 ||
+               gen_die 'Could not mount the initrd filesystem!'
 }
 
-create_initrd_unmount_loop()
-{
+create_initrd_unmount_loop() {
        cd ${TEMP}
-       umount "${TEMP}/initrd-mount" || gen_die "could not unmount initrd system"
+       umount "${TEMP}/initrd-mount" ||
+               gen_die 'Could not unmount initrd system!'
 }
 
-move_initrd_to_loop()
-{
+move_initrd_to_loop() {
        cd "${TEMP}/initrd-temp"
-       mv * "${TEMP}/initrd-mount" > ${DEBUGFILE}
+       mv * "${TEMP}/initrd-mount" >> ${DEBUGFILE} 2>&1
+}
+
+# check for static linked file with objdump
+is_static() {
+       LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
+       return $?
 }
 
 create_base_initrd_sys() {
@@ -30,63 +39,191 @@ create_base_initrd_sys() {
        mkdir -p ${TEMP}/initrd-temp/usr
        mkdir -p ${TEMP}/initrd-temp/proc
        mkdir -p ${TEMP}/initrd-temp/temp
+       mkdir -p ${TEMP}/initrd-temp/sys
        mkdir -p ${TEMP}/initrd-temp/.initrd
-       mkdir -p ${TEMP}/initrd-temp/new_root
-       mkdir -p ${TEMP}/initrd-temp/keymaps
+       mkdir -p ${TEMP}/initrd-temp/var/lock/dmraid
        ln -s bin ${TEMP}/initrd-temp/sbin
        ln -s ../bin ${TEMP}/initrd-temp/usr/bin
        ln -s ../bin ${TEMP}/initrd-temp/usr/sbin
-       echo "/dev/ram0     /           ext2    defaults" > ${TEMP}/initrd-temp/etc/fstab
+
+       echo "/dev/ram0     /           ext2    defaults        0 0" > ${TEMP}/initrd-temp/etc/fstab
        echo "proc          /proc       proc    defaults    0 0" >> ${TEMP}/initrd-temp/etc/fstab
 
-       echo "REGISTER        .*           MKOLDCOMPAT" > ${TEMP}/initrd-temp/etc/devfsd.conf
-       echo "UNREGISTER      .*           RMOLDCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
-       echo "REGISTER        .*           MKNEWCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
-       echo "UNREGISTER      .*           RMNEWCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
+       if [ "${NODEVFSD}" = '' ]
+       then
+               echo "REGISTER        .*           MKOLDCOMPAT" > ${TEMP}/initrd-temp/etc/devfsd.conf
+               echo "UNREGISTER      .*           RMOLDCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
+               echo "REGISTER        .*           MKNEWCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
+               echo "UNREGISTER      .*           RMNEWCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
+       fi
 
+       # SGI LiveCDs need the following binary (no better place for it than here)
+       # getdvhoff is a DEPEND of genkernel, so it *should* exist
+       if [ ${BUILD_INITRAMFS} -eq 1 ]
+       then
+               [ -e /usr/lib/getdvhoff/getdvhoff ] \
+                       && cp /usr/lib/getdvhoff/getdvhoff ${TEMP}/initrd-temp/bin \
+                       || gen_die "sys-boot/getdvhoff not merged!"
+       fi
 
        cd ${TEMP}/initrd-temp/dev
        MAKEDEV std
        MAKEDEV console
 
-       cp "${BUSYBOX_BINCACHE}" "${TEMP}/initrd-temp/bin/busybox.bz2" || gen_die "could not copy busybox from bincache"
-       bunzip2 "${TEMP}/initrd-temp/bin/busybox.bz2" || gen_die "could not uncompress busybox"
+       if [ "${DISKLABEL}" -eq '1' ]; then
+               cp "${BLKID_BINCACHE}" "${TEMP}/initrd-temp/bin/blkid.bz2" ||
+                       gen_die 'Could not copy blkid from bincache!'
+               bunzip2 "${TEMP}/initrd-temp/bin/blkid.bz2" ||
+                       gen_die 'Could not uncompress blkid!'
+               chmod +x "${TEMP}/initrd-temp/bin/blkid"
+       fi
+
+       cp "${BUSYBOX_BINCACHE}" "${TEMP}/initrd-temp/bin/busybox.tar.bz2" ||
+               gen_die 'Could not copy busybox from bincache!'
+       tar -xjf "${TEMP}/initrd-temp/bin/busybox.tar.bz2" -C "${TEMP}/initrd-temp/bin" busybox ||
+               gen_die 'Could not extract busybox bincache!'
        chmod +x "${TEMP}/initrd-temp/bin/busybox"
 
-       if [ "${NOINITRDMODULES}" = "" ]
+       # devfsd
+       if [ "${DEVFS}" -eq '1' ]
        then
-               if [ "${PAT}" -gt "4" ]
-               then
-                       cp "${MODULE_INIT_TOOLS_BINCACHE}" "${TEMP}/initrd-temp/bin/insmod.static.bz2" || gen_die "could not copy insmod.static from bincache"
-               else
-                       cp "${MODUTILS_BINCACHE}" "${TEMP}/initrd-temp/bin/insmod.static.bz2" || gen_die "could not copy insmod.static from bincache"
-               fi
+               cp "${DEVFSD_BINCACHE}" "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die 'Could not copy devfsd executable from bincache!'
+               bunzip2 "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die 'Could not uncompress devfsd!'
+               chmod +x "${TEMP}/initrd-temp/bin/devfsd"
+       fi
+
+       #unionfs modules
+       if [ "${UNIONFS}" -eq '1' ]
+       then
+               print_info 1 'UNIONFS MODULES: Adding support (compiling)...'
+               compile_unionfs_modules
+               /bin/tar -jxpf "${UNIONFS_MODULES_BINCACHE}" -C "${TEMP}/initrd-temp" ||
+                       gen_die "Could not extract unionfs modules binary cache!";
+       fi
+       
+       #unionfs utils
+       if [ "${UNIONFS}" -eq '1' ]
+       then
+               print_info 1 'UNIONFS TOOLS: Adding support (compiling)...'
+               compile_unionfs_utils
+               /bin/tar -jxpf "${UNIONFS_BINCACHE}" -C "${TEMP}/initrd-temp" ||
+                       gen_die "Could not extract unionfs tools binary cache!";
+       fi
 
-               bunzip2 "${TEMP}/initrd-temp/bin/insmod.static.bz2" || gen_die "could not uncompress insmod.static"
-               mv "${TEMP}/initrd-temp/bin/insmod.static" "${TEMP}/initrd-temp/bin/insmod"
-               chmod +x "${TEMP}/initrd-temp/bin/insmod"
+       # DMRAID 
+       if [ "${DMRAID}" = '1' ]
+       then
+               print_info 1 'DMRAID: Adding support (compiling binaries)...'
+               compile_dmraid
+               /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initrd-temp" ||
+                       gen_die "Could not extract dmraid binary cache!";
        fi
 
-       cp "${DEVFSD_BINCACHE}" "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die "could not copy devfsd executable from bincache"
-       bunzip2 "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die "could not uncompress devfsd"
-       chmod +x "${TEMP}/initrd-temp/bin/devfsd"
+       # LVM2
+       if [ "${LVM2}" = '1' ]
+       then
+               if [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable';
+               then
+                       print_info 1 'LVM2: Adding support (using local static binaries)...'
+                       cp /sbin/lvm "${TEMP}/initrd-temp/bin/lvm" ||
+                               gen_die 'Could not copy over lvm!'
+               else
+                       print_info 1 'LVM2: Adding support (compiling binaries)...'
+                       compile_lvm2
 
-# We make our own devfsd.conf these days, the default one doesn't work with the stripped
-# down devfsd we use with dietlibc
-#      cp "${DEVFSD_CONF_BINCACHE}" "${TEMP}/initrd-temp/etc/devfsd.conf.bz2" || gen_die "could not copy devfsd.conf from bincache"
-#      bunzip2 "${TEMP}/initrd-temp/etc/devfsd.conf.bz2" || gen_die "could not uncompress devfsd.conf"
+                       /bin/tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initrd-temp" ||
+                               gen_die "Could not extract lvm2 binary cache!";
+                       mv ${TEMP}/initrd-temp/bin/lvm.static ${TEMP}/initrd-temp/bin/lvm ||
+                               gen_die 'LVM2 error: Could not move lvm.static to lvm!'
+               fi
+               for i in vgchange vgscan; do
+                       ln  ${TEMP}/initrd-temp/bin/lvm ${TEMP}/initrd-temp/bin/$i ||
+                               gen_die "LVM2 error: Could not link ${i}!"
+               done
+               mkdir -p ${TEMP}/initrd-temp/etc/lvm
+               if [ -x /sbin/lvm ]
+               then
+#                      lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
+#                      ret=$?
+#                      if [ ${ret} != 0 ]
+#                      then
+                               cp /etc/lvm/lvm.conf "${TEMP}/initrd-temp/etc/lvm/" ||
+                                       gen_die 'Could not copy over lvm.conf!'
+#                      else
+#                              gen_die 'Could not copy over lvm.conf!'
+#                      fi
+               fi
+       fi
+       
+       # EVMS2
+       if [ "${EVMS2}" = '1' ]
+       then
+               if [ -e '/sbin/evms_activate' ]
+               then
+                       print_info 1 'EVMS2: Adding support...' 
+                       mkdir -p ${TEMP}/initrd-temp/lib
+                       mkdir -p ${TEMP}/initrd-temp/sbin
+                       mkdir -p ${TEMP}/initrd-temp/etc
+                       mkdir -p ${TEMP}/initrd-temp/bin
+                       cp -a /lib/ld-* "${TEMP}/initrd-temp/lib" \
+                               || gen_die 'Could not copy files for EVMS2!'
+                       if [ -n "`ls /lib/libgcc_s*`" ]
+                       then
+                               cp -a /lib/libgcc_s* "${TEMP}/initrd-temp/lib" \
+                                       || gen_die 'Could not copy files for EVMS2!'
+                       fi
+                       cp -a /lib/libc-* /lib/libc.* "${TEMP}/initrd-temp/lib" \
+                               || gen_die 'Could not copy files for EVMS2!'
+                       cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initrd-temp/lib" \
+                               || gen_die 'Could not copy files for EVMS2!'
+                       cp -a /lib/libpthread* "${TEMP}/initrd-temp/lib" \
+                               || gen_die 'Could not copy files for EVMS2!'
+                       cp -a /lib/libuuid*so* "${TEMP}/initrd-temp/lib" \
+                               || gen_die 'Could not copy files for EVMS2!'
+                       cp -a /lib/libevms*so* "${TEMP}/initrd-temp/lib" \
+                               || gen_die 'Could not copy files for EVMS2!'
+                       cp -a /lib/evms "${TEMP}/initrd-temp/lib" \
+                               || gen_die 'Could not copy files for EVMS2!'
+                       cp -a /lib/evms/* "${TEMP}/initrd-temp/lib/evms" \
+                               || gen_die 'Could not copy files for EVMS2!'
+                       cp -a /etc/evms.conf "${TEMP}/initrd-temp/etc" \
+                               || gen_die 'Could not copy files for EVMS2!'
+                       cp /sbin/evms_activate "${TEMP}/initrd-temp/sbin" \
+                               || gen_die 'Could not copy over evms_activate!'
+                       # Fix EVMS2 complaining that it cant find the swap utilities.
+                       # These are not required in the initrd
+                       for swap_libs in "${TEMP}/initrd-temp/lib/evms/*/swap*.so"
+                       do
+                               rm ${swap_libs}
+                       done
+               fi
+       fi      
 
        for i in '[' ash basename cat chroot clear cp dirname echo env false find \
-       grep gunzip gzip ln ls loadkmap losetup lsmod mkdir mknod more mount mv \
-       pivot_root ps awk pwd rm rmdir rmmod sh sleep tar test touch true umount uname \
-       xargs yes zcat chmod chown cut kill killall; do
+       grep gunzip gzip ln ls loadkmap losetup lsmod mdev mkdir mknod more mount \
+       mv pivot_root ps awk pwd rm rmdir rmmod sed sh sleep tar test touch true \
+       umount uname xargs yes zcat chmod chown cut kill killall; do
                rm -f ${TEMP}/initrd-temp/bin/$i > /dev/null
-               ln  ${TEMP}/initrd-temp/bin/busybox ${TEMP}/initrd-temp/bin/$i || gen_die "could not link ${i}"
+               ln  ${TEMP}/initrd-temp/bin/busybox ${TEMP}/initrd-temp/bin/$i ||
+                       gen_die "Busybox error: could not link ${i}!"
        done
+
+       if isTrue ${LUKS}
+       then
+               if is_static /bin/cryptsetup
+               then
+                       print_info 1 "Including LUKS support"
+                       rm -f ${TEMP}/initrd-temp/sbin/cryptsetup
+                       cp /bin/cryptsetup ${TEMP}/initrd-temp/sbin/cryptsetup
+                       chmod +x "${TEMP}/initrd-temp/sbin/cryptsetup"
+               else
+                       print_info 1 "LUKS support requires static cryptsetup at /bin/cryptsetup"
+                       print_info 1 "Not including LUKS support"
+               fi
+       fi
 }
 
-print_list()
-{
+print_list() {
        local x
        for x in ${*}
        do
@@ -95,43 +232,63 @@ print_list()
 }
 
 create_initrd_modules() {
+       local group
+       local group_modules
+       
        if [ "${PAT}" -gt "4" ]
        then
                MOD_EXT=".ko"
        else
                MOD_EXT=".o"
        fi
+
+       print_info 2 "initrd: >> Searching for modules..."
+
+       if [ "${INSTALL_MOD_PATH}" != '' ]
+       then
+               cd ${INSTALL_MOD_PATH}
+       else
+               cd /
+       fi
+                                                                                                       
        for i in `gen_dep_list`
        do
-               print_info 2 "$i : module searching" 1 0
-               mymod=`find /lib/modules/${KV} -name "${i}${MOD_EXT}"`
+               mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1`
                if [ -z "${mymod}" ]
                then
-                       print_info 2 "Warning : ${i}${MOD_EXT} not found; skipping..."
+                       print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
                        continue;
                fi
-               print_info 2 "copying ${mymod} to initrd"
+               print_info 2 "initrd: >> Copying ${i}${MOD_EXT}..."
                cp -ax --parents "${mymod}" "${TEMP}/initrd-temp"
        done
 
-       cp -ax --parents /lib/modules/${KV}/modules* ${TEMP}/initrd-temp
+       cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initrd-temp 2>/dev/null
 
        mkdir -p "${TEMP}/initrd-temp/etc/modules"
-       print_list ${SCSI_MODULES} > "${TEMP}/initrd-temp/etc/modules/scsi"
-       print_list ${FIREWIRE_MODULES} > "${TEMP}/initrd-temp/etc/modules/firewire"
-       print_list ${ATARAID_MODULES} > "${TEMP}/initrd-temp/etc/modules/ataraid"
-       print_list ${PCMCIA_MODULES} > "${TEMP}/initrd-temp/etc/modules/pcmcia"
-       print_list ${USB_MODULES} > "${TEMP}/initrd-temp/etc/modules/usb"
+       for group_modules in ${!MODULES_*}; do
+               group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
+               print_list ${!group_modules} > "${TEMP}/initrd-temp/etc/modules/${group}"
+       done
 }
 
 create_initrd_aux() {
-       if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
+       if [ -f "${CMD_LINUXRC}" ]
        then
-               cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initrd-temp/linuxrc"
-       else
-               cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initrd-temp/linuxrc"
+               cp "${CMD_LINUXRC}" "${TEMP}/initrd-temp/linuxrc"
+               print_info 2 "        >> Copying user specified linuxrc: ${CMD_LINUXRC}"
+       else    
+               if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
+               then
+                       cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initrd-temp/linuxrc"
+               else
+                       cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initrd-temp/linuxrc"
+               fi
        fi
 
+       # Make sure it's executable
+       chmod 0755 "${TEMP}/initrd-temp/linuxrc"
+
        if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
        then
                cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
@@ -145,18 +302,37 @@ create_initrd_aux() {
        else
                cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
        fi
+       
+       echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initrd-temp/etc/initrd.defaults" 
+       for group_modules in ${!MODULES_*}; do
+               group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
+               echo -n "${group} " >> "${TEMP}/initrd-temp/etc/initrd.defaults"
+       done
+       echo '"' >> "${TEMP}/initrd-temp/etc/initrd.defaults"   
+
        if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
        then
                cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
        else
                cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
        fi
+       if isTrue $CMD_DOKEYMAPAUTO
+       then
+               echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
+       fi
+       mkdir -p "${TEMP}/initrd-temp/lib/keymaps"
+       /bin/tar -C "${TEMP}/initrd-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
+       if isTrue $CMD_SLOWUSB
+       then
+               echo 'MY_HWOPTS="${MY_HWOPTS} slowusb"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
+       fi
 
+       cd ${TEMP}/initrd-temp/sbin && ln -s ../linuxrc init
+       cd ${OLDPWD}
        chmod +x "${TEMP}/initrd-temp/linuxrc"
        chmod +x "${TEMP}/initrd-temp/etc/initrd.scripts"
        chmod +x "${TEMP}/initrd-temp/etc/initrd.defaults"
        chmod +x "${TEMP}/initrd-temp/sbin/modprobe"
-
 }
 
 calc_initrd_size() {
@@ -169,51 +345,52 @@ calc_initrd_size() {
 create_initrd() {
        local MOD_EXT
 
-       print_info 1 "initrd: creating base system"
+       print_info 1 "initrd: >> Initializing..."
        create_base_initrd_sys
 
-       if [ "${NOINITRDMODULES}" = "" ]
+       if [ "${NOINITRDMODULES}" = '' ]
        then
-               print_info 1 "initrd: copying modules"
+               print_info 1 "        >> Copying modules..."
                create_initrd_modules
        else
-               print_info 1 "initrd: not copying modules"
+               print_info 1 "initrd: Not copying modules..."
        fi
 
-       print_info 1 "initrd: copying auxilary files"
+       print_info 1 "        >> Copying auxilary files..."
        create_initrd_aux
 
-       print_info 1 "initrd: calculating initrd size"
        INITRD_CALC_SIZE=`calc_initrd_size`
-
-       print_info 1 "initrd: calculated size ${INITRD_CALC_SIZE} + 100k slop for fs overhead"
-       INITRD_SIZE=`expr ${INITRD_CALC_SIZE} + 100`
-
-       print_info 1 "initrd: real size ${INITRD_SIZE}"
-
-       print_info 1 "initrd: creating loopback filesystem"
+       INITRD_SIZE=`expr ${INITRD_CALC_SIZE} + 250`
+       print_info 1 "        :: Size is at ${INITRD_SIZE}K"
+       print_info 1 "        >> Creating loopback filesystem..."
        create_initrd_loop ${INITRD_SIZE}
 
-       print_info 1 "initrd: moving initrd fs to loopback"
+       print_info 1 "        >> Moving initrd files to the loopback..."
        move_initrd_to_loop
 
-       print_info 1 "initrd: cleaning up and compressing initrd"
+       print_info 1 "        >> Cleaning up and compressing the initrd..."
        create_initrd_unmount_loop
 
        if [ "${COMPRESS_INITRD}" ]
        then
-               gzip -f -9 ${TEMP}/initrd-loop
-               mv ${TEMP}/initrd-loop.gz ${TEMP}/initrd-loop
+               gzip -f -9 ${TMPDIR}/initrd-${KV}
+               mv ${TMPDIR}/initrd-${KV}.gz ${TMPDIR}/initrd-${KV}
        fi
 
-       if [ "${BOOTSPLASH}" -eq "1" ]
+       if ! isTrue "${CMD_NOINSTALL}"
        then
-               print_info 1 "initrd: copying bootsplash"
-               /sbin/splash -s -f /etc/bootsplash/gentoo/config/bootsplash-800x600.cfg >> ${TEMP}/initrd-loop || gen_die "could not copy 800x600 bootsplash"
-               /sbin/splash -s -f /etc/bootsplash/gentoo/config/bootsplash-1024x768.cfg >> ${TEMP}/initrd-loop || gen_die "could not copy 1024x768 bootsplash"
-               /sbin/splash -s -f /etc/bootsplash/gentoo/config/bootsplash-1280x1024.cfg >> ${TEMP}/initrd-loop || gen_die "could not copy 1280x1024 bootsplash"
-               /sbin/splash -s -f /etc/bootsplash/gentoo/config/bootsplash-1600x1200.cfg >> ${TEMP}/initrd-loop || gen_die "could not copy 1600x1200 bootsplash"
+               copy_image_with_preserve "initrd" \
+                       "${TMPDIR}/initrd-${KV}" \
+                       "initrd-${KNAME}-${ARCH}-${KV}"
        fi
-       cp ${TEMP}/initrd-loop /boot/initrd-${KV} || gen_die "could not copy initrd to boot"
-}
 
+       # Pegasos hack for merging the initrd into the kernel at compile time
+       [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] ||
+               [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] &&
+               cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz &&
+               rm ${TMPDIR}/initrd-${KV}
+
+       # Mips also mimics Pegasos to merge the initrd into the kernel
+       [ ${BUILD_INITRAMFS} -eq 1 ] \
+               && cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/mips/ramdisk/initrd.img.gz
+}