All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Ian Campbell <ian.campbell@citrix.com>
Cc: wei.liu2@citrix.com, ian.jackson@eu.citrix.com,
	745419-forwarded@bugs.debian.org, xen-devel@lists.xen.org
Subject: Re: [PATCH] tools: pygrub: if partition table is empty, try treating as a whole disk
Date: Wed, 11 Nov 2015 14:57:51 +0000	[thread overview]
Message-ID: <20151111145751.GD10274@zion.uk.xensource.com> (raw)
In-Reply-To: <1446734772-27405-1-git-send-email-ian.campbell@citrix.com>

On Thu, Nov 05, 2015 at 02:46:12PM +0000, Ian Campbell wrote:
> pygrub (in identify_disk_image()) detects a DOS style partition table
> via the presence of the 0xaa55 signature at the end of the first
> sector of the disk.
> 
> However this signature is also present in whole-disk configurations
> when there is an MBR on the disk. Many filesystems (e.g. ext[234])
> include leading padding in their on disk format specifically to enable
> this.
> 
> So if we think we have a DOS partition table but do not find any
> actual partition table entries we may as well try looking at it as a
> whole disk image. Worst case is we probe and find there isn't anything
> there.
> 
> This was reported by Sjors Gielen in Debian bug #745419. The fix was
> inspired by a patch by Adi Kriegisch in
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=745419#27
> 
> Tested by genext2fs'ing my /boot into a new raw image (works) and
> then:
>    dd if=/usr/lib/grub/i386-pc/g2ldr.mbr of=img conv=notrunc bs=512 count=1
> 
> to add an MBR (with 0xaa55 signature) to it, which after this patch
> also works.
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> Cc: 745419-forwarded@bugs.debian.org

Acked-by: Wei Liu <wei.liu2@citrix.com>

> ---
>  tools/pygrub/src/pygrub | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
> index e4aedda..40f9584 100755
> --- a/tools/pygrub/src/pygrub
> +++ b/tools/pygrub/src/pygrub
> @@ -156,6 +156,11 @@ def get_partition_offsets(file):
>          else:
>              part_offs.append(offset)
>  
> +    # We thought we had a DOS partition table, but didn't find any
> +    # actual valid partition entries. This can happen because an MBR
> +    # (e.g. grubs) may contain the same signature.
> +    if not part_offs: part_offs = [0]
> +
>      return part_offs
>  
>  class GrubLineEditor(curses.textpad.Textbox):
> -- 
> 2.1.4
> 

  reply	other threads:[~2015-11-11 14:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 14:46 [PATCH] tools: pygrub: if partition table is empty, try treating as a whole disk Ian Campbell
2015-11-11 14:57 ` Wei Liu [this message]
2015-11-11 15:39   ` Ian Jackson
2015-11-16 11:07     ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151111145751.GD10274@zion.uk.xensource.com \
    --to=wei.liu2@citrix.com \
    --cc=745419-forwarded@bugs.debian.org \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.