Date: Fri, 16 Jul 2021 22:13:13 +0200 From: Michael Gmelin <freebsd@grem.de> To: Warner Losh <imp@bsdimp.com> Cc: Thomas Laus <lausts@acm.org>, Current FreeBSD <freebsd-current@freebsd.org> Subject: Re: EFI boot partition overwritten Message-ID: <ECA284DE-A0D3-4122-A830-B043ECE3CED6@grem.de> In-Reply-To: <CANCZdfqKcXrkc=aK=ck1yjgGjNPnKZjQwOV5TopEdLTjxGi%2BdQ@mail.gmail.com> References: <CANCZdfqKcXrkc=aK=ck1yjgGjNPnKZjQwOV5TopEdLTjxGi%2BdQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> On 16. Jul 2021, at 19:38, Warner Losh <imp@bsdimp.com> wrote: >=20 > =EF=BB=BFOn Fri, Jul 16, 2021 at 6:14 AM Thomas Laus <lausts@acm.org> wrot= e: >=20 >> Group: >>=20 >> This is an issue for more than just CURRENT. The 'usr/src/UPDATING' >> file has the instructions for updating the ZFS bootblocks but not the >> EFI partition. I recently upgraded a RELEASE-12.2 to RELEASE-13.0. The >> freebsd-update procedure did not upgrade the ZFS bootblocks. I forgot >> that this PC was UEFI only and overwrote the first partition with the >> gptzfsboot code. That made my system un-bootable. I found the recovery >> procedure on one of the FreeBSD forums and was able to reformat the EFI >> MSDOS partition, create the proper directory structure, and copy the >> loader.efi file to the correct location and filename using the Live >> Filesystem running on the installation CD. >>=20 >> I searched the man pages and the UPDATING file for instructions but came >> up empty and had to resort to finding the answer on one of the forums. >> The filenames have changed since FreeBSD first supported EFI and some of >> the forum instructions are out of date. My problem must be fairly >> common and the recovery procedure should be in a man page with a >> footnote or man reference somewhere on the install media. >>=20 >> Since CURRENT receives more updates to the EFI boot loader than the >> release versions, there should be instructions in the CURRENT >> 'usr/src/UPDATING' file on how to update the EFI bootcode. >>=20 >=20 > There should be. Yes. Last time I went hunting for a place to shoe-horn it= > in, I got distracted by something else. >=20 > The instructions are relatively straight forward. I'm writing them here fo= r > your benefit, and also in case someone wants to send me a diff/pull reques= t > to include them. Or better yet, put this in the handbook and we can > reference > a location from there. >=20 > WARNING: This is a quick run-through of how to do this if you need to. > The example commands given might not be exactly right for all installation= s > as differing numbers of partitions will change the '-i' parameters. >=20 > Frist, you need a partition that's of the right type. For GPT that type is= > `efi` > as shown in `gpart show <boot-device>` eg > # gpart show ada0 > =3D> 40 2000409184 ada0 GPT (954G) > 40 1600 - free - (800K) > 1640 1992292792 2 freebsd-ufs (950G) > 1992294432 7000000 3 freebsd-swap (3.3G) > 1999294432 1114792 4 efi (544M) >=20 > If you don't have one, you'll need to create one. In the above exmaple, > I had installed the system with a tiny partition for booting with legacy > BIOS, but then moved to booting with UEFI. I did this by turning off > swapping and doing the following: > # gpart resize -i 3 -s 7000000 ada0 > I then created a new efi partition: > # gpart add -t efi ada0 > and I let it autosize. >=20 > Next, I needed a FAT32 filesystem on that device. FAT16 usually will > work and often FAT12, but there are known examples of system integrators > that omit support for these last two (more the latter than the former sinc= e > it's viewed as a floppy only thing, and who uses floppies). I just used > newfs_msdos and mounted it: > # newfs_msdos -F 32 /dev/ada0p4 > # mount -t msdos /dev/ada0p4 /boot/efi >=20 > Next, you need to put a bootloader on the system. Unless you have > special needs, loader.efi is that loader. > # mkdir -p /boot/efi/efi/boot > # cp /boot/loader.efi /boot/efi/efi/boot/bootx64.efi >=20 > If you are using efibootmgr to set a location to boot from, generally peop= le > create a freebsd directory (we've registered /efi/freebsd with the proper > folks > to avoid conflicts): > # mkdir -p /boot/efi/efi/freebsd > # cp /boot/loader.efi /boot/efi/efi/freebsd > # efibootmgr -c -a -k /boot/kernel/kernel -l > /boot/efi/efi/freebsd/loader.efi -L "FreeBSD Boot" > though some vendors impose limits on how many boot envs you can create > and some do not allow any at all. >=20 It would be cool to also update the loader.efi man page to be a bit more use= ful (this is what 'zpool upgrade' refers to/will refer to in the future). -m > Warner
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ECA284DE-A0D3-4122-A830-B043ECE3CED6>