Hack to make older bootcds create initrds. Uses mkinitrd shell script.
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Mon, 19 Feb 2007 21:07:42 +0000 (21:07 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Mon, 19 Feb 2007 21:07:42 +0000 (21:07 +0000)
source/mkinitrd.sh [new file with mode: 0644]
source/steps/MakeInitrd.py

diff --git a/source/mkinitrd.sh b/source/mkinitrd.sh
new file mode 100644 (file)
index 0000000..d9d7205
--- /dev/null
@@ -0,0 +1,163 @@
+#!/bin/sh
+# --- T2-COPYRIGHT-NOTE-BEGIN ---
+# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
+# 
+# T2 SDE: package/.../mkinitrd/mkinitrd.sh
+# Copyright (C) 2005 - 2006 The T2 SDE Project
+# 
+# More information can be found in the files COPYING and README.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License. A copy of the
+# GNU General Public License can be found in the file COPYING.
+# --- T2-COPYRIGHT-NOTE-END ---
+
+set -e
+
+if [ $UID != 0 ]; then
+       echo "Non root - exiting ..."
+       exit 1
+fi
+
+while [ "$1" ]; do
+  case $1 in
+       [0-9]*) kernelver="$1" ;;
+       -R) root="$2" ; shift ;;
+       *) echo "Usage: mkinitrd [ -R root ] [ kernelver ]"
+          exit 1 ;;
+  esac
+  shift
+done
+
+[ "$root" ] || root=""
+[ "$kernelver" ] || kernelver=`uname -r`
+[ "$moddir" ] || moddir="${root}/lib/modules/$kernelver"
+
+echo "Kernel: $kernelver, module dir: $moddir"
+
+if [ ! -d $moddir ]; then
+       echo "Module dir $moddir does not exist!"
+       exit 2
+fi
+
+sysmap=""
+[ -f "${root}/boot/System.map-$kernelver" ] && sysmap="${root}/boot/System.map-$kernelver"
+
+if [ -z "$sysmap" ]; then
+       echo "System.map_$kernelver not found!"
+       exit 2
+fi
+
+echo "System.map: $sysmap"
+
+# check needed tools
+#for x in cpio gzip ; do
+#      if ! which $x >/dev/null ; then
+#              echo "$x not found!"
+#              exit 2
+#      fi
+#done
+
+tmpdir=`mktemp`
+
+# create basic structure
+#
+rm -rf $tmpdir >/dev/null
+
+echo "Create dirtree ..."
+
+mkdir -p $tmpdir/{dev,bin,sbin,proc,sys,lib/modules,lib/udev,etc/hotplug.d/default}
+mknod $tmpdir/dev/console c 5 1
+
+# copy the basic / rootfs kernel modules
+#
+echo "Copying kernel modules ..."
+
+(
+  find $moddir/kernel -type f | grep \
+       -e reiserfs -e reiser4 -e ext2 -e ext3 -e /jfs -e /xfs \
+       -e isofs -e udf -e /unionfs -e ntfs -e fat -e dm-mod \
+       -e /ide/ -e /ata/ -e /scsi/ -e /message/ \
+       -e hci -e usb-storage -e sbp2 \
+       -e drivers/net/ -e '/ipv6\.' -e usbhid |
+  while read fn ; do
+
+       for x in $fn `modinfo $fn | grep depends |
+                cut -d : -f 2- | sed -e 's/ //g' -e 's/,/ /g' `
+       do
+               # expand to full name if it was a depend
+               [ $x = ${x##*/} ] &&
+               x=`find $moddir/kernel -name "$x.*o"`
+
+               echo -n "${x##*/} "
+
+               # strip $root prefix
+               xt=${x##$root}
+
+               mkdir -p `dirname $tmpdir/$xt`
+               cp $x $tmpdir/$xt 2>/dev/null
+       done
+  done
+) | fold -s ; echo
+
+# generate map files
+#
+/sbin/depmod -ae -b $tmpdir -F $sysmap $kernelver
+
+echo "Injecting programs and configuration ..."
+
+# copying config
+#
+cp -ar ${root}/etc/udev $tmpdir/etc/
+# in theory all, but fat and currently only cdrom_id is needed ...
+#cp -ar ${root}/lib/udev/cdrom_id $tmpdir/lib/udev/
+
+# setup programs
+#
+for x in ${root}/sbin/{hotplug,udevd,modprobe,insmod} 
+do
+       # sanity check
+       file $x | grep -q "dynamically linked" &&
+               echo "Warning: $x is dynamically linked!"
+       cp $x $tmpdir/sbin/
+done
+
+x=${root}/sbin/insmod.old
+if [ ! -e $x ]; then
+       echo "Warning: Skipped optional file $x!"
+else
+        file $x | grep -q "dynamically linked" &&
+                echo "Warning: $x is dynamically linked!"
+        cp $x $tmpdir/sbin/
+       ln -s insmod.old $tmpdir/sbin/modprobe.old
+fi
+
+ln -s /sbin/udev $tmpdir/etc/hotplug.d/default/10-udev.hotplug
+cp ${root}/bin/bash $tmpdir/bin/sh
+
+# static, tiny embutils and friends
+#
+#cp ${root}/usr/embutils/{mount,umount,rm,mv,mkdir,ln,ls,switch_root,sleep,losetup,chmod,cat,sed,mknod} \
+#   $tmpdir/bin/
+ln -s mv $tmpdir/bin/cp
+
+cp ${root}/sbin/init $tmpdir/init
+
+# Custom ACPI DSDT table
+if test -f "${root}/boot/DSDT.aml"; then
+       echo "Adding local DSDT file: $dsdt"
+       cp ${root}/boot/DSDT.aml $tmpdir/DSDT.aml
+fi
+
+# create the cpio image
+#
+echo "Archiving ..."
+( cd $tmpdir
+  find . | cpio -o -H newc | gzip -c9 > ${root}/boot/initrd-$kernelver.img
+)
+
+# display the resulting image
+#
+du -sh ${root}/boot/initrd-$kernelver.img
+rm -rf $tmpdir
index 4854da7..918af03 100644 (file)
@@ -11,6 +11,7 @@ import os, string
 from Exceptions import *
 import utils
 import systeminfo
+import shutil
 
 def Run( vars, log ):
     """
@@ -50,8 +51,22 @@ def Run( vars, log ):
 
     initrd, kernel_version= systeminfo.getKernelVersion(vars,log)
     utils.removefile( "%s/boot/%s" % (SYSIMG_PATH, initrd) )
-    utils.sysexec( "chroot %s mkinitrd -v /boot/initrd-%s.img %s" % \
+    if checkKern() == True:
+        utils.sysexec( "chroot %s mkinitrd -v /boot/initrd-%s.img %s" % \
                    (SYSIMG_PATH, kernel_version, kernel_version), log )
+    else:
+        shutil.copy("./mkinitrd.sh","%s/tmp/mkinitrd.sh" % SYSIMG_PATH)
+        os.chmod("%s/tmp/mkinitrd.sh" % SYSIMG_PATH, 755)
+        utils.sysexec( "chroot %s /tmp/mkinitrd.sh %s" % (SYSIMG_PATH, kernel_version))
 
     if fake_root_lvm == True:
         utils.removefile( "%s/%s" % (SYSIMG_PATH,PARTITIONS["mapper-root"]) )
+
+def checkKern():
+    #  Older bootcds only support LinuxThreads.  This hack is to get mkinitrd
+    #  to run without segfaulting by using /lib/obsolete/linuxthreads
+    kver = os.popen("/bin/uname -r", "r").readlines()[0].rstrip().split(".")
+    if int(kver[1]) > 4:
+        return True
+    elif int(kver[1]) <=4:
+        return False