source: grub-pc/trunk/fuentes/docs/autoiso.cfg @ 22

Last change on this file since 22 was 22, checked in by mabarracus, 5 years ago

updated version and apply net.ifnames=0 into debian/rules

File size: 6.3 KB
Line 
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
18function pathname { regexp -s 2:"$2" '^(\(.*\))?(/.*)$' "$1"; }
19function devname  { regexp -s "$2" '^(\(.*\)).*$' "$1"; }
20
21function loopback_iso_entry {
22    realdev="$1"
23    isopath="$2"
24    loopdev="$3"
25
26    if test -f /boot/grub/loopback.cfg; then
27        cfgpath=/boot/grub/loopback.cfg
28    elif test -f /grub/loopback.cfg; then
29        cfgpath=/grub/loopback.cfg
30    else
31        return 1;
32    fi
33
34    echo loopback.cfg $isopath: yes
35    menuentry "Boot GRUB Loopback Config from ${realdev}${isopath}" "$realdev" "$isopath" "$cfgpath" {
36        set device="$2"
37        set iso_path="$3"
38        set cfg_path="$4"
39
40        export iso_path
41        loopback loopdev_cfg "${device}${iso_path}"
42        set root=(loopdev_cfg)
43        configfile $cfg_path
44        loopback -d loopdev_cfg
45    }
46    return 0
47}
48
49function grml_iso_entry {
50    realdev="$1"
51    isopath="$2"
52    loopdev="$3"
53
54    result=1
55    for dir in /boot/grml /boot/grmlsmall /boot/grmlmedium; do
56        if ! test -f ${dir}/linux26 -a -f ${dir}/initrd.gz; then continue; fi
57
58        echo grml $isopath: yes
59        result=0
60        menuentry "GRML Linux from ${realdev}${isopath}" \
61            "$realdev" "$isopath" "$dir" {
62            set device="$2"
63            set isopath="$3"
64            set grmldir="$4"
65
66            loopback loopdev_grml "${device}${isopath}"
67            set root=(loopdev_grml)
68            linux $grmldir/linux26 findiso="$isopath" apm=power-off quiet \
69                boot=live nomce
70            initrd $grmldir/initrd.gz
71            loopback -d loopdev_grml
72        }
73    done
74    return $result
75}
76
77function pmagic_iso_entry {
78    realdev="$1"
79    isopath="$2"
80    loopdev="$3"
81
82    if ! test -f /pmagic/bzImage -a -f /pmagic/initramfs; then return 1; fi
83
84    echo pmagic $isopath: yes
85    menuentry "Parted Magic from ${realdev}${isopath}" "$realdev" "$isopath" {
86        set device="$2"
87        set isopath="$3"
88
89        loopback loopdev_pmagic "${device}${isopath}"
90        set root=(loopdev_pmagic)
91        linux /pmagic/bzImage iso_filename="$isopath" edd=off noapic \
92            load_ramdisk=1 prompt_ramdisk=0 rw sleep=10 loglevel=0 \
93            keymap=$langcode
94        initrd /pmagic/initramfs
95        loopback -d loopdev_pmagic
96    }
97    return 0
98}
99
100function sidux_iso_entry {
101    realdev="$1"
102    isopath="$2"
103    loopdev="$3"
104
105    result=1
106    for kernel in /boot/vmlinuz-*-sidux-*; do
107        if ! test -f "$kernel"; then continue; fi
108        regexp -s 1:v1 -s 2:v2 '/boot/vmlinuz-(.*)-sidux-(.*)' "$kernel"
109
110        initrd="/boot/initrd.img-$v1-sidux-$v2"
111        if ! test -f "$initrd"; then continue; fi
112
113        result=0
114        echo sidux $isopath: yes
115        menuentry "Sidux vmlinux-$v1-sidux-$v2 from ${realdev}${isopath}" "$realdev" "$isopath" "$kernel" "$initrd" {
116            set device="$2"
117            set isopath="$3"
118            set kernel="$4"
119            set initrd="$5"
120
121            loopback loopdev_sidux "${device}${isopath}"
122            set root=(loopdev_sidux)
123            linux $kernel fromiso=$isopath boot=fll quiet
124            initrd $initrd
125            loopback -d loopdev_sidux
126        }
127    done
128    return $result
129}
130
131function slax_iso_entry {
132    realdev="$1"
133    isopath="$2"
134    loopdev="$3"
135
136    if ! test -f /boot/vmlinuz -a -f /boot/initrd.gz; then return 1; fi
137
138    echo slax $isopath: yes
139    menuentry "Slax Linux from ${realdev}${isopath}" "$realdev" "$isopath" {
140        set device="$2"
141        set isopath="$3"
142
143        loopback loopdev_slax "${device}${isopath}"
144        set root=(loopdev_slax)
145        linux /boot/vmlinuz from=$isopath ramdisk_size=6666 root=/dev/ram0 rw
146        initrd /boot/initrd.gz
147        loopback -d loopdev_slax
148    }
149    return 0
150}
151
152function tinycore_iso_entry {
153    realpath="$1"
154    isopath="$2"
155    loopdev="$3"
156
157    if ! test -f /boot/bzImage -a -f /boot/tinycore.gz; then return 1; fi
158
159    echo tinycore $isopath: yes
160    menuentry "Tinycore Linux from ${realdev}${isopath}" "$realdev" "$isopath" {
161        set device="$2"
162        set isopath="$3"
163
164        loopback loopdev_tiny "${device}${isopath}"
165        set root=(loopdev_tiny)
166        linux /boot/bzImage
167        initrd /boot/tinycore.gz
168        loopback -d loopdev_tiny
169    }
170    return 0
171}
172
173function casper_iso_entry {
174    realpath="$1"
175    isopath="$2"
176    loopdev="$3"
177
178    if ! test -f /casper/vmlinuz; then return 1; fi
179    initrd=
180    for f in /casper/initrd.*z; do
181        if ! test -f "$f"; then continue; fi
182        pathname "$f" initrd
183    done
184    if test -z "$initrd"; then return 1; fi
185
186    echo casper $isopath: yes
187    menuentry "Casper based Linux from ${realdev}${isopath}" "$realdev" "$isopath" "$initrd" {
188        set device="$2"
189        set isopath="$3"
190        set initrd="$4"
191
192        loopback loopdev_casper "${device}${isopath}"
193        set root=(loopdev_casper)
194        linux /casper/vmlinuz boot=casper iso-scan/filename="$isopath" quiet splash noprompt keyb="$langcode" \
195            debian-installer/language="$langcode" console-setup/layoutcode?="$langcode" --
196        initrd $initrd
197        loopback -d loopdev_casper
198    }
199    return 0
200}
201
202function scan_isos {
203    isodirs="$1"
204
205    for dev in (*); do
206        for dir in $isodirs; do
207            for file in ${dev}${dir}/*.iso ${dev}${dir}/*.ISO; do
208                if ! test -f "$file"; then continue; fi
209
210                pathname $file isopath
211                if test -z "$dev" -o -z "$isopath"; then continue; fi
212
213                if ! loopback loopdev_scan "$file"; then continue; fi
214                saved_root=$root
215                set root=(loopdev_scan)
216
217                if   loopback_iso_entry $dev $isopath (loopdev_scan); then true;
218                elif grml_iso_entry     $dev $isopath (loopdev_scan); then true;
219                elif pmagic_iso_entry   $dev $isopath (loopdev_scan); then true;
220                elif sidux_iso_entry    $dev $isopath (loopdev_scan); then true;
221                elif slax_iso_entry     $dev $isopath (loopdev_scan); then true;
222                elif tinycore_iso_entry $dev $isopath (loopdev_scan); then true;
223                elif casper_iso_entry   $dev $isopath (loopdev_scan); then true;
224                else true; fi
225
226                set root=$saved_root
227                loopback -d loopdev_scan
228            done
229        done
230    done
231    return 0
232}
233
234# XXX Remove later
235insmod serial
236serial
237terminal_output --append serial
238# terminal_input --append serial
239
240langcode="$lang"
241
242insmod regexp
243scan_isos /iso /boot/iso
244
Note: See TracBrowser for help on using the repository browser.