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.

87 lines
2.1 KiB

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