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.

212 lines
5.7 KiB

  1. #!/bin/sh
  2. #
  3. # This is a contributed script to create a bootable ISO image from your
  4. # rescue target build.
  5. #
  6. # It uses isolinux (syslinux) to create a non-emu bootable image.
  7. # It uses memdisk (syslinux) to add grub to the list of choices.
  8. #
  9. # (C) 2004 Tobias Hintze
  10. #
  11. [ -z "$GRUBSRC" ] && GRUBSRC="/usr/share/grub"
  12. [ -z "$SYSLINUXSRC" ] && SYSLINUXSRC="/usr/lib/syslinux"
  13. set -e
  14. usage() {
  15. echo "Usage:"
  16. echo " $0 ISODIR"
  17. echo " creates the iso image from iso-dir"
  18. echo
  19. echo " $0 -c KERNEL INITRD[.gz] SYSTEM [OVERLAY]"
  20. echo " creates iso-dir"
  21. echo
  22. echo " $0 -C KERNEL INITRD[.gz] SYSTEM [OVERLAY]"
  23. echo " creates the iso image from kernel, initrd and system tarball"
  24. echo ""
  25. echo "Example usage (most commonly used):"
  26. echo "(You get an iso image with default configuration and given files.)"
  27. echo ""
  28. echo "$0 -C vmlinuz initrd.img system.tar.bz2"
  29. echo ""
  30. echo "Using the -C option is like using the -c option except that after creating"
  31. echo "the temporary iso-dir the script calls itself to create the image from that"
  32. echo "dir (first usage option). The iso-dir is deleted on success afterwards."
  33. echo ""
  34. echo "* initrd.img and system.tar.bz2 are generated during the rescue-target build."
  35. echo "* kernel must have support for devfs"
  36. echo "* kernel must have support for initrd"
  37. echo "* kernel must have support for iso9660"
  38. echo ""
  39. exit 1
  40. }
  41. die() {
  42. echo "$1"
  43. exit 2
  44. }
  45. check_reqs() {
  46. [ -z "`type -p grub`" ] && \
  47. die "You need grub to create an image with this script."
  48. [ -z "`type -p e2fsimage`" ] && \
  49. die "You need e2fsimage to create an image with this script."
  50. [ -z "`type -p mkisofs`" ] && \
  51. die "You need mkisofs to create an image with this script."
  52. [ -d "$GRUBSRC" ] || die "No grub stages at $GRUBSRC. I need them!"
  53. [ -d "$SYSLINUXSRC" ] || die "No syslinux at $SYSLINUXSRC. I need it!"
  54. echo "requirements ok."
  55. }
  56. test -z "$1" && usage
  57. case "$1" in
  58. -c|-C)
  59. CREATEDIR=1
  60. [[ "$1" == "-C" ]] && CREATEDIR=2
  61. [[ $# == 4 || $# == 5 ]] || usage
  62. [ -r $2 ] || exec echo "failed to read kernel image $2"
  63. [ -r $3 ] || exec echo "failed to read initrd image $3"
  64. [ -r $4 ] || exec echo "failed to read system $4"
  65. KERNEL=$2
  66. INITRD=$3
  67. SYSTEM=$4
  68. [[ $# == 5 ]] && {
  69. [ -r $5 ] || exec echo "failed to read overlay $5"
  70. OVERLAY=$5
  71. }
  72. ;;
  73. *)
  74. [[ $# == 1 ]] || usage
  75. [ -r $1 ] || exec echo "failed to read iso-dir $1"
  76. esac
  77. [[ "$CREATEDIR" != 1 ]] && [ -e iso ] && die "file \"iso\" is in my way."
  78. check_reqs
  79. GRUBSRC="$( find $GRUBSRC -type d -mindepth 1 -maxdepth 1 | head -n 1 )"
  80. [ -r $GRUBSRC/stage1 -a -r $GRUBSRC/stage2 ] || die "grub stage1 or stage2 missing."
  81. [ -r $SYSLINUXSRC/isolinux.bin -a \
  82. -r $SYSLINUXSRC/memdisk ] || die "isolinux.bin or memdisk missing."
  83. if [ -n "$CREATEDIR" ]
  84. then
  85. TMPDIR=/var/tmp/rescuecd.$$
  86. mkdir $TMPDIR || die "failed to create tmp-dir \"$TMPDIR\"."
  87. mkdir -pv $TMPDIR/iso/isolinux $TMPDIR/iso/rescue $TMPDIR/fd
  88. #
  89. # prepare the directory
  90. #
  91. # syslinux
  92. cp -v $SYSLINUXSRC/isolinux.bin $SYSLINUXSRC/memdisk $TMPDIR/iso/isolinux/
  93. # kernel
  94. cp -v $KERNEL $TMPDIR/iso/isolinux/krescue
  95. # initrd
  96. if [ "`file -bi $INITRD`" == "application/x-gzip" ] ; then
  97. cp -v $INITRD $TMPDIR/iso/isolinux/rdrescue.gz
  98. else
  99. echo "compressing initrd image..."
  100. cat $INITRD | gzip -c > $TMPDIR/iso/isolinux/rdrescue.gz
  101. fi
  102. cp -v $SYSTEM $TMPDIR/iso/rescue/system.tb2
  103. [ -n "$OVERLAY" ] && cp -v $OVERLAY $TMPDIR/iso/rescue/overlay.tb2
  104. #
  105. # create grub fd
  106. #
  107. echo "creating bootable grub fd image"
  108. mkdir -v $TMPDIR/fd/grub
  109. cp -v $GRUBSRC/*stage* $TMPDIR/fd/grub/
  110. e2fsimage -f $TMPDIR/iso/isolinux/fdgrub.img -d $TMPDIR/fd -v -s 360
  111. rm -f $TMPDIR/device.map
  112. echo "(fd0) $TMPDIR/iso/isolinux/fdgrub.img" > $TMPDIR/device.map
  113. [[ "`id -u`" == "0" ]] && {
  114. echo "i don't want to run grub as root. destructive potential too high."
  115. echo "if you want to do it on your own issue the following command: "
  116. echo
  117. echo "grub --device-map=$TMPDIR/device.map --batch <<EOF"
  118. echo "root (fd0)"
  119. echo "setup (fd0)"
  120. echo "EOF"
  121. echo
  122. die "Cowardly refusing to endanger your MBR and disks."
  123. }
  124. grub --device-map=$TMPDIR/device.map --batch <<EOF
  125. root (fd0)
  126. setup (fd0)
  127. EOF
  128. echo ""
  129. echo "finished creating fdgrub.img"
  130. # create isolinux.cfg
  131. cat > $TMPDIR/iso/isolinux/isolinux.cfg << EOF
  132. DEFAULT rescue
  133. TIMEOUT 300
  134. PROMPT 1
  135. DISPLAY display.txt
  136. LABEL rescue
  137. KERNEL krescue
  138. APPEND initrd=rdrescue.gz root=/dev/ram boot=iso9660:/dev/cdroms/cdrom0 system=/mnt_boot/rescue/system.tb2 overlay=/mnt_boot/rescue/overlay.tb2 panic=60
  139. LABEL grub
  140. KERNEL memdisk
  141. APPEND initrd=fdgrub.img
  142. EOF
  143. cat > $TMPDIR/iso/isolinux/display.txt << "EOF"
  144. ____ ___ ___ _ __ _
  145. | _ \ / _ \ / __| |/ / | | _ _ __ _ _ _ _
  146. | . _/| | | | | | '_/ | | |_| '_ \| | | | \/ |
  147. | |\ \| |_| | |__| . \ | |__| | | | | `_' |> <
  148. |_| \_\ ___/ \___|_|\_\ |____|_|_| |_|\___/|_/\_|
  149. [============> http://www.rocklinux.org/ <============]
  150. Actions:
  151. --------
  152. <ENTER> Boot into rescue system (ramdisk)
  153. grub <ENTER> Run grub from emulated floppy image
  154. rescue options <ENTER> Boot into rescue system with given options
  155. "EOF"
  156. EOF
  157. if [ "$CREATEDIR" == "1" ] ; then
  158. echo "ready. you might want to run:"
  159. echo "$0 $TMPDIR/iso"
  160. elif [ "$CREATEDIR" == "2" ] ; then
  161. echo "running $0 $TMPDIR/iso"
  162. $0 $TMPDIR/iso
  163. rm -rfv $TMPDIR
  164. fi
  165. exit 0
  166. fi
  167. test -z "$1" && usage
  168. ISODIR=$1
  169. test -d $ISODIR || die "ISODIR \"$ISODIR\" not a directory."
  170. create_iso_image() {
  171. test -e iso && die "file \"iso\" is in my way."
  172. mkisofs -b isolinux/isolinux.bin -c isolinux/boot.cat \
  173. -no-emul-boot -boot-load-size 4 \
  174. -boot-info-table -o iso $ISODIR
  175. }
  176. create_iso_image