1- # Sample GRUB script to autodetect operating systems
2- #
3- # Copyright (C) 2017 Marcelo Politzer Couto
1+ # Copyright (C) 2021 Marcelo Politzer Couto
42# Copyright (C) 2010 Free Software Foundation, Inc.
53#
64# GRUB is free software: you can redistribute it and/or modify
1614# You should have received a copy of the GNU General Public License
1715# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
1816
19- function pathname { regexp -s 2:" $2" ' ^(\( .*\) )? (/.*)$' " $1" ; }
17+ function pathname { regexp -s 2:" $2" ' ^(\( .*\) )/* (/.*)$' " $1" ; }
2018function devname { regexp -s " $2" ' ^(\( .*\) ).*$' " $1" ; }
2119
2220function isolinux_iso_entry {
23- dev =" $1"
24- iso =" $2"
25- label =" $3"
26-
21+ realdev =" $1"
22+ isopath =" $2"
23+ loopdev =" $3"
2724
2825 if test -f /boot/isolinux/isolinux.cfg; then
29- cfg =/boot/isolinux/isolinux.cfg
26+ cfgpath =/boot/isolinux/isolinux.cfg
3027 elif test -f /syslinux/syslinux.cfg; then
31- cfg =/syslinux/syslinux.cfg
28+ cfgpath =/syslinux/syslinux.cfg
3229 elif test -f /isolinux/isolinux.cfg; then
33- cfg =/isolinux/isolinux.cfg
30+ cfgpath =/isolinux/isolinux.cfg
3431 elif test -f /boot/x86_64/loader/isolinux.cfg; then
35- cfg =/boot/x86_64/loader/isolinux.cfg
32+ cfgpath =/boot/x86_64/loader/isolinux.cfg
3633 else
3734 return 1;
3835 fi
3936
40- echo isolinux based $iso : yes
41- menuentry " $iso (isolinux) " " $dev " " $iso " " $cfg " " $label " {
42- set dev = " $2 "
43- set iso =" $3 "
44- set cfg =" $4 "
45- set label =" $5 "
37+ echo isolinux based $isopath : yes
38+ probe -s label -l $realdev
39+ menuentry " ${indent}${isopath} (isolinux) " " $realdev " " $isopath " " $cfgpath " {
40+ set device =" $2 "
41+ set isopath =" $3 "
42+ set cfgpath =" $4 "
4643
47- loopback loop " ${dev}${iso}"
44+ probe -s rootuuid -u $device
45+ loopback loop " ${device}${isopath}"
4846 set root =(loop)
4947
48+ # this flag requires a hacked grub!!
49+
50+ # language settings
51+ set linux_extra =" $langset"
52+
5053 # arch based
51- set linux_extra =" ${linux_extra} img_dev=" /dev/disk/by-label/$label" img_loop=$iso earlymodules=loop"
54+ set linux_extra =" ${linux_extra} img_dev=/dev/disk/by-uuid/$rootuuid img_loop=$isopath earlymodules=loop"
55+
56+ # gentoo based
57+ set linux_extra =" ${linux_extra} isofrom=$isopath"
58+
59+ # ubuntu based, fedora, opensuse, rosa
60+ set linux_extra =" ${linux_extra} iso-scan/filename=$isopath"
61+
62+ # antiX based
63+ set linux_extra =" ${linux_extra} from=all fromiso=$isopath"
64+
65+ # Grml Live Linux
66+ set linux_extra =" ${linux_extra} findiso=$isopath"
67+
68+ # sysrcd
69+ set linux_extra =" ${linux_extra} isoloop=$isopath"
70+
71+ # MagOS Linux (UIRD)
72+ set linux_extra =" ${linux_extra} uird.from=${isopath},/MagOS uird.force scantimeout=3"
73+
74+ # TODO: SUSE based
75+ set linux_extra =" ${linux_extra} isofrom_device=/dev/disk/by-uuid/$rootuuid isofrom_system=$isopath"
76+
77+ # others?
78+ set linux_extra =" ${linux_extra} isoboot=$isopath"
5279
5380 export linux_extra
54- syslinux_configfile $cfg
81+ syslinux_configfile $cfgpath
5582 }
5683 return 0
5784}
5885
59- # iso_path is used by the loopback target, do not change!
6086function loopback_iso_entry {
6187 realdev =" $1"
6288 isopath =" $2"
89+ loopdev =" $3"
6390
6491 if test -f /boot/grub/loopback.cfg; then
6592 cfgpath =/boot/grub/loopback.cfg
6693 elif test -f /grub/loopback.cfg; then
6794 cfgpath =/grub/loopback.cfg
6895 else
69- return 1;
96+ return 1
7097 fi
7198
7299 echo loopback.cfg $isopath: yes
73- menuentry " ${isopath} (loopback)" " $realdev" " $isopath" " $cfgpath" {
100+ probe -s label -l $realdev
101+ menuentry " ${indent}${isopath} (loopback)" " $realdev" " $isopath" " $cfgpath" {
74102 set device =" $2"
75- set iso_path =" $3"
76- set cfg =" $4"
103+ set isopath =" $3"
104+ set cfgpath =" $4"
77105
78- export iso_path
79- loopback loop " ${device}${iso_path}"
106+ loopback loop " ${device}${isopath}"
80107 set root =(loop)
81- configfile $cfg
82- loopback -d loop
83- }
84- return 0
85- }
86108
87- function bsdfamily_iso_entry {
88- realdev =" $1 "
89- isopath = " $2 "
109+ probe -s rootuuid -u $device
110+ set isopath =" $isopath $langset "
111+ export isopath
90112
91- if test -f /FreeNAS-MANIFEST; then kpath=/boot/kernel/kernel; # FreeNAS
92- elif test -f /boot/zfsloader; then kpath=/boot/kernel/kernel; # FreeBSD
93- else return 1; fi
94-
95- echo bsd-family.cfg $isopath: yes
96- menuentry " ${isopath} (BSD family)" " $realdev" " $isopath" {
97- set device =" $2"
98- set iso =" $3"
99-
100- export iso
101- loopback loop " ${device}${iso}"
102- set root =(loop)
103-
104- echo " This may take a while..."
105- kfreebsd /boot/kernel/kernel
106- kfreebsd_module " ${device}${iso}" type =mfs_root
107- set kFreeBSD.vfs.root.mountfrom =cd9660:/dev/md0
113+ configfile $cfgpath
114+ loopback -d loop
108115 }
109116 return 0
110117}
111118
112119function scan_isos {
113120 isodirs =" $1"
114- label =" $2"
115121
122+ echo " scanning ..."
116123 for dev in (*); do
117124 for dir in $isodirs; do
118125 for file in ${dev}${dir}/*.iso ${dev}${dir}/*.ISO; do
119126 if ! test -f " $file" ; then continue; fi
120127
121128 pathname $file isopath
122- if test -z " $dev" -o -z " $isopath" ; then continue; fi
123129
124130 if ! loopback loopdev_scan " $file" ; then continue; fi
125131 saved_root =$root
126132 set root =(loopdev_scan)
127133
128- if loopback_iso_entry $dev $isopath ; then true;
129- elif isolinux_iso_entry $dev $isopath " $label " ; then true;
130- elif bsdfamily_iso_entry $dev $isopath; then true;
134+ if false ; then true;
135+ elif loopback_iso_entry $dev $isopath (loopdev_scan) ; then true;
136+ elif isolinux_iso_entry $dev $isopath (loopdev_scan) ; then true;
131137 else true; fi
132138
133139 set root =$saved_root
@@ -138,12 +144,15 @@ function scan_isos {
138144 return 0
139145}
140146
141- # XXX Remove later
142- insmod serial
143- serial
144- terminal_output --append serial
145- # terminal_input --append serial
147+ insmod part_gpt
148+ insmod part_msdos
149+ insmod regexp
146150
147151langcode =" $lang"
148152
149- insmod regexp
153+ regexp -s langcode ' (^..)' " $lang"
154+ langset =" lang=${lang} debian-installer/language=${langcode} keyboard-configuration/layoutcode?=${langcode}"
155+ indent =" " # indent for menu entries
156+
157+ scan_isos " $iso_dirs"
158+ newdir_scan_entry
0 commit comments