OpenSDE Packages Database (without history before r20070)
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.

184 lines
4.3 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: package/.../mkinitrd/mkinitrd.sh
  6. # Copyright (C) 2006 - 2008 The OpenSDE Project
  7. # Copyright (C) 2005 - 2006 The T2 SDE Project
  8. #
  9. # More information can be found in the files COPYING and README.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. set -e
  17. if [ $UID != 0 ]; then
  18. echo "Non root - exiting ..."
  19. exit 1
  20. fi
  21. while [ "$1" ]; do
  22. case $1 in
  23. [0-9]*) kernelver="$1" ;;
  24. -R) root="$2" ; shift ;;
  25. *) echo "Usage: mkinitrd [ -R root ] [ kernelver ]"
  26. exit 1 ;;
  27. esac
  28. shift
  29. done
  30. [ "$root" ] || root=
  31. [ "$kernelver" ] || kernelver=`uname -r`
  32. [ "$moddir" ] || moddir="${root}/lib/modules/$kernelver"
  33. echo "Kernel: $kernelver, module dir: $moddir"
  34. if [ ! -d $moddir ]; then
  35. echo "Module dir $moddir does not exist!"
  36. exit 2
  37. fi
  38. sysmap=
  39. [ -f "${root}/boot/System.map_$kernelver" ] && sysmap="${root}/boot/System.map_$kernelver"
  40. if [ -z "$sysmap" ]; then
  41. echo "System.map_$kernelver not found!"
  42. exit 2
  43. fi
  44. echo "System.map: $sysmap"
  45. # check needed tools
  46. for x in cpio gzip ; do
  47. if ! which $x >/dev/null ; then
  48. echo "$x not found!"
  49. exit 2
  50. fi
  51. done
  52. tmpdir=`mktemp`
  53. # create basic structure
  54. #
  55. rm -rf $tmpdir >/dev/null
  56. echo "Create dirtree ..."
  57. mkdir -p $tmpdir/{dev,bin,sbin,proc,sys,lib/modules,lib/udev,etc/hotplug.d/default}
  58. mknod $tmpdir/dev/console c 5 1
  59. # copy the basic / rootfs kernel modules
  60. #
  61. echo "Copying kernel modules ..."
  62. if [ -x /sbin/modinfo -a -x /sbin/depmod ]; then
  63. find $moddir/kernel -type f | grep \
  64. -e reiserfs -e reiser4 -e ext2 -e ext3 -e /jfs -e /xfs \
  65. -e isofs -e udf -e /unionfs -e ntfs -e fat -e dm-mod -e md-mod \
  66. -e /ide/ -e /ata/ -e /scsi/ -e /message/ -e hci \
  67. -e usb-storage -e sbp2 -e /md/raid \
  68. -e /block/ \
  69. -e drivers/net/ -e '/ipv6\.' |
  70. while read fn ; do
  71. for x in $fn `/sbin/modinfo $fn | grep depends |
  72. cut -d : -f 2- | sed -e 's/ //g' -e 's/,/ /g' `
  73. do
  74. # expand to full name if it was a depend
  75. [ $x = ${x##*/} ] &&
  76. x=`find $moddir/kernel -name "$x.*o"`
  77. echo -n "${x##*/} "
  78. # strip $root prefix
  79. xt=${x##$root}
  80. mkdir -p `dirname $tmpdir/$xt`
  81. cp $x $tmpdir/$xt 2>/dev/null
  82. done
  83. done | fold -s ; echo
  84. # generate map files
  85. #
  86. /sbin/depmod -ae -b $tmpdir -F $sysmap $kernelver
  87. else
  88. echo "ERROR: modinfo or depmod are missing in your installation."
  89. exit 1
  90. fi
  91. echo "Injecting programs and configuration ..."
  92. # copying config
  93. #
  94. # group (needed by udev to resolve group names)
  95. cp -a ${root}/etc/group $tmpdir/etc/
  96. # udev
  97. cp -ar ${root}/etc/udev $tmpdir/etc/
  98. # in theory all, but fat and currently only cdrom_id is needed ...
  99. cp -ar ${root}/lib/udev/* $tmpdir/lib/udev/
  100. # setup programs
  101. #
  102. for x in ${root}/sbin/{udevd,udevtrigger,udevsettle,modprobe,insmod} ${root}/usr/sbin/disktype
  103. do
  104. # sanity check
  105. file $x | grep -q "dynamically linked" &&
  106. echo "Warning: $x is dynamically linked!"
  107. cp $x $tmpdir/sbin/
  108. done
  109. x=${root}/sbin/insmod.old
  110. if [ ! -e $x ]; then
  111. echo "Warning: Skipped optional file $x!"
  112. else
  113. file $x | grep -q "dynamically linked" &&
  114. echo "Warning: $x is dynamically linked!"
  115. cp $x $tmpdir/sbin/
  116. ln -s insmod.old $tmpdir/sbin/modprobe.old
  117. fi
  118. ln -s /sbin/udev $tmpdir/etc/hotplug.d/default/10-udev.hotplug
  119. cp ${root}/bin/pdksh $tmpdir/bin/sh
  120. # static, tiny embutils and friends
  121. #
  122. for x in mount umount rm mv cp mkdir ln ls switch_root sleep losetup chmod cat sed mknod
  123. do
  124. if [ -x $root/usr/embutils/$x ]; then
  125. x=$root/usr/embutils/$x
  126. elif [ -x $root/usr/bin/$x ]; then
  127. x=$root/usr/bin/$x
  128. elif [ -x $root/bin/$x ]; then
  129. x=$root/bin/$x
  130. else
  131. echo "Error: $x was not found!" 1>&2
  132. false
  133. fi
  134. # sanity check
  135. file $x | grep -q "dynamically linked" &&
  136. echo "Warning: $x is dynamically linked!"
  137. cp $x $tmpdir/bin/
  138. done
  139. cp ${root}/sbin/initrdinit $tmpdir/init
  140. # create the cpio image
  141. #
  142. echo "Archiving ..."
  143. ( cd $tmpdir
  144. find * | cpio -o -H newc | gzip -c9 > ${root}/boot/initrd-$kernelver.img
  145. )
  146. # display the resulting image
  147. #
  148. du -sh ${root}/boot/initrd-$kernelver.img
  149. rm -rf $tmpdir