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.

88 lines
2.2 KiB

  1. #!/bin/sh
  2. kernel=`uname -r`
  3. tmpdir=`mktemp -d`
  4. modprobeopt=`echo $kernel | sed '/2.4/ { s,.*,-n,; q; }; s,.*,--show-depends,'`
  5. empty=0
  6. if [ "$1" = "empty" ]; then
  7. empty=1; shift
  8. fi
  9. if [ -n "$1" ]; then
  10. if [ -d "/lib/modules/$1" ]; then
  11. kernel="$1"
  12. else
  13. echo "Can't open /lib/modules/$1: No such directory."
  14. echo "Usage: $0 [ kernel-version ]"
  15. exit 1
  16. fi
  17. fi
  18. cat << 'EOT' > $tmpdir/linuxrc.c
  19. #include <unistd.h>
  20. #include <sys/types.h>
  21. #include <sys/wait.h>
  22. #include <stdio.h>
  23. int main()
  24. {
  25. EOT
  26. echo "Creating /boot/initrd-${kernel}.img ..."
  27. if [ "$empty" = 0 ]; then
  28. grep '^modprobe ' /etc/conf/kernel |
  29. grep -v 'no-initrd' | sed 's,[ ]#.*,,' |
  30. while read a b; do $a $modprobeopt -v $b 2> /dev/null; done |
  31. while read a b c; do
  32. # ouch - this is pretty ugly....
  33. b="${b//`uname -r`/$kernel}"
  34. if [ ! -f $tmpdir/${b##*/} ]; then
  35. echo "Adding $b."; cp $b $tmpdir
  36. x="$( eval "echo ${b##*/} $c" )"
  37. cat << EOT >> $tmpdir/linuxrc.c
  38. /* $x */
  39. if ( fork() ) wait(NULL);
  40. else {
  41. printf("initrd: loading %s.\n", "$x"); fflush(stdout);
  42. execl("/insmod.static", "/insmod.static", "${x// /", "}", NULL);
  43. _exit(1);
  44. }
  45. EOT
  46. fi
  47. done
  48. fi
  49. echo -e '\tprintf("initrd: going to re-mount root now.\\n");' >> $tmpdir/linuxrc.c
  50. echo -e '\treturn 0;\n}' >> $tmpdir/linuxrc.c
  51. gcc -s -static -Wall -Os -o $tmpdir/linuxrc $tmpdir/linuxrc.c
  52. cp /sbin/insmod.static* $tmpdir/
  53. if [ -f $tmpdir/insmod.static.old ]; then
  54. ln -s insmod.static.old $tmpdir/insmod.old
  55. fi
  56. mkdir -p $tmpdir/dev
  57. mknod $tmpdir/dev/null c 1 3
  58. mknod $tmpdir/dev/zero c 1 5
  59. mknod $tmpdir/dev/tty c 5 0
  60. mknod $tmpdir/dev/console c 5 1
  61. if false; then
  62. # FIXME: kernel doesn't like romfs as initrd ?!?!
  63. genromfs -f /boot/initrd-${kernel}.img.tmp -d $tmpdir
  64. else
  65. # This works, but only for initrd images < 4 MB
  66. dd if=/dev/zero of=/boot/initrd-${kernel}.img.tmp \
  67. count=4096 bs=1024 &> /dev/null
  68. mke2fs -m 0 -N 180 -F /boot/initrd-${kernel}.img.tmp &> /dev/null
  69. mntpoint="`mktemp -d`"
  70. mount -o loop /boot/initrd-${kernel}.img.tmp $mntpoint
  71. rmdir $mntpoint/lost+found/
  72. cp -a $tmpdir/* $mntpoint/
  73. umount -d $mntpoint
  74. rmdir $mntpoint
  75. fi
  76. gzip < /boot/initrd-${kernel}.img.tmp > /boot/initrd-${kernel}.img
  77. rm -f /boot/initrd-${kernel}.img.tmp
  78. rm -rf $tmpdir
  79. echo "Done."