Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Oct 2019 23:54:41 +0000
From:      Johannes Totz <johannes@jo-t.de>
To:        Andriy Gapon <avg@FreeBSD.org>, freebsd-fs@freebsd.org
Subject:   Re: zpool attach/resilver trashes bsdlabel bootcode
Message-ID:  <2ca27aa3-bec8-db97-20fb-bfdc37ad7ef7@jo-t.de>
In-Reply-To: <f3a4d3af-db4f-7689-fa67-e133dbd42364@FreeBSD.org>
References:  <qp4pkj$7f28$1@blaine.gmane.org> <f3a4d3af-db4f-7689-fa67-e133dbd42364@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 28/10/2019 13:06, Andriy Gapon wrote:
> On 27/10/2019 22:02, Johannes Totz wrote:
>> Hi there,
>>
>> how does a zpool attach and subsequent resilver deal with the bootcode that's
>> inside a bsdlabel partition?
>> I'm trying to create a bootable image (with mbr, slices, and partition) but
>> every time I attach the partition to a pool the bootcode ends up garbled and the
>> image is not bootable.
>>
>> For example:
>>> /usr/bin/truncate -s 1025m /var/tmp/usbbootpoolimg.raw
>>> /sbin/mdconfig -a -t vnode -u 3 -S 512 -y 16 -x 63 -f /var/tmp/usbbootpoolimg.raw
>>>
>>> /sbin/gpart create -s mbr /dev/md3
>>> /sbin/gpart add -s 1g -t freebsd /dev/md3
>>> /sbin/gpart set -a active -i 1 /dev/md3
>>> /sbin/gpart bootcode -b /boot/boot0 /dev/md3
>>> /sbin/gpart create -s bsd /dev/md3s1
>>> /sbin/gpart add -t freebsd-zfs /dev/md3s1
>>>
>>> /sbin/bsdlabel -B /dev/md3s1
>>> /bin/dd if=/boot/zfsboot of=/var/tmp/zfsboot1 count=1
>>> /sbin/gpart bootcode -b /var/tmp/zfsboot1 /dev/md3s1
>>> /bin/dd if=/boot/zfsboot of=/dev/md3s1a skip=1 seek=1024
>>
>> All good up to here. Image is bootable, but there is no pool yet in the image so
>> the bootloader complains. Fine.
>> Then:
>>
>>> /sbin/zpool attach bootpool gpt/boot2 /dev/md3s1a
>>
>> Now the freshly installed bootcode is trashed. If I try to boot this it makes it
>> to the F1 boot prompt (the mbr part) but then hangs indefinitely.
>>
>> If I write the bootcode again, after the pool resilver is done then the image
>> boots.
>>
>> To me, the bootcode is part of the partitioning scheme, not part of the pool
>> that needs resilvering.
>> Any ideas?
> 
> You write the second part of zfsboot inside of ZFS managed area.
> So, you should do that *after* ZFS initializes the partition.

I had https://www.freebsd.org/cgi/man.cgi?query=zfsboot interpreted to 
mean that zfs wont touch the special boot area (even though it's under 
zfs control).

Is that vdev initialisation the only time that the bootcode gets 
overwritten? Never on "normal" resilver?


Cheers,

Johannes



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2ca27aa3-bec8-db97-20fb-bfdc37ad7ef7>