From owner-freebsd-hackers@freebsd.org Thu Apr 14 14:28:52 2016 Return-Path: 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 27E68B109AB for ; Thu, 14 Apr 2016 14:28:52 +0000 (UTC) (envelope-from allanjude@freebsd.org) Received: from mx1.scaleengine.net (mx1.scaleengine.net [209.51.186.6]) by mx1.freebsd.org (Postfix) with ESMTP id 0D61C167A for ; Thu, 14 Apr 2016 14:28:51 +0000 (UTC) (envelope-from allanjude@freebsd.org) Received: from [10.1.1.2] (unknown [10.1.1.2]) (Authenticated sender: allanjude.freebsd@scaleengine.com) by mx1.scaleengine.net (Postfix) with ESMTPSA id A1BF3D8F4 for ; Thu, 14 Apr 2016 14:28:50 +0000 (UTC) Subject: Re: A few stupid questions regarding MBR and boot0 To: freebsd-hackers@freebsd.org References: <20160414144849.7a08b1db@fujitsu> <20160414153627.7fc50247@fujitsu> From: Allan Jude Message-ID: <570FA922.1000401@freebsd.org> Date: Thu, 14 Apr 2016 10:28:50 -0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <20160414153627.7fc50247@fujitsu> Content-Type: text/plain; charset=windows-1252 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2016 14:28:52 -0000 On 2016-04-14 08:36, Aleksander Alekseev wrote: > 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 > There are multiple MBRs to choose from IIRC: /boot/boot0 just starts FreeBSD /boot/mbr presents a menu, where you pick which partition to start, including support for other operating systems (since it just loads the volume boot record of the indicated partition) -- Allan Jude