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.

150 lines
3.6 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. # (C) 2004 Tobias Hintze
  7. #
  8. GRUBSRC=/usr/share/grub/i386-*
  9. set -e
  10. usage() {
  11. echo "Usage:"
  12. echo " $0 ISODIR FDDIR"
  13. echo " creates the iso from iso-dir and fd-dir"
  14. echo
  15. echo " $0 -c KERNEL INITRD[.gz] SYSTEM [OVERLAY]"
  16. echo " creates iso-dir and fd-dir"
  17. echo
  18. echo " $0 -C KERNEL INITRD[.gz] SYSTEM [OVERLAY]"
  19. echo " creates the iso from kernel, initrd and system tarball"
  20. echo ""
  21. echo "initrd.img and system.tar.bz2 are generated during the"
  22. echo "rescue-target build."
  23. echo ""
  24. echo "the kernel must have support for devfs and initrd."
  25. echo ""
  26. exit 1
  27. }
  28. die() {
  29. echo "$1"
  30. exit 2
  31. }
  32. test -z "$1" && usage
  33. if [ "$1" == "-c" ] ; then
  34. CREATEDIRS=1
  35. fi
  36. if [ "$1" == "-C" ] ; then
  37. CREATEDIRS=2
  38. fi
  39. if [ ! -z "$CREATEDIRS" ]
  40. then
  41. shift
  42. TMPDIR=/var/tmp/rescue.$$
  43. mkdir $TMPDIR || die "failed to create tmp-dir \"$TMPDIR\"."
  44. mkdir -v $TMPDIR/iso $TMPDIR/fd
  45. #
  46. # prepare fd dir
  47. #
  48. test -z "$1" && usage
  49. KERNEL=$1 ; shift
  50. test -z "$1" && usage
  51. INITRD=$1 ; shift
  52. test -z "$1" && usage
  53. SYSTEM=$1 ; shift
  54. # kernel to fd
  55. cp -v $KERNEL $TMPDIR/fd/bzImage
  56. # initrd to fd
  57. if [ "`file -bi $INITRD`" == "application/x-gzip" ] ; then
  58. cp -v $INITRD $TMPDIR/fd/initrd.gz
  59. else
  60. echo "compressing initrd image..."
  61. cat $INITRD | gzip -c > $TMPDIR/fd/initrd.gz
  62. fi
  63. mkdir $TMPDIR/fd/grub
  64. # menu.lst to fd
  65. cat > $TMPDIR/fd/grub/menu.lst << EOF
  66. timeout 10
  67. title rescue ramdisk from cdrom
  68. kernel (fd0)/bzImage root=/dev/ram0 boot=iso9660:/dev/cdroms/cdrom0 panic=30
  69. initrd (fd0)/initrd.gz
  70. title LVM-boot-cycle
  71. configfile (fd0)/grub/menu.lst-LBC
  72. EOF
  73. cat > $TMPDIR/fd/grub/menu.lst-LBC << EOF
  74. title lvm boot cycle rootlv=/dev/vg00/lvroot0
  75. kernel (fd0)/bzImage root=/dev/ram0 boot=iso9660:/dev/cdroms/cdrom0 stage2init=/sbin/init-lvm-cycle rootlv=/dev/vg00/lvroot0 panic=30
  76. initrd (fd0)/initrd.gz
  77. title lvm boot cycle rootlv=/dev/vg00/lvroot1
  78. kernel (fd0)/bzImage root=/dev/ram0 boot=iso9660:/dev/cdroms/cdrom0 stage2init=/sbin/init-lvm-cycle rootlv=/dev/vg00/lvroot1 panic=30
  79. initrd (fd0)/initrd.gz
  80. title lvm boot cycle rootlv=/dev/vg00/lv00
  81. kernel (fd0)/bzImage root=/dev/ram0 boot=iso9660:/dev/cdroms/cdrom0 stage2init=/sbin/init-lvm-cycle rootlv=/dev/vg00/lv00 panic=30
  82. initrd (fd0)/initrd.gz
  83. EOF
  84. cp -v $GRUBSRC/stage[12] $GRUBSRC/{e2fs,fat,xfs}_stage1_5 $TMPDIR/fd/grub/
  85. #
  86. # prepare iso dir
  87. #
  88. mkdir $TMPDIR/iso/rescue/
  89. cp -v $SYSTEM $TMPDIR/iso/rescue/system.tar.bz2
  90. if [ ! -z "$1" ] ; then
  91. OVERLAY=$1 ; shift
  92. cp -v $OVERLAY $TMPDIR/iso/rescue/overlay.tar.bz2
  93. fi
  94. if [ "$CREATEDIRS" == "1" ] ; then
  95. echo "ready. you might want to run:"
  96. echo "$0 $TMPDIR/iso $TMPDIR/fd"
  97. elif [ "$CREATEDIRS" == "2" ] ; then
  98. echo "running $0 $TMPDIR/iso $TMPDIR/fd"
  99. $0 $TMPDIR/iso $TMPDIR/fd
  100. rm -rfv $TMPDIR/iso $TMPDIR/fd
  101. rmdir -v $TMPDIR
  102. fi
  103. exit 0
  104. fi
  105. ISODIR=$1 ; shift
  106. test -z "$1" && usage
  107. FDDIR=$1 ; shift
  108. test -d $ISODIR || die "ISODIR \"$ISODIR\" not a directory."
  109. test -d $FDDIR || die "FDDIR \"$FDDIR\" not a directory."
  110. e2fsimage -f $ISODIR/fdemu.img -d $FDDIR -v -s 2880
  111. rm -f $ISODIR/device.map-$$
  112. echo "(fd0) $ISODIR/fdemu.img" > $ISODIR/device.map-$$
  113. if [ "`id -u`" == "0" ]
  114. then
  115. die "i don't want to run grub as root. destructive potential too high."
  116. fi
  117. grub --device-map=$ISODIR/device.map-$$ --batch <<EOF
  118. root (fd0)
  119. setup (fd0)
  120. EOF
  121. rm -fv $ISODIR/device.map-$$
  122. create_fdemu_image() {
  123. test -e iso && die "file \"iso\" is in my way."
  124. mkisofs -b fdemu.img -r -l -d -c boot.catalog \
  125. -allow-multidot -allow-lowercase -o iso $ISODIR
  126. }
  127. create_fdemu_image