3
-- Copyright (C) 2009 Free Software Foundation, Inc.
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.
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.
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/>.
19
function enum_device (device, fs, uuid)
24
local kernelnames = {}
27
local function enum_file (name)
30
version = string.match (name, "vmlinuz%-(.*)")
31
if (version == nil) then
32
version = string.match (name, "linux%-(.*)")
34
if (version ~= nil) then
35
table.insert (kernels, version)
36
table.insert (kernelnames, name)
37
kernel_num = kernel_num + 1
41
local function sort_kernel (first, second)
42
local a1, a2, a3, a4, b1, b2, b3, b4
44
a1, a2, a3, a4 = string.match (first, "(%d+)%.?(%d*).?(%d*)%-?(%d*)")
45
b1, b2, b3, b4 = string.match (second, "(%d+)%.?(%d*).?(%d*)%-?(%d*)")
46
return (a1 > b1) or (a2 > b2) or (a3 > b3) or (a4 < b4);
48
local function freebsd_variants (title, header, footer)
49
normal = "\nset FreeBSD.acpi_load=YES" ..
50
"\nset FreeBSD.hint.acpi.0.disabled=0"
51
noacpi = "\nunset FreeBSD.acpi_load" ..
52
"\nset FreeBSD.hint.acpi.0.disabled=1" ..
53
"\nset FreeBSD.loader.acpi_disabled_by_user=1"
54
safe = "\nset FreeBSD.hint.apic.0.disabled=1" ..
55
"\nset FreeBSD.hw.ata.ata_dma=0" ..
56
"\nset FreeBSD.hw.ata.atapi_dma=0" ..
57
"\nset FreeBSD.hw.ata.wc=0" ..
58
"\nset FreeBSD.hw.eisa_slots=0" ..
59
"\nset FreeBSD.hint.kbdmux.0.disabled=1"
60
grub.add_menu (header .. normal .. footer, title)
61
grub.add_menu (header .. " --single" .. normal .. footer,
63
grub.add_menu (header .. " --verbose" .. normal .. footer,
64
title .. " (verbose)")
65
grub.add_menu (header .. " --verbose" .. noacpi .. footer,
66
title .. " (without ACPI)")
67
grub.add_menu (header .. " --verbose" .. noacpi .. safe .. footer,
68
title .. " (safe mode)")
71
root = "(" .. device .. ")/"
72
source = "set root=" .. device .. "\nchainloader +1"
74
local drive_num = string.match (device, "hd(%d+)")
75
if (drive_num ~= nil) and (drive_num ~= "0") then
76
source = source .. "\ndrivemap -s hd0 hd" .. drive_num
80
if (grub.file_exist (root .. "bootmgr") and
81
grub.file_exist (root .. "boot/bcd")) then
82
title = "Windows Vista bootmgr"
83
source = "set root=" .. device .. "\nchainloader +1"
84
elseif (grub.file_exist (root .. "ntldr") and
85
grub.file_exist (root .. "ntdetect.com") and
86
grub.file_exist (root .. "boot.ini")) then
87
title = "Windows NT/2000/XP loader"
88
elseif (grub.file_exist (root .. "windows/win.com")) then
89
title = "Windows 98/ME"
90
elseif (grub.file_exist (root .. "io.sys") and
91
grub.file_exist (root .. "command.com")) then
93
elseif (grub.file_exist (root .. "kernel.sys")) then
95
elseif ((fs == "ufs1" or fs == "ufs2") and grub.file_exist (root .. "boot/kernel/kernel") and
96
grub.file_exist (root .. "boot/device.hints")) then
97
header = "set root=" .. device .. "\nfreebsd /boot/kernel/kernel"
98
footer = "\nset FreeBSD.vfs.root.mountfrom=ufs:ufsid/" .. uuid ..
99
"\nfreebsd_loadenv /boot/device.hints"
100
title = "FreeBSD (on " .. fs .. " ".. device .. ")"
101
freebsd_variants (title, header, footer)
103
elseif (fs == "zfs" and grub.file_exist (root .. "/@/boot/kernel/kernel") and
104
grub.file_exist (root .. "/@/boot/device.hints")) then
105
header = "set root=" .. device .. "\nfreebsd /@/boot/kernel/kernel"
106
footer = "\nfreebsd_module_elf /@/boot/kernel/opensolaris.ko" ..
107
"\nfreebsd_module_elf /@/boot/kernel/zfs.ko" ..
108
"\nfreebsd_module /@/boot/zfs/zpool.cache type=/boot/zfs/zpool.cache" ..
109
"\nprobe -l -s name $root" ..
110
"\nset FreeBSD.vfs.root.mountfrom=zfs:$name" ..
111
"\nfreebsd_loadenv /@/boot/device.hints"
112
title = "FreeBSD (on " .. fs .. " ".. device .. ")"
113
freebsd_variants (title, header, footer)
115
elseif (fs == "hfsplus" and grub.file_exist (root .. "mach_kernel")) then
116
source = "set root=" .. device ..
119
"\nif [ /var/vm/sleepimage -nt10 / ]; then" ..
120
"\n if xnu_resume /var/vm/sleepimage; then" ..
124
"\nif [ $do_resume == 0 ]; then" ..
125
"\n xnu_uuid " .. uuid .. " uuid" ..
126
"\n if [ -f /Extra/DSDT.aml ]; then" ..
127
"\n acpi -e /Extra/DSDT.aml" ..
129
"\n xnu_kernel /mach_kernel boot-uuid=${uuid} rd=*uuid" ..
130
"\n if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then" ..
131
"\n xnu_mkext /System/Library/Extensions.mkext" ..
133
"\n xnu_kextdir /System/Library/Extensions" ..
135
"\n if [ -f /Extra/Extensions.mkext ]; then" ..
136
"\n xnu_mkext /Extra/Extensions.mkext" ..
138
"\n if [ -d /Extra/Extensions ]; then" ..
139
"\n xnu_kextdir /Extra/Extensions" ..
141
"\n if [ -f /Extra/devtree.txt ]; then" ..
142
"\n xnu_devtree /Extra/devtree.txt" ..
144
"\n if [ -f /Extra/splash.jpg ]; then" ..
146
"\n xnu_splash /Extra/splash.jpg" ..
148
"\n if [ -f /Extra/splash.png ]; then" ..
150
"\n xnu_splash /Extra/splash.png" ..
152
"\n if [ -f /Extra/splash.tga ]; then" ..
154
"\n xnu_splash /Extra/splash.tga" ..
157
title = "Mac OS X/Darwin"
159
grub.enum_file (enum_file, root .. "boot")
160
if kernel_num ~= 0 then
161
table.sort (kernels, sort_kernel)
162
table.sort (kernelnames, sort_kernel)
163
for i = 1, kernel_num do
166
title = "Linux " .. kernels[i]
167
source = "set root=" .. device ..
168
"\nlinux /boot/" .. kernelnames[i] ..
169
" root=UUID=" .. uuid .. " ro"
171
if grub.file_exist (root .. "boot/initrd-" ..
172
kernels[i] .. ".img") then
173
initrd = "\ninitrd /boot/initrd-" .. kernels[i] .. ".img"
174
elseif grub.file_exist (root .. "boot/initrd.img-" .. kernels[i]) then
175
initrd = "\ninitrd /boot/initrd.img-" .. kernels[i]
176
elseif grub.file_exist (root .. "boot/initrd-" .. kernels[i]) then
177
initrd = "\ninitrd /boot/initrd-" .. kernels[i]
182
grub.add_menu (source .. initrd, title)
183
grub.add_menu (source .. " single" .. initrd,
184
title .. " (single-user mode)")
191
local partition = string.match (device, ".*,(%d+)")
193
if (partition ~= nil) and (tonumber (partition) > 4) then
200
grub.add_menu (source, title)
204
grub.enum_device (enum_device)