#!lua -- -- Copyright (C) 2009 Free Software Foundation, Inc. -- -- GRUB is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- GRUB is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with GRUB. If not, see . -- function bootiso (isofile) local err_no local err_msg local function print_error (msg) print ("Error: " .. msg) grub.run ("read") end local function find_file (folder, match) local filename local function enum_file (name) if (filename == nil) then filename = string.match (name, match) end end grub.enum_file (enum_file, folder) if (filename) then return folder .. "/" .. filename else return nil end end local function try_boot_generic () local grubcfg = "(loop)/boot/grub/grub.cfg" if (grub.file_exist (grubcfg)) then grub.run ("configfile " .. grubcfg) return true end return false end local function try_boot_grml () local linux = "(loop)/boot/grml/linux26" local initrd = "(loop)/boot/grml/initrd.gz" local params = "findiso=" .. isofile .. " apm=power-off vga=791 quiet boot=live nomce" if (grub.file_exist ("(loop)/GRML/grml-version") and grub.file_exist (linux) and grub.file_exist (initrd)) then grub.run ("linux " .. linux .. " " .. params) grub.run ("initrd " .. initrd) return true end return false end local function try_boot_sidux () local linux = find_file ("(loop)/boot", "vmlinuz%-.*%-sidux%-.*") local initrd = find_file ("(loop)/boot", "initrd%.img%-.*%-sidux%-.*") local params = "fromiso=" .. isofile .. " boot=fll quiet vga=791" if (linux and grub.file_exist (linux) and initrd and grub.file_exist (initrd)) then grub.run ("linux " .. linux .. " " .. params) grub.run ("initrd " .. initrd) return true end return false end local function try_boot_ubuntu () local linux = "(loop)/casper/vmlinuz" local initrd = "(loop)/casper/initrd.gz" local params = "boot=casper iso-scan/filename=" .. isofile .. " quiet splash noprompt --" if (grub.file_exist ("(loop)/preseed/ubuntu.seed") and grub.file_exist (linux) and grub.file_exist (initrd)) then grub.run ("linux " .. linux .. " " .. params) grub.run ("initrd " .. initrd) return true end return false end if (isofile == nil) then print_error ("variable 'isofile' is undefined") elseif (not grub.file_exist (isofile)) then print_error ("file '" .. isofile .. "' does not exist") else err_no,err_msg = grub.run ("loopback loop " .. isofile) if (err_no ~= 0) then print_error ("Cannot load ISO: " .. err_msg) else if (try_boot_grml ()) then elseif (try_boot_sidux ()) then elseif (try_boot_ubuntu ()) then elseif (try_boot_generic ()) then else print_error ("Unsupported ISO type") end end end end bootiso (grub.getenv ("isofile"))