mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.0 KiB

  1. #!/bin/bash
  2. kernel=`uname -r`
  3. tmpdir=`mktemp -d`
  4. if [ -n "$1" ]; then
  5. if [ -d "/lib/modules/$1" ]; then
  6. kernel="$1"
  7. else
  8. echo "Can't open /lib/modules/$1: No such directory."
  9. echo "Usage: $0 [ kernel-version ]"
  10. exit 1
  11. fi
  12. fi
  13. echo "Creating /boot/initrdnew-${kernel}.img ..."
  14. mkdir -p $tmpdir/etc/conf
  15. grep '^modprobe ' /etc/conf/kernel | grep -v 'no-initrd' | \
  16. sed 's,[ ]#.*,,' | \
  17. while read a b ; do
  18. b="`find /lib/modules/$kernel -name "$b.o" -o -name "$b.ko"`"
  19. echo "Adding $b."
  20. mkdir -p $tmpdir/${b%/*}
  21. cp $b $tmpdir/$b
  22. echo "/sbin/insmod $b $c" >> $tmpdir/etc/conf/kernel
  23. done
  24. mkdir -p $tmpdir/dev $tmpdir/root $tmpdir/tmp $tmpdir/proc $tmpdir/sys
  25. mknod $tmpdir/dev/ram0 b 1 0
  26. mknod $tmpdir/dev/null c 1 3
  27. mknod $tmpdir/dev/zero c 1 5
  28. mknod $tmpdir/dev/tty c 5 0
  29. mknod $tmpdir/dev/console c 5 1
  30. # this copies a set of programs and the necessary libraries into a
  31. # chroot environment
  32. echo -n "Checking necessary fsck programs ... "
  33. while read dev a mnt b fs c ; do
  34. [ -e "/sbin/fsck.${fs}" ] && echo "/sbin/fsck.${fs} /sbin/fsck.${fs}"
  35. done < <( mount ) | sort | uniq >/etc/conf/initrd/initrd_fsck
  36. echo "/sbin/fsck /sbin/fsck" >>/etc/conf/initrd/initrd_fsck
  37. echo "done"
  38. targetdir=$tmpdir
  39. programs="/bin/bash /bin/bash2 /bin/sh /bin/ls /sbin/pivot_root /sbin/insmod /sbin/insmod.old /bin/mount /bin/umount /usr/bin/chroot /etc/fstab /bin/mkdir"
  40. libs="/lib/ld-linux.so.2"
  41. for x in $programs ; do
  42. [ -e $x ] || continue
  43. mkdir -p $targetdir/${x%/*}
  44. cp -a $x $targetdir/$x
  45. file $x | grep -q ELF || continue
  46. libs="$libs `ldd $x 2>/dev/null | grep -v 'not a dynamic executable' | sed -e 's,^[\t ]*,,g' | cut -f 3 -d' '`"
  47. done
  48. for x in /etc/conf/initrd/initrd_* ; do
  49. [ -f $x ] || continue
  50. while read file target ; do
  51. if [ -d $file ] ; then
  52. find $file -type f | while read f ; do
  53. tfile=${targetdir}/${target}/${f#$file}
  54. [ -e $tfile ] && continue
  55. mkdir -p ${tfile%/*}
  56. cp $f $tfile
  57. libs="$libs `ldd $f 2>/dev/null | grep -v 'not a dynamic executable' | sed -e 's,^[\t ]*,,g' | cut -f 3 -d' '`"
  58. done
  59. fi
  60. [ -f $file ] || continue
  61. mkdir -p $targetdir/${target%/*}
  62. cp $file $targetdir/$target
  63. file $file | grep -q ELF || continue
  64. libs="$libs `ldd $file 2>/dev/null | grep -v 'not a dynamic executable' | sed -e 's,^[\t ]*,,g' | cut -f 3 -d' '`"
  65. done < $x
  66. done
  67. while [ -n "$libs" ] ; do
  68. oldlibs=$libs
  69. libs=""
  70. for x in $oldlibs ; do
  71. mkdir -p $targetdir/${x%/*}
  72. cp $x $targetdir/$x
  73. file $x | grep -q ELF || continue
  74. for y in `ldd $x 2>/dev/null | grep -v 'not a dynamic executable' | sed -e 's,^[\t ]*,,g' | cut -f 3 -d' '` ; do
  75. [ ! -e "$targetdir/$y" ] && libs="$libs $y"
  76. done
  77. done
  78. done
  79. itmp=`mktemp`
  80. dd if=/dev/zero of=${itmp} count=8192 bs=1024 > /dev/null 2>&1
  81. mke2fs -m 0 -N 5120 -F ${itmp} > /dev/null 2>&1
  82. mntpoint="`mktemp -d`"
  83. mount -o loop ${itmp} $mntpoint
  84. rmdir $mntpoint/lost+found/
  85. cp -a $tmpdir/* $mntpoint/
  86. umount -d $mntpoint
  87. rmdir $mntpoint
  88. gzip -9 < ${itmp} > /boot/initrdnew-${kernel}.img
  89. rm -f ${itmp}
  90. rm -rf $tmpdir
  91. echo "Done."