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.

187 lines
5.0 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 grub with fd-emu to create a bootable image.
  7. #
  8. # (C) 2004 Tobias Hintze
  9. #
  10. GRUBSRC=/usr/share/grub/i386-*
  11. set -e
  12. usage() {
  13. echo "Usage:"
  14. echo " $0 ISODIR FDDIR"
  15. echo " creates the iso image from iso-dir and fd-dir"
  16. echo
  17. echo " $0 -c KERNEL INITRD[.gz] SYSTEM [OVERLAY]"
  18. echo " creates iso-dir and fd-dir"
  19. echo
  20. echo " $0 -C KERNEL INITRD[.gz] SYSTEM [OVERLAY]"
  21. echo " creates the iso image from kernel, initrd and system tarball"
  22. echo ""
  23. echo "Example usage (most commonly used):"
  24. echo "(You get an iso image with default configuration and given files.)"
  25. echo ""
  26. echo "$0 -C vmlinuz initrd.img system.tar.bz2"
  27. echo ""
  28. echo "Using the -C option is like using the -c option except that after creating"
  29. echo "the temporary directories the script calls itself to create the image from them"
  30. echo "(first usage option). The directories are deleted on success afterwards."
  31. echo ""
  32. echo "* initrd.img and system.tar.bz2 are generated during the rescue-target build."
  33. echo "* kernel must have support for devfs"
  34. echo "* kernel must have support for initrd"
  35. echo "* kernel must have support for iso9660"
  36. echo "* kernel must be small to fit on 2880KB (minus initrd and grub stages)"
  37. exit 1
  38. }
  39. die() {
  40. echo "$1"
  41. exit 2
  42. }
  43. check_reqs() {
  44. [ -z "`type -p e2fsimage`" ] && \
  45. die "You need e2fsimage to create an image with this script."
  46. [ -z "`type -p mkisofs`" ] && \
  47. die "You need mkisofs to create an image with this script."
  48. [ -z "`type -p grub`" ] && \
  49. die "You need grub to create an image with this script."
  50. echo "requirements ok."
  51. }
  52. test -z "$1" && usage
  53. case "$1" in
  54. -c|-C)
  55. CREATEDIRS=1
  56. [[ "$1" == "-C" ]] && CREATEDIRS=2
  57. [[ $# == 4 || $# == 5 ]] || usage
  58. [ -r $2 ] || exec echo "failed to read kernel image $2"
  59. [ -r $3 ] || exec echo "failed to read initrd image $3"
  60. [ -r $4 ] || exec echo "failed to read system $4"
  61. [[ $# == 5 ]] && {
  62. [ -r $5 ] || exec echo "failed to read overlay $5"
  63. }
  64. ;;
  65. *)
  66. [[ $# == 2 ]] || usage
  67. [ -r $1 ] || exec echo "failed to read iso-dir $1"
  68. [ -r $2 ] || exec echo "failed to read fd-dir $2"
  69. ;;
  70. esac
  71. [[ "$CREATEDIRS" != 1 ]] && [ -e iso ] && die "file \"iso\" is in my way."
  72. check_reqs
  73. if [ -n "$CREATEDIRS" ]
  74. then
  75. shift
  76. TMPDIR=/var/tmp/rescue.$$
  77. mkdir $TMPDIR || die "failed to create tmp-dir \"$TMPDIR\"."
  78. mkdir -v $TMPDIR/iso $TMPDIR/fd
  79. #
  80. # prepare fd dir
  81. #
  82. test -z "$1" && usage
  83. KERNEL=$1 ; shift
  84. test -z "$1" && usage
  85. INITRD=$1 ; shift
  86. test -z "$1" && usage
  87. SYSTEM=$1 ; shift
  88. # kernel to fd
  89. cp -v $KERNEL $TMPDIR/fd/bzImage
  90. # initrd to fd
  91. if [ "`file -bi $INITRD`" == "application/x-gzip" ] ; then
  92. cp -v $INITRD $TMPDIR/fd/initrd.gz
  93. else
  94. echo "compressing initrd image..."
  95. cat $INITRD | gzip -c > $TMPDIR/fd/initrd.gz
  96. fi
  97. mkdir $TMPDIR/fd/grub
  98. # menu.lst to fd
  99. cat > $TMPDIR/fd/grub/menu.lst << EOF
  100. timeout 10
  101. title rescue ramdisk from cdrom
  102. kernel (fd0)/bzImage root=/dev/ram0 boot=iso9660:/dev/cdroms/cdrom0 panic=30
  103. initrd (fd0)/initrd.gz
  104. title LVM-boot-cycle
  105. configfile (fd0)/grub/menu.lst-LBC
  106. EOF
  107. cat > $TMPDIR/fd/grub/menu.lst-LBC << EOF
  108. title lvm boot cycle rootlv=/dev/vg00/lvroot0
  109. kernel (fd0)/bzImage root=/dev/ram0 boot=iso9660:/dev/cdroms/cdrom0 stage2init=/sbin/init-lvm-cycle rootlv=/dev/vg00/lvroot0 panic=30
  110. initrd (fd0)/initrd.gz
  111. title lvm boot cycle rootlv=/dev/vg00/lvroot1
  112. kernel (fd0)/bzImage root=/dev/ram0 boot=iso9660:/dev/cdroms/cdrom0 stage2init=/sbin/init-lvm-cycle rootlv=/dev/vg00/lvroot1 panic=30
  113. initrd (fd0)/initrd.gz
  114. title lvm boot cycle rootlv=/dev/vg00/lv00
  115. kernel (fd0)/bzImage root=/dev/ram0 boot=iso9660:/dev/cdroms/cdrom0 stage2init=/sbin/init-lvm-cycle rootlv=/dev/vg00/lv00 panic=30
  116. initrd (fd0)/initrd.gz
  117. EOF
  118. cp -v $GRUBSRC/stage[12] $GRUBSRC/{e2fs,fat,xfs}_stage1_5 $TMPDIR/fd/grub/
  119. #
  120. # prepare iso dir
  121. #
  122. mkdir $TMPDIR/iso/rescue/
  123. cp -v $SYSTEM $TMPDIR/iso/rescue/system.tar.bz2
  124. if [ ! -z "$1" ] ; then
  125. OVERLAY=$1 ; shift
  126. cp -v $OVERLAY $TMPDIR/iso/rescue/overlay.tar.bz2
  127. fi
  128. if [ "$CREATEDIRS" == "1" ] ; then
  129. echo "ready. you might want to run:"
  130. echo "$0 $TMPDIR/iso $TMPDIR/fd"
  131. elif [ "$CREATEDIRS" == "2" ] ; then
  132. echo "running $0 $TMPDIR/iso $TMPDIR/fd"
  133. $0 $TMPDIR/iso $TMPDIR/fd
  134. rm -rfv $TMPDIR/iso $TMPDIR/fd
  135. rmdir -v $TMPDIR
  136. fi
  137. exit 0
  138. fi
  139. ISODIR=$1 ; shift
  140. test -z "$1" && usage
  141. FDDIR=$1 ; shift
  142. test -d $ISODIR || die "ISODIR \"$ISODIR\" not a directory."
  143. test -d $FDDIR || die "FDDIR \"$FDDIR\" not a directory."
  144. e2fsimage -f $ISODIR/fdemu.img -d $FDDIR -v -s 2880
  145. rm -f $ISODIR/device.map-$$
  146. echo "(fd0) $ISODIR/fdemu.img" > $ISODIR/device.map-$$
  147. if [ "`id -u`" == "0" ]
  148. then
  149. die "i don't want to run grub as root. destructive potential too high."
  150. fi
  151. grub --device-map=$ISODIR/device.map-$$ --batch <<EOF
  152. root (fd0)
  153. setup (fd0)
  154. EOF
  155. rm -fv $ISODIR/device.map-$$
  156. create_iso_image() {
  157. test -e iso && die "file \"iso\" is in my way."
  158. mkisofs -b fdemu.img -r -l -d -c boot.catalog \
  159. -allow-multidot -allow-lowercase -o iso $ISODIR
  160. }
  161. create_iso_image