[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 0/1] inspect: Fix a bug in the *BSD root detection



Hello,

I've been reading the *BSD detection code in check_filesystem() in
inspect-fs.c in order to write a patch for OpenBSD detection that is
missing. Both, in FreeBSD and in NetBSD you have this piece of code:

 
    /* Ignore /dev/sda1 which is a shadow of the real root filesystem
     * that is probably /dev/sda5 (see:
     * http://www.freebsd.org/doc/handbook/disk-organization.html)
     */
    if (m->im_type == MOUNTABLE_DEVICE &&
        match (g, m->im_device, re_first_partition))
      return 0;

This assumption is not always true. First of all, the MBR partition
that hosts the disklabel could be any of the primary partitions. Not
just the first one. The OpenBSD installer for example will by default
use the 4th partition. I'm pretty sure you can change this in FreeBSD
and NetBSD too.

The other thing is that /dev/sda5 will not always be there. The problem
is the weird way the kernel maps the disklabel partitions:

https://github.com/torvalds/linux/blob/master/block/partitions/msdos.c#L303-L310

The kernel will not map a disklabel subpartition if it has the same
boundaries with the parent (MBR) partition or if its boundaries exceed
the disklabel.

In the disklabel's partition table 'a' is always the root partition, 'b'
is the swap, in OpenBSD and FreeBSD 'c' is the full hard disk. In NetBSD
'c' is the disklabel partition itself and 'd' is the full hard disk.
Those partitions are invalid for the kernel. If I have a *BSD
installation with just root and swap, the kernel will show 3 partitions:
/dev/sda1 for the disklabel, /dev/sda5 for root and /dev/sda6 for swap,
but If I only have a root partition then this will likely have the same
boundaries with the MBR partition and the kernel will not map it again
to /dev/sda5. In this case inspect_os() will completely miss the OS.

I tried to fix this by removing the code above and checking again for
duplicated *BSD root partitions after all the file systems have been
scanned to unmark the is_root. It's not the prettiest thing in the
world but I couldn't think of something better.

Nikos

Nikos Skalkotos (1):
  inspect: Fix a bug in the *BSD root detection

 src/guestfs-internal.h |  1 +
 src/inspect-fs.c       | 55 +++++++++++++++++++++++++++++++++-----------------
 src/inspect.c          |  6 ++++++
 3 files changed, 43 insertions(+), 19 deletions(-)

-- 
2.1.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]