From: Ian Campbell Subject: Re: [PATCH] Add HybridISO support for PyGrub2 Date: Tue, 25 Oct 2011 10:17:38 +0100 Message-ID: <1319534259.3385.224.camel@zakaz.uk.xensource.com> References: <201110251057.06774.hahn@univention.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <201110251057.06774.hahn@univention.de> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Philipp Hahn Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On Tue, 2011-10-25 at 09:56 +0100, Philipp Hahn wrote: > grub-mkrescue internally uses xorriso, which generates a > so-called "hybrid ISO": The ISO images also contains a DOS partition table, > which allows the identical ISO file to be stored on an USB stick for booting > from it. This breaks PyGrub, since it (wrongly) detects the DOS partition > table and uses the first partition instead of the complete ISO file. Is the problem here that, having detected a DOS partition, pygrub is then unwilling to accept that the partition contains an ISO9660 file system? Or is it that the DOS partition table covers something other than the ISO9660 data? Where does the kernel we want to boot actually live? Is there some reference to the layout of an hybridiso? i.e. what is the significance on 0x8006? What are the chances of false positives? > Add a check to detech HybridISO files and fall back to unpartitioned > operation. > > Signed-off-by: Philipp Hahn > --- a/tools/pygrub/src/pygrub > +++ b/tools/pygrub/src/pygrub > @@ -41,12 +41,16 @@ def enable_cursor(ison): > pass > > def is_disk_image(file): > + """Detect DOS partition table.""" > fd = os.open(file, os.O_RDONLY) > - buf = os.read(fd, 512) > + buf = os.read(fd, 0x8006) > os.close(fd) > > if len(buf) >= 512 and \ > struct.unpack("H", buf[0x1fe: 0x200]) == (0xaa55,): > + # HybridISO contains a DOS partition table for booting from USB > devices, but really is an ISO image > + if len(buf) >= 0x8006 and buf[0x8001:0x8006] == 'CD001': > + return False > return True > return False >