autoiso.cfg 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. # Sample GRUB script to autodetect operating systems
  2. #
  3. # Copyright (C) 2010 Free Software Foundation, Inc.
  4. #
  5. # GRUB is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # GRUB is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. function pathname { regexp -s 2:"$2" '^(\(.*\))?(/.*)$' "$1"; }
  18. function devname { regexp -s "$2" '^(\(.*\)).*$' "$1"; }
  19. function loopback_iso_entry {
  20. realdev="$1"
  21. isopath="$2"
  22. loopdev="$3"
  23. if test -f /boot/grub/loopback.cfg; then
  24. cfgpath=/boot/grub/loopback.cfg
  25. elif test -f /grub/loopback.cfg; then
  26. cfgpath=/grub/loopback.cfg
  27. else
  28. return 1;
  29. fi
  30. echo loopback.cfg $isopath: yes
  31. menuentry "Boot GRUB Loopback Config from ${realdev}${isopath}" "$realdev" "$isopath" "$cfgpath" {
  32. set device="$2"
  33. set iso_path="$3"
  34. set cfg_path="$4"
  35. export iso_path
  36. loopback loopdev_cfg "${device}${iso_path}"
  37. set root=(loopdev_cfg)
  38. configfile $cfg_path
  39. loopback -d loopdev_cfg
  40. }
  41. return 0
  42. }
  43. function grml_iso_entry {
  44. realdev="$1"
  45. isopath="$2"
  46. loopdev="$3"
  47. result=1
  48. for dir in /boot/grml /boot/grmlsmall /boot/grmlmedium; do
  49. if ! test -f ${dir}/linux26 -a -f ${dir}/initrd.gz; then continue; fi
  50. echo grml $isopath: yes
  51. result=0
  52. menuentry "GRML Linux from ${realdev}${isopath}" \
  53. "$realdev" "$isopath" "$dir" {
  54. set device="$2"
  55. set isopath="$3"
  56. set grmldir="$4"
  57. loopback loopdev_grml "${device}${isopath}"
  58. set root=(loopdev_grml)
  59. linux $grmldir/linux26 findiso="$isopath" apm=power-off quiet \
  60. boot=live nomce
  61. initrd $grmldir/initrd.gz
  62. loopback -d loopdev_grml
  63. }
  64. done
  65. return $result
  66. }
  67. function pmagic_iso_entry {
  68. realdev="$1"
  69. isopath="$2"
  70. loopdev="$3"
  71. if ! test -f /pmagic/bzImage -a -f /pmagic/initramfs; then return 1; fi
  72. echo pmagic $isopath: yes
  73. menuentry "Parted Magic from ${realdev}${isopath}" "$realdev" "$isopath" {
  74. set device="$2"
  75. set isopath="$3"
  76. loopback loopdev_pmagic "${device}${isopath}"
  77. set root=(loopdev_pmagic)
  78. linux /pmagic/bzImage iso_filename="$isopath" edd=off noapic \
  79. load_ramdisk=1 prompt_ramdisk=0 rw sleep=10 loglevel=0 \
  80. keymap=$langcode
  81. initrd /pmagic/initramfs
  82. loopback -d loopdev_pmagic
  83. }
  84. return 0
  85. }
  86. function sidux_iso_entry {
  87. realdev="$1"
  88. isopath="$2"
  89. loopdev="$3"
  90. result=1
  91. for kernel in /boot/vmlinuz-*-sidux-*; do
  92. if ! test -f "$kernel"; then continue; fi
  93. regexp -s 1:v1 -s 2:v2 '/boot/vmlinuz-(.*)-sidux-(.*)' "$kernel"
  94. initrd="/boot/initrd.img-$v1-sidux-$v2"
  95. if ! test -f "$initrd"; then continue; fi
  96. result=0
  97. echo sidux $isopath: yes
  98. menuentry "Sidux vmlinux-$v1-sidux-$v2 from ${realdev}${isopath}" "$realdev" "$isopath" "$kernel" "$initrd" {
  99. set device="$2"
  100. set isopath="$3"
  101. set kernel="$4"
  102. set initrd="$5"
  103. loopback loopdev_sidux "${device}${isopath}"
  104. set root=(loopdev_sidux)
  105. linux $kernel fromiso=$isopath boot=fll quiet
  106. initrd $initrd
  107. loopback -d loopdev_sidux
  108. }
  109. done
  110. return $result
  111. }
  112. function slax_iso_entry {
  113. realdev="$1"
  114. isopath="$2"
  115. loopdev="$3"
  116. if ! test -f /boot/vmlinuz -a -f /boot/initrd.gz; then return 1; fi
  117. echo slax $isopath: yes
  118. menuentry "Slax Linux from ${realdev}${isopath}" "$realdev" "$isopath" {
  119. set device="$2"
  120. set isopath="$3"
  121. loopback loopdev_slax "${device}${isopath}"
  122. set root=(loopdev_slax)
  123. linux /boot/vmlinuz from=$isopath ramdisk_size=6666 root=/dev/ram0 rw
  124. initrd /boot/initrd.gz
  125. loopback -d loopdev_slax
  126. }
  127. return 0
  128. }
  129. function tinycore_iso_entry {
  130. realpath="$1"
  131. isopath="$2"
  132. loopdev="$3"
  133. if ! test -f /boot/bzImage -a -f /boot/tinycore.gz; then return 1; fi
  134. echo tinycore $isopath: yes
  135. menuentry "Tinycore Linux from ${realdev}${isopath}" "$realdev" "$isopath" {
  136. set device="$2"
  137. set isopath="$3"
  138. loopback loopdev_tiny "${device}${isopath}"
  139. set root=(loopdev_tiny)
  140. linux /boot/bzImage
  141. initrd /boot/tinycore.gz
  142. loopback -d loopdev_tiny
  143. }
  144. return 0
  145. }
  146. function casper_iso_entry {
  147. realpath="$1"
  148. isopath="$2"
  149. loopdev="$3"
  150. if ! test -f /casper/vmlinuz; then return 1; fi
  151. initrd=
  152. for f in /casper/initrd.*z; do
  153. if ! test -f "$f"; then continue; fi
  154. pathname "$f" initrd
  155. done
  156. if test -z "$initrd"; then return 1; fi
  157. echo casper $isopath: yes
  158. menuentry "Casper based Linux from ${realdev}${isopath}" "$realdev" "$isopath" "$initrd" {
  159. set device="$2"
  160. set isopath="$3"
  161. set initrd="$4"
  162. loopback loopdev_casper "${device}${isopath}"
  163. set root=(loopdev_casper)
  164. linux /casper/vmlinuz boot=casper iso-scan/filename="$isopath" quiet splash noprompt keyb="$langcode" \
  165. debian-installer/language="$langcode" console-setup/layoutcode?="$langcode" --
  166. initrd $initrd
  167. loopback -d loopdev_casper
  168. }
  169. return 0
  170. }
  171. function scan_isos {
  172. isodirs="$1"
  173. for dev in (*); do
  174. for dir in $isodirs; do
  175. for file in ${dev}${dir}/*.iso ${dev}${dir}/*.ISO; do
  176. if ! test -f "$file"; then continue; fi
  177. pathname $file isopath
  178. if test -z "$dev" -o -z "$isopath"; then continue; fi
  179. if ! loopback loopdev_scan "$file"; then continue; fi
  180. saved_root=$root
  181. set root=(loopdev_scan)
  182. if loopback_iso_entry $dev $isopath (loopdev_scan); then true;
  183. elif grml_iso_entry $dev $isopath (loopdev_scan); then true;
  184. elif pmagic_iso_entry $dev $isopath (loopdev_scan); then true;
  185. elif sidux_iso_entry $dev $isopath (loopdev_scan); then true;
  186. elif slax_iso_entry $dev $isopath (loopdev_scan); then true;
  187. elif tinycore_iso_entry $dev $isopath (loopdev_scan); then true;
  188. elif casper_iso_entry $dev $isopath (loopdev_scan); then true;
  189. else true; fi
  190. set root=$saved_root
  191. loopback -d loopdev_scan
  192. done
  193. done
  194. done
  195. return 0
  196. }
  197. # XXX Remove later
  198. insmod serial
  199. serial
  200. terminal_output --append serial
  201. # terminal_input --append serial
  202. langcode="$lang"
  203. insmod regexp
  204. scan_isos /iso /boot/iso