Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Apr 2016 14:00:14 +0200 (CEST)
From:      =?ISO-8859-1?Q?Trond_Endrest=F8l?= <Trond.Endrestol@fagskolen.gjovik.no>
To:        Aleksander Alekseev <afiskon@devzen.ru>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: A few stupid questions regarding MBR and boot0
Message-ID:  <alpine.BSF.2.20.1604141353310.14591@mail.fig.ol.no>
In-Reply-To: <20160414144849.7a08b1db@fujitsu>
References:  <20160414144849.7a08b1db@fujitsu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 14 Apr 2016 14:48+0300, Aleksander Alekseev wrote:

> Hello
> 
> I was trying to figure out how FreeBSD boot process works and noticed
> something strange.
> 
> 1) If I understand correctly first 512 bytes of /dev/ad0
> and /boot/boot0 file should match, but they don't:
> 
> http://afiskon.ru/s/31/665dc9755c_mbr.txt

The MBR consists of two parts, the bootcode and the partition table. 
Any discrepancies is generally due to the partition table being zero 
in /boot/boot0 and realistic data stored in block 0.

> Could someone please explain why they don't match?
> 
> 2) I tried to compile boot0 from source (r297956) but compilation
> failed:
> 
> ```
> $ cd sys/boot/i386/boot0
> $ make
> 
> Warning: Object directory not changed from
> original /usr/home/eax/freebsd-src/sys/boot/i386/boot0
> 
> /usr/local/bin/clang38 -O2 -pipe -O2 -pipe -g -march=native
> -DVOLUME_SERIAL -DPXE -DFLAGS=0x8f  -DTICKS=0xb6  -DCOMSPEED="7 << 5 +
> 3" -march=i386 -ffreestanding  -msoft-float -m32 -std=gnu99
> -Qunused-arguments -m32 -c boot0.S -o boot0.o clang -cc1as: fatal
> error: error in backend: invalid .org offset '430' (at offset '439')
> *** Error code 1
> 
> Stop.
> make: stopped in /usr/home/eax/freebsd-src/sys/boot/i386/boot0
> ```
> 
> Am I doing something wrong?

I have never attempted to build the FreeBSD sources outside /usr/src. 
The advice below might be plain wrong.

Try:

  cd sys/boot/i386/boot0
  make clean
  make OBJDIR=/usr/home/eax/freebsd-obj obj
  make OBJDIR=/usr/home/eax/freebsd-obj all

If you want it installed, run

  make OBJDIR=/usr/home/eax/freebsd-obj install

-- 
+-------------------------------+------------------------------------+
| Vennlig hilsen,               | Best regards,                      |
| Trond Endrestøl,              | Trond Endrestøl,                   |
| IT-ansvarlig,                 | System administrator,              |
| Fagskolen Innlandet,          | Gjøvik Technical College, Norway,  |
| tlf. mob.   952 62 567,       | Cellular...: +47 952 62 567,       |
| sentralbord 61 14 54 00.      | Switchboard: +47 61 14 54 00.      |
+-------------------------------+------------------------------------+
From owner-freebsd-hackers@freebsd.org  Thu Apr 14 12:05:43 2016
Return-Path: <owner-freebsd-hackers@freebsd.org>
Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 69B3EB10EA4
 for <freebsd-hackers@mailman.ysv.freebsd.org>;
 Thu, 14 Apr 2016 12:05:43 +0000 (UTC)
 (envelope-from trond@fagskolen.gjovik.no)
Received: from smtp.fagskolen.gjovik.no (smtp.fagskolen.gjovik.no
 [IPv6:2001:700:1100:1:200:ff:fe00:b])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client CN "smtp.fagskolen.gjovik.no",
 Issuer "Fagskolen i Gj??vik" (not verified))
 by mx1.freebsd.org (Postfix) with ESMTPS id 137D91226
 for <freebsd-hackers@freebsd.org>; Thu, 14 Apr 2016 12:05:42 +0000 (UTC)
 (envelope-from trond@fagskolen.gjovik.no)
Received: from mail.fig.ol.no (localhost [127.0.0.1])
 by mail.fig.ol.no (8.15.2/8.15.2) with ESMTPS id u3EC5SAF070307
 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO);
 Thu, 14 Apr 2016 14:05:29 +0200 (CEST)
 (envelope-from trond@fagskolen.gjovik.no)
Received: from localhost (trond@localhost)
 by mail.fig.ol.no (8.15.2/8.15.2/Submit) with ESMTP id u3EC5SdD070304;
 Thu, 14 Apr 2016 14:05:28 +0200 (CEST)
 (envelope-from trond@fagskolen.gjovik.no)
X-Authentication-Warning: mail.fig.ol.no: trond owned process doing -bs
Date: Thu, 14 Apr 2016 14:05:28 +0200 (CEST)
From: =?ISO-8859-1?Q?Trond_Endrest=F8l?= <Trond.Endrestol@fagskolen.gjovik.no>
Sender: Trond.Endrestol@fagskolen.gjovik.no
To: Aleksander Alekseev <afiskon@devzen.ru>
cc: freebsd-hackers@freebsd.org
Subject: Re: A few stupid questions regarding MBR and boot0
In-Reply-To: <alpine.BSF.2.20.1604141353310.14591@mail.fig.ol.no>
Message-ID: <alpine.BSF.2.20.1604141404540.14591@mail.fig.ol.no>
References: <20160414144849.7a08b1db@fujitsu>
 <alpine.BSF.2.20.1604141353310.14591@mail.fig.ol.no>
User-Agent: Alpine 2.20 (BSF 67 2015-01-07)
Organization: Fagskolen Innlandet
OpenPGP: url=http://fig.ol.no/~trond/trond.key
MIME-Version: 1.0
X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED, AWL autolearn=ham
 autolearn_force=no version=3.4.1
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on mail.fig.ol.no
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8BIT
X-Content-Filtered-By: Mailman/MimeDel 2.1.21
X-BeenThere: freebsd-hackers@freebsd.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Technical Discussions relating to FreeBSD
 <freebsd-hackers.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-hackers>, 
 <mailto:freebsd-hackers-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-hackers/>;
List-Post: <mailto:freebsd-hackers@freebsd.org>
List-Help: <mailto:freebsd-hackers-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-hackers>, 
 <mailto:freebsd-hackers-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 14 Apr 2016 12:05:43 -0000

On Thu, 14 Apr 2016 14:00+0200, Trond Endrestøl wrote:

> On Thu, 14 Apr 2016 14:48+0300, Aleksander Alekseev wrote:
> 
> > Hello
> > 
> > I was trying to figure out how FreeBSD boot process works and noticed
> > something strange.
> > 
> > 1) If I understand correctly first 512 bytes of /dev/ad0
> > and /boot/boot0 file should match, but they don't:
> > 
> > http://afiskon.ru/s/31/665dc9755c_mbr.txt
> 
> The MBR consists of two parts, the bootcode and the partition table. 
> Any discrepancies is generally due to the partition table being zero 
> in /boot/boot0 and realistic data stored in block 0.

BTW, check out /boot/mbr.

> > Could someone please explain why they don't match?
> > 
> > 2) I tried to compile boot0 from source (r297956) but compilation
> > failed:
> > 
> > ```
> > $ cd sys/boot/i386/boot0
> > $ make
> > 
> > Warning: Object directory not changed from
> > original /usr/home/eax/freebsd-src/sys/boot/i386/boot0
> > 
> > /usr/local/bin/clang38 -O2 -pipe -O2 -pipe -g -march=native
> > -DVOLUME_SERIAL -DPXE -DFLAGS=0x8f  -DTICKS=0xb6  -DCOMSPEED="7 << 5 +
> > 3" -march=i386 -ffreestanding  -msoft-float -m32 -std=gnu99
> > -Qunused-arguments -m32 -c boot0.S -o boot0.o clang -cc1as: fatal
> > error: error in backend: invalid .org offset '430' (at offset '439')
> > *** Error code 1
> > 
> > Stop.
> > make: stopped in /usr/home/eax/freebsd-src/sys/boot/i386/boot0
> > ```
> > 
> > Am I doing something wrong?
> 
> I have never attempted to build the FreeBSD sources outside /usr/src. 
> The advice below might be plain wrong.
> 
> Try:
> 
>   cd sys/boot/i386/boot0
>   make clean
>   make OBJDIR=/usr/home/eax/freebsd-obj obj
>   make OBJDIR=/usr/home/eax/freebsd-obj all
> 
> If you want it installed, run
> 
>   make OBJDIR=/usr/home/eax/freebsd-obj install

-- 
+-------------------------------+------------------------------------+
| Vennlig hilsen,               | Best regards,                      |
| Trond Endrestøl,              | Trond Endrestøl,                   |
| IT-ansvarlig,                 | System administrator,              |
| Fagskolen Innlandet,          | Gjøvik Technical College, Norway,  |
| tlf. mob.   952 62 567,       | Cellular...: +47 952 62 567,       |
| sentralbord 61 14 54 00.      | Switchboard: +47 61 14 54 00.      |
+-------------------------------+------------------------------------+
From owner-freebsd-hackers@freebsd.org  Thu Apr 14 12:37:18 2016
Return-Path: <owner-freebsd-hackers@freebsd.org>
Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3E33EAECE8D
 for <freebsd-hackers@mailman.ysv.freebsd.org>;
 Thu, 14 Apr 2016 12:37:18 +0000 (UTC)
 (envelope-from afiskon@devzen.ru)
Received: from relay11.nicmail.ru (relay11.nicmail.ru [195.208.3.7])
 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id E901817CF
 for <freebsd-hackers@freebsd.org>; Thu, 14 Apr 2016 12:37:17 +0000 (UTC)
 (envelope-from afiskon@devzen.ru)
Received: from [109.70.25.187] (port=35887 helo=fujitsu)
 by f06.mail.nic.ru with esmtp (Exim 5.55)
 (envelope-from <afiskon@devzen.ru>)
 id 1aqgWQ-000K7C-2E; Thu, 14 Apr 2016 15:37:22 +0300
Received: from [93.174.131.138] (account afiskon@devzen.ru HELO fujitsu)
 by proxy08.mail.nic.ru (Exim 5.55)
 with id 1aqgWA-00044W-HY; Thu, 14 Apr 2016 15:37:06 +0300
Date: Thu, 14 Apr 2016 15:36:27 +0300
From: Aleksander Alekseev <afiskon@devzen.ru>
To: Trond =?UTF-8?B?RW5kcmVzdMO4bA==?= <Trond.Endrestol@fagskolen.gjovik.no>
Cc: freebsd-hackers@freebsd.org
Subject: Re: A few stupid questions regarding MBR and boot0
Message-ID: <20160414153627.7fc50247@fujitsu>
In-Reply-To: <alpine.BSF.2.20.1604141353310.14591@mail.fig.ol.no>
References: <20160414144849.7a08b1db@fujitsu>
 <alpine.BSF.2.20.1604141353310.14591@mail.fig.ol.no>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-BeenThere: freebsd-hackers@freebsd.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Technical Discussions relating to FreeBSD
 <freebsd-hackers.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-hackers>, 
 <mailto:freebsd-hackers-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-hackers/>;
List-Post: <mailto:freebsd-hackers@freebsd.org>
List-Help: <mailto:freebsd-hackers-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-hackers>, 
 <mailto:freebsd-hackers-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 14 Apr 2016 12:37:18 -0000

Hello, Trond

Thanks for your replies.

> > 1) If I understand correctly first 512 bytes of /dev/ad0
> > and /boot/boot0 file should match, but they don't:
> > 
> > http://afiskon.ru/s/31/665dc9755c_mbr.txt
> 
> The MBR consists of two parts, the bootcode and the partition table. 
> Any discrepancies is generally due to the partition table being zero 
> in /boot/boot0 and realistic data stored in block 0.

Yes, but if I'm not mistaken partition table starts only at 0x1be. But
in my case data is not just slightly different in last few bytes. Its
not the same at all.

> BTW, check out /boot/mbr.

OK, this looks like something I have on ad0. But this file is not
mentioned in corresponding chapters of Handbook [1] or Architecture
Handbook [2]. Besides Architecture Handbook clearly states:

"""
Indeed, boot0 /is/ the MBR.
"""

If /boot/boot0 is MBR then what is /boot/mbr? Current version of
Handbook mentions it twice in 18.3.2 and doesn't exactly explains what
this file is for. According to FreeBSD 8.4 Handbook [3]:

"""
By default, the MBR installed by fdisk(8) is such an MBR and is based
on /boot/mbr.
"""

Do I right understand that current version of Handbook is wrong
regarding:

"""
The MBR installed by the FreeBSD installer is based on /boot/boot0.
"""

... and in fact boot0 is only used in dual-boot case?

BTW `cd sys/boot/i386/mbr && make` works as expected.

> I have never attempted to build the FreeBSD sources outside /usr/src. 
> The advice below might be plain wrong.
> 
> Try:
> 
>   cd sys/boot/i386/boot0
>   make clean
>   make OBJDIR=/usr/home/eax/freebsd-obj obj
>   make OBJDIR=/usr/home/eax/freebsd-obj all
> 
> If you want it installed, run
> 
>   make OBJDIR=/usr/home/eax/freebsd-obj install
> 

Doesn't work:

```
$ make OBJDIR=/usr/home/eax/freebsd-obj obj
mkdir: /usr/obj/usr: Permission denied
*** Error code 1

Stop.
make: stopped in /usr/home/eax/freebsd-src/sys/boot/i386/boot0
```

I also tried `OBJDIR=... make`. Naturally I could try `sudo make ...`
but if I'm not wrong boot0 doesn't have any dependencies, it's a
reasonably simple assembly program.

[1]https://www.freebsd.org/doc/handbook/boot-introduction.html
[2]https://www.freebsd.org/doc/en/books/arch-handbook/boot-boot0.html
[3]https://docs.freebsd.org/doc/8.4-RELEASE/share/doc/freebsd/handbook/boot-introduction.html

-- 
Best regards,
Aleksander Alekseev
http://eax.me/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.2.20.1604141353310.14591>