Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MSY0T-0001bc-Gr for mharc-grub-devel@gnu.org; Sun, 19 Jul 2009 11:08:53 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MSY0R-0001Zg-RZ for grub-devel@gnu.org; Sun, 19 Jul 2009 11:08:51 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MSY0M-0001T9-W0 for grub-devel@gnu.org; Sun, 19 Jul 2009 11:08:51 -0400 Received: from [199.232.76.173] (port=53287 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MSY0M-0001SL-KI for grub-devel@gnu.org; Sun, 19 Jul 2009 11:08:46 -0400 Received: from mail-fx0-f216.google.com ([209.85.220.216]:52097) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MSY0L-0001QR-PI for grub-devel@gnu.org; Sun, 19 Jul 2009 11:08:46 -0400 Received: by fxm12 with SMTP id 12so76413fxm.42 for ; Sun, 19 Jul 2009 08:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:content-type :date:message-id:mime-version:x-mailer; bh=wFRhG4C+cOyyhYUGdrwns6SrATkhrXxP2DHODbF3f/g=; b=SGUDI9tg5LRDVSMiYJl2Eybk430o4GmlBsZ6TAKvaTmAJdU4L5dtNEvEOfKY4nbG41 jL+NR5jGCj4uO1SvgqOVtttqPkbEUPL1E1MRYAuXXv+NBkxY5RX7IahIAK9ELOVgTklW eeGg28Yfu7A3tY+3Fi9wsVXAiQ46Vp0Qp5eQM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:content-type:date:message-id:mime-version:x-mailer; b=UQWySLRd4hX8cis9dTzmCH0/iaVjHOFAk86dhb6OewgdNSneBY8stfu3lvZshK1Hv6 dTv4hxGfdOhaRGMpHBQpuY1IroOkaeYQxW46Vpny9KyJ8SA4lyxnOa/D19fkE9wwqjYQ w0TE5QpEO2vrRIG7w39JXbRyD0+ysE/t1AN7U= Received: by 10.103.182.1 with SMTP id j1mr1677998mup.119.1248015734525; Sun, 19 Jul 2009 08:02:14 -0700 (PDT) Received: from ?192.168.178.23? (dslc-082-083-015-115.pools.arcor-ip.net [82.83.15.115]) by mx.google.com with ESMTPS id e9sm17058947muf.32.2009.07.19.08.02.13 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 19 Jul 2009 08:02:14 -0700 (PDT) From: Ron To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="=-PdJP7RyUj5fSs20VHbgt" Date: Sun, 19 Jul 2009 17:01:10 +0200 Message-Id: <1248015670.3160.50.camel@ronsnb> Mime-Version: 1.0 X-Mailer: Evolution 2.27.4.1 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Lua scripts for booting LiveCD iso files X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Jul 2009 15:08:52 -0000 --=-PdJP7RyUj5fSs20VHbgt Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi, I've written two lua scripts that can automatically detect and boot LiveCD iso files. I'm using these scripts on my USB-Stick, so I can just put the LiveCD iso file on it and use it and don't have to use the different LiveCD to USB tools, which often not allow more than one Live System on one USB-Stick. The first script listisos.lua lists all iso files in a specific folder. The folder can be specified with an environment variable "isofolder" or if it is not set it looks in "/boot/isos". The second script bootiso.lua actually boots an iso file specified with the "isofile" environment variable and is used for the menuentries that the listisos.lua script creates. The following LiveCD types are currently supported: * Grml * Sidux * Ubuntu --=-PdJP7RyUj5fSs20VHbgt Content-Disposition: attachment; filename="listisos.lua" Content-Type: text/x-lua; name="listisos.lua"; charset="UTF-8" Content-Transfer-Encoding: 7bit #!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 . -- isofolder = grub.getenv ("isofolder") if (isofolder == nil) then isofolder = "/boot/isos" end function enum_file (name) local title = string.match (name, "(.*)%.[iI][sS][oO]") if (title) then local source = "set isofile=" .. isofolder .. "/" .. name .. "\nsource /boot/grub/bootiso.lua" grub.add_menu (source, title) end end grub.enum_file (enum_file, isofolder) --=-PdJP7RyUj5fSs20VHbgt Content-Disposition: attachment; filename="bootiso.lua" Content-Type: text/x-lua; name="bootiso.lua"; charset="UTF-8" Content-Transfer-Encoding: 7bit #!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")) --=-PdJP7RyUj5fSs20VHbgt--