From owner-freebsd-bugs@freebsd.org Fri Jan 25 21:37:39 2019 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4B9F914C3DDD for ; Fri, 25 Jan 2019 21:37:39 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id D4A6974432 for ; Fri, 25 Jan 2019 21:37:38 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id 941A314C3DDC; Fri, 25 Jan 2019 21:37:38 +0000 (UTC) Delivered-To: bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6ECDF14C3DDB for ; Fri, 25 Jan 2019 21:37:38 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0812074431 for ; Fri, 25 Jan 2019 21:37:38 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id 13B0419E6 for ; Fri, 25 Jan 2019 21:37:37 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id x0PLbad7010588 for ; Fri, 25 Jan 2019 21:37:36 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id x0PLbajD010587 for bugs@FreeBSD.org; Fri, 25 Jan 2019 21:37:36 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 235206] Starting with a damaged GPT scheme under legacy BIOS Date: Fri, 25 Jan 2019 21:37:36 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: misc X-Bugzilla-Version: 12.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: kmachine@free.fr X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jan 2019 21:37:39 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D235206 Bug ID: 235206 Summary: Starting with a damaged GPT scheme under legacy BIOS Product: Base System Version: 12.0-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: misc Assignee: bugs@FreeBSD.org Reporter: kmachine@free.fr Created attachment 201403 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D201403&action= =3Dedit Patch to add an automatic GPT recovery feature to gptboot pmbr is the protective MBR program used by the FreeBSD GPT implementation. = It allows to boot a GPT system disk under legacy BIOS. Its main task is to fin= d a "freebsd-boot" partiton, load its content and execute it. This content, depending on the type of root file system, is either gptboot (UFS) or gptzfsboot (ZFS). pmbr has a nice feature: it can boot a disk even if its primary GPT header = is damaged, provided the backup header is healthy. To be clear, it only checks= the tag "EFI PART" at the beginning of the header. It does not verify the crc32= of the header nor the one of the partition table. The problem is that nor gptboot nor gptzfsboot handles correctly a damaged primary header and, as a result, the boot process dies after pmbr. To reproduce this issue (warning! This is destructive, don't do that unless= you don't care of the system you operate on): - Boot on a disc1.iso or a memstick image. - In the shell, identify the target disc. - For example, if the target disk is ada0, type: dd if=3D/dev/zero of=3D/dev/ada0 seek=3D1 count=3D1=20 - Reboot (you need to start in legacy BIOS mode). If the root file system is ZFS, you'll see something like this: --------------- shortening read at 20971505 from 16 to 15 gptzfsboot: No ZFS pools located, can't boot --------------- Or: --------------- gptzfsboot: error 12 lba 20971505 gptzfsboot: No ZFS pools located, can't boot --------------- This example is on a VM with a 10 GiB disk. It seems that the first error occurs when the disk is "fixed" and the last if the disk is "dynamic". If the root file system is UFS, you will get: --------------- gptboot: invalid primary GPT header gptboot: using backup GPT BTX loader 1.00 BTX version is 1.02 Consoles: internal video/keyboard BIOS drive C: is disk0 BIOS 639kB/3668928kB available memory FreeBSD/x86 bootstrap loader, Revision 1.1 Startup error in /boot/lua/loader.lua: LUA ERROR: cannot open /boot/lua/loader.lua: no such file or directory can't load 'kernel' OK _ --------------- I managed to bring a solution for gptboot. I thought that the base problem = is it does not mend the GPT scheme, despite it is aware of its corruption. It could, though. This the reason why I wrote a patch for /usr/src/stand/libsa/gpt.c. After applying this patch, gptboot recovers automatically the GPT scheme in the scenario where the primary header/table= are damaged and the backup header/table are valid. In such a case, with the patched gptboot you get: gptboot: invalid primary GPT header gptboot: trying to recover GPT... gptboot: GPT recovering -> SUCCESS And then, the boot process continue. I have to look for a gptzfsboot solution but I feel it's more complex. It doesn't use gpt.c apparently so I have to search deeper for this one. PS : this is more or less the first time I propose a patch so be indulgent = with me as I don't know many things in FreeBSD programming. I tried to do my bes= t. --=20 You are receiving this mail because: You are the assignee for the bug.=