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.

194 lines
4.4 KiB

  1. #!/bin/sh
  2. # create initramfs image by using gen_cpio_init
  3. # (no need for root privileges)
  4. #
  5. # see ./build.d/ to see how the content is created!
  6. export PATH=$PATH:/sbin:/bin:/usr/bin:/usr/sbin
  7. k_ver=`uname -r`
  8. usage() {
  9. cat <<-EOF
  10. mkinitramfs - create initramfs image by using gen_cpio_init
  11. typical use:
  12. mkinitramfs [ -r KERNEL_VERSION ] [ -m MODULES_DIR ] [ -o OUTPUT_FILE ]
  13. If no options are given the following defaults apply:
  14. mkinitramfs -r $k_ver -m $mod_origin -o $outfile
  15. Options:
  16. -r Specify kernel version to use for modules dir
  17. -m Specify directory where to search for kernel modules
  18. -o Specify location of output file
  19. -p VAR=val Pass some variable definition to the build.d scripts
  20. -O output file list to given location
  21. --build-dir alternate directory for /lib/rock_initramfs/build.d/
  22. providing pluggable build components (scripts)
  23. --files-dir alternate directory for /lib/rock_initramfs/files/
  24. providing a location for files needed by
  25. build.d-scripts
  26. --root-dir prefix for some directory locations
  27. (/lib/modules, /lib/rock_initramfs
  28. and --files-dir, --build-dir if relative)
  29. --gen_init_cpio alternate binary for gen_init_cpio
  30. (usefull when default binary was cross compiled)
  31. --add-gen-line additional line to be passed to gen_init_cpio
  32. (usefull for small changes without modifying
  33. the whole build.d/-directory)
  34. EOF
  35. }
  36. rootdir=""
  37. while [ ${#} -gt 0 ]
  38. do
  39. case "$1" in
  40. -v) verbose=yes
  41. ;;
  42. -r)
  43. k_ver=$2
  44. shift
  45. ;;
  46. -m)
  47. mod_origin=$2
  48. shift
  49. ;;
  50. -O)
  51. listoutfile=$2
  52. shift
  53. ;;
  54. -o)
  55. outfile=$2
  56. shift
  57. ;;
  58. -p)
  59. scriptopt="$scriptopt ${2%%=*}='${2#*=}'"
  60. shift
  61. ;;
  62. --root-dir)
  63. rootdir="$2"
  64. shift
  65. ;;
  66. --build-dir)
  67. builddir="$2"
  68. shift
  69. ;;
  70. --files-dir)
  71. filesdir="$2"
  72. shift
  73. ;;
  74. --libexec-dir)
  75. libexecdir="$2"
  76. shift
  77. ;;
  78. --add-gen-line)
  79. additional_gen_lines="$additional_gen_lines;$2"
  80. shift
  81. ;;
  82. --gen_init_cpio)
  83. gen_init_cpio="$2"
  84. shift
  85. ;;
  86. *)
  87. usage=1
  88. ;;
  89. esac
  90. shift
  91. done
  92. [ -n "${rootdir}" -a "${rootdir:0:1}" != "/" ] && rootdir="`pwd`/$rootdir"
  93. [ -z "$mod_origin" ] && mod_origin=$rootdir/lib/modules/$k_ver
  94. [ -z "$outfile" ] && outfile=$rootdir/boot/initramfs-$k_ver.cpio.gz
  95. [ -z "$listoutfile" ] && listoutfile=$rootdir/boot/initramfs-$k_ver.cpio.lst
  96. if [ "$usage" = "1" ]
  97. then
  98. usage
  99. exit
  100. fi
  101. export BASE=$rootdir/lib/rock_initramfs
  102. [ -z "$builddir" ] && builddir="$BASE/build.d"
  103. [ -z "$filesdir" ] && filesdir="$BASE/files"
  104. [ -z "$libexecdir" ] && libexecdir="$BASE/libexec"
  105. [ "${builddir:0:1}" = "/" ] || builddir="$rootdir/$builddir"
  106. [ "${filesdir:0:1}" = "/" ] || filesdir="$rootdir/$filesdir"
  107. [ "${libexecdir:0:1}" = "/" ] || libexecdir="$rootdir/$libexecdir"
  108. [ ${outfile:0:1} = "/" ] || outfile="`pwd`/$outfile"
  109. [ ${listoutfile:0:1} = "/" ] || listoutfile="`pwd`/$listoutfile"
  110. [ ${mod_origin:0:1} = "/" ] || mod_origin="`pwd`/$mod_origin"
  111. [ -z "$rootdir" ] && rootdir=/
  112. cat << EOF
  113. kernel version: $k_ver
  114. module origin: $mod_origin
  115. output file: $outfile
  116. root dir: $rootdir
  117. build dir: $builddir
  118. files dir: $filesdir
  119. libexec dir: $libexecdir
  120. EOF
  121. export rootdir
  122. export builddir
  123. export filesdir
  124. export verbose
  125. export k_ver mod_origin scriptopt
  126. # provide a tmpdir to our helpers
  127. export TMPDIR="/tmp/irfs-`date +%s`.$$"
  128. mkdir -pv $TMPDIR
  129. # compile our list of cpio-content
  130. . ${libexecdir}/functions
  131. ${libexecdir}/build-list.sh > ${TMPDIR}/list
  132. echo "$additional_gen_lines" | tr ';' '\n' >> ${TMPDIR}/list
  133. if [ -n "$verbose" ]
  134. then
  135. echo "compiled list:"
  136. echo "======================="
  137. cat ${TMPDIR}/list
  138. echo "======================="
  139. fi
  140. # create and compress cpio archive
  141. if [ -z "$gen_init_cpio" ] ; then
  142. ${libexecdir}/gen_init_cpio ${TMPDIR}/list | gzip -9 > $outfile
  143. else
  144. ${gen_init_cpio} ${TMPDIR}/list | gzip -9 > $outfile
  145. fi
  146. [ -n "$listoutfile" ] && cp -v ${TMPDIR}/list "$listoutfile"
  147. if [ -n "$verbose" ]
  148. then
  149. echo "contents of TMPDIR=$TMPDIR:"
  150. echo "======================="
  151. find $TMPDIR
  152. echo "======================="
  153. fi
  154. # remove the tmpdir
  155. rm -rf $TMPDIR
  156. # can be extracted with:
  157. # gzip -dc ../irfs.cpio.gz | ( rm -rf ./root ; mkdir root ; cd root ; cpio -i -d -H newc --no-absolute-filenames )