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
)
26 local function enum_file (name
)
29 version
= string.match (name
, "vmlinuz%-(.*)")
30 if (version
~= nil) then
31 table.insert (kernels
, version
)
32 kernel_num
= kernel_num
+ 1
36 local function sort_kernel (first
, second
)
37 local a1
, a2
, a3
, a4
, b1
, b2
, b3
, b4
39 a1
, a2
, a3
, a4
= string.match (first
, "(%d+)%.?(%d*).?(%d*)%-?(%d*)")
40 b1
, b2
, b3
, b4
= string.match (second
, "(%d+)%.?(%d*).?(%d*)%-?(%d*)")
41 return (a1
> b1
) or (a2
> b2
) or (a3
> b3
) or (a4
< b4
);
44 root
= "(" .. device
.. ")/"
45 source
= "root (" .. device
.. ")\nchainloader +1"
47 if (grub
.file_exist (root
.. "bootmgr") and
48 grub
.file_exist (root
.. "boot/bcd")) then
49 title
= "Windows Vista bootmgr"
50 elseif (grub
.file_exist (root
.. "ntldr") and
51 grub
.file_exist (root
.. "ntdetect.com") and
52 grub
.file_exist (root
.. "boot.ini")) then
53 title
= "Windows NT/2000/XP loader"
54 elseif (grub
.file_exist (root
.. "windows/win.com")) then
55 title
= "Windows 98/ME"
56 elseif (grub
.file_exist (root
.. "io.sys") and
57 grub
.file_exist (root
.. "command.com")) then
59 elseif (grub
.file_exist (root
.. "kernel.sys")) then
61 elseif (grub
.file_exist (root
.. "boot/loader") and
62 grub
.file_exist (root
.. "boot/device.hints")) then
63 source
= "root (" .. device
.. ")\nfreebsd /boot/loader" ..
64 "\nfreebsd_loadenv /boot/device.hints"
67 grub
.enum_file (enum_file
, root
.. "boot")
68 if kernel_num
~= 0 then
69 table.sort (kernels
, sort_kernel
)
70 for i
= 1, kernel_num
do
73 title
= "Linux " .. kernels
[i
]
74 source
= "root (" .. device
..
75 ")\nlinux /boot/vmlinuz-" .. kernels
[i
] ..
76 " root=UUID=" .. uuid
.. " ro"
78 if grub
.file_exist (root
.. "boot/initrd-" ..
79 kernels
[i
] .. ".img") then
80 initrd
= "\ninitrd /boot/initrd-" .. kernels
[i
] .. ".img"
81 elseif grub
.file_exist (root
.. "boot/initrd.img-" .. kernels
[i
]) then
82 initrd
= "\ninitrd /boot/initrd.img-" .. kernels
[i
]
83 elseif grub
.file_exist (root
.. "boot/initrd-" .. kernels
[i
]) then
84 initrd
= "\ninitrd /boot/initrd-" .. kernels
[i
]
89 grub
.add_menu (source
.. initrd
, title
)
90 grub
.add_menu (source
.. " single" .. initrd
,
91 title
.. " (single-user mode)")
98 local partition
= string.match (device
, ".*,(%d+)")
100 if (partition
~= nil) and (tonumber (partition
) > 4) then
107 grub
.add_menu (source
, title
)
111 grub
.enum_device (enum_device
)