Reinstalling boot blocks on a ZFS-only system

Jeremy Chadwick jdc at koitsu.org
Mon May 13 03:17:44 UTC 2013


On Sun, May 12, 2013 at 10:20:26PM -0400, Chris Ross wrote:
> 
> On May 12, 2013, at 16:58 , Jeremy Chadwick <jdc at koitsu.org> wrote:
> > The command is "gpart bootcode", however I cannot be bothered to
> > remember the syntax; I imagine it greatly depends on if you're using GPT
> > vs. MBR, in addition to what your partition layout look like.  Meaning:
> > there is no "universal standard", it depends entirely on how you set
> > your stuff up.  But the command is definitely "gpart bootcode".
> > 
> > Next, AFAIK there is no need to boot alternate media (CD etc.) to
> > accomplish this.
> > 
> > You may also need to set kern.geom.debugflags=0x10 to inhibit GEOM's
> > "safety measure" / to permit writing to LBA 0; see GEOM(4) and search
> > for the word "foot".
> 
>   In the past, I've found I've been unable to install all of the bootblocks if I
> boot from the ZFS root.  When booting from a cd, the basic:
> 
> 	gpart bootcode -p ${bootdir}/zfsboot ${disk}
> 	dd if=${bootdir}zfsloader of=/dev/${disk}a bs=512 oseek=1024 conv=notrunc,sync
> 
> works.  But, if I boot from ZFS, then I can't dd anything into the front of the 
> drives.  Right now, the problem after booting from the CD, is trying to mount
> a read/write filesystem (mfs, or the like) so that I can scp the bootblocks onto the
> system and install them.  BUt, I eventually found the command I'd lost. so I 
> think I'm alright.  Thanks...

What does "unable to install" mean?  What output/error do you get?  I am
going to assume you get EPERM (Operation not permitted), which would be
caused by GEOM's "preventive foot-shooting" (keep reading).

Is there some reason you're sticking with the MBR scheme instead of GPT?
Taken from GEOM(4):

     Both types of bootstrap code are used to boot from the GUID Partition Ta-
     ble.  First, a protective MBR is embedded into the first disk sector from
     the /boot/pmbr image.  It searches the GPT freebsd-boot partition (see
     the PARTITION TYPES section) in the GPT and runs the next bootstrap stage
     from it.  The freebsd-boot partition should be smaller than 545 KB.
     There are two variants of bootstrap code to write to this partition:
     /boot/gptboot and /boot/gptzfsboot.  /boot/gptboot is used to boot from
     UFS.  It searches freebsd-ufs GPT partitions and starts /boot/loader (the
     third bootstrap stage) if found.  The /boot/gptzfsboot is used to boot
     from ZFS.  It searches freebsd-zfs GPT partitions and starts
     /boot/zfsloader if found.

So by moving to GPT you would relieve yourself of a lot of pain,
particularly that dd nonsense (which looks like it could seriously hurt
you, especially if you're doing it by hand by booting some CD).  An
added bonus to using the GPT scheme is that you can align your
partitions easier for 4096-byte sector drives.

With GPT, I believe you'd use this, and only this:

sysctl kern.geom.debugflags=16
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ${disk}
sysctl kern.geom.debugflags=0

(That also assumes the GPT freebsd-boot partition is what's comes first
on $disk (i.e. index 1), as it should be)

If you're using mirrors, you would need to do the gpart command for each
disk that is part of your mirror vdev; i.e. if ada0 and ada1 are a
mirror, issue the gpart command against ada0 and ada1, otherwise you may
find that if one of your disks dies you might not be able to boot from
the system.

All this comes from:

https://wiki.freebsd.org/RootOnZFS/GPTZFSBoot/Mirror

(You'll find the EPERM situation mentioned there too)

I should also note that if you do go with GPT, please use a larger
freebsd-boot partition size (512KBytes is ideal, not 64KBytes), because
the bootstraps are often >64KBytes these days.

http://www.wonkity.com/~wblock/docs/html/ssd.html

Good luck.

-- 
| Jeremy Chadwick                                   jdc at koitsu.org |
| UNIX Systems Administrator                http://jdc.koitsu.org/ |
| Mountain View, CA, US                                            |
| Making life hard for others since 1977.             PGP 4BD6C0CB |


More information about the freebsd-stable mailing list