您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

geniso 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/bin/bash
  2. #
  3. # Generate a isolinux ISO boot image
  4. function help() {
  5. echo "usage: ${0} [OPTIONS] foo.lkrn [bar.lkrn,...]"
  6. echo
  7. echo "where OPTIONS are:"
  8. echo " -h show this help"
  9. echo " -l build legacy image with floppy emulation"
  10. echo " -o FILE save iso image to file"
  11. }
  12. LEGACY=0
  13. FIRST=""
  14. while getopts "hlo:" opt; do
  15. case ${opt} in
  16. h)
  17. help
  18. exit 0
  19. ;;
  20. l)
  21. LEGACY=1
  22. ;;
  23. o)
  24. OUT="${OPTARG}"
  25. ;;
  26. esac
  27. done
  28. shift $((OPTIND - 1))
  29. if [ -z "${OUT}" ]; then
  30. echo "${0}: no output file given" >&2
  31. help
  32. exit 1
  33. fi
  34. # There should either be mkisofs or the compatible genisoimage program
  35. for command in genisoimage mkisofs; do
  36. if ${command} --version >/dev/null 2>/dev/null; then
  37. mkisofs=(${command})
  38. break
  39. fi
  40. done
  41. if [ -z "${mkisofs}" ]; then
  42. echo "${0}: mkisofs or genisoimage not found, please install or set PATH" >&2
  43. exit 1
  44. fi
  45. dir=$(mktemp -d bin/iso.dir.XXXXXX)
  46. cfg=${dir}/isolinux.cfg
  47. mkisofs+=(-quiet -l -volid "iPXE" -preparer "iPXE build system"
  48. -appid "iPXE ${VERSION} - Open Source Network Boot Firmware"
  49. -publisher "http://ipxe.org/" -c boot.cat)
  50. # generate the config
  51. cat > ${cfg} <<EOF
  52. # These default options can be changed in the geniso script
  53. SAY iPXE ISO boot image
  54. TIMEOUT 30
  55. EOF
  56. for f; do
  57. if [ ! -r ${f} ]; then
  58. echo "${f} does not exist, skipping" >&2
  59. continue
  60. fi
  61. b=$(basename ${f})
  62. g=${b%.lkrn}
  63. g=${g//[^a-z0-9]}
  64. g=${g:0:8}.krn
  65. case "${FIRST}" in
  66. "")
  67. echo "DEFAULT ${b}"
  68. FIRST=${g}
  69. ;;
  70. esac
  71. echo "LABEL ${b}"
  72. echo " KERNEL ${g}"
  73. cp ${f} ${dir}/${g}
  74. done >> ${cfg}
  75. case "${LEGACY}" in
  76. 1)
  77. # check for mtools
  78. case "$(mtools -V)" in
  79. Mtools\ version\ 3.9.9*|Mtools\ version\ 3.9.1[0-9]*|[mM]tools\ *\ [4-9].*)
  80. ;;
  81. *)
  82. echo "Mtools version 3.9.9 or later is required" >&2
  83. exit 1
  84. ;;
  85. esac
  86. # generate floppy image
  87. img=${dir}/boot.img
  88. mformat -f 1440 -C -i ${img} ::
  89. # copy lkrn file to floppy image
  90. for f in ${dir}/*.krn; do
  91. mcopy -m -i ${img} ${f} ::$(basename ${g})
  92. rm -f ${f}
  93. done
  94. # copy config file to floppy image
  95. mcopy -i ${img} ${cfg} ::syslinux.cfg
  96. rm -f ${cfg}
  97. # write syslinux bootloader to floppy image
  98. if ! syslinux ${img}; then
  99. echo "${0}: failed writing syslinux to floppy image ${img}" >&2
  100. exit 1
  101. fi
  102. # generate the iso image
  103. "${mkisofs[@]}" -b boot.img -output ${OUT} ${dir}
  104. ;;
  105. 0)
  106. # copy isolinux bootloader
  107. cp ${ISOLINUX_BIN} ${dir}
  108. # syslinux 6.x needs a file called ldlinux.c32
  109. LDLINUX_C32=$(dirname ${ISOLINUX_BIN})/ldlinux.c32
  110. if [ -s ${LDLINUX_C32} ]; then
  111. cp ${LDLINUX_C32} ${dir}
  112. fi
  113. # generate the iso image
  114. "${mkisofs[@]}" -b isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -output ${OUT} ${dir}
  115. # isohybrid will be used if available
  116. if isohybrid --version >/dev/null 2>/dev/null; then
  117. isohybrid ${OUT} >/dev/null
  118. fi
  119. ;;
  120. esac
  121. # clean up temporary dir
  122. rm -fr ${dir}