From nobody Fri Jul 21 02:37:45 2023 X-Original-To: freebsd-current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R6Ycr107lz4nPmX for ; Fri, 21 Jul 2023 02:37:48 +0000 (UTC) (envelope-from mike@mail2.karels.net) Received: from mail2.karels.net (mail2.karels.net [3.19.118.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "freebsd", Issuer "freebsd" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R6Ycp4tzMz4RWC for ; Fri, 21 Jul 2023 02:37:46 +0000 (UTC) (envelope-from mike@mail2.karels.net) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=karels.net header.s=mail2 header.b=lGsQ3ESl; spf=none (mx1.freebsd.org: domain of mike@mail2.karels.net has no SPF policy when checking 3.19.118.201) smtp.mailfrom=mike@mail2.karels.net; dmarc=none Received: from mail2.karels.net (localhost [127.0.0.1]) by mail2.karels.net (8.17.1/8.17.1) with ESMTPS id 36L2bjjM049892 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 20 Jul 2023 21:37:45 -0500 (CDT) (envelope-from mike@mail2.karels.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karels.net; s=mail2; t=1689907065; bh=Q5Hznyb7fMiIkroRdiyiLaNdDB5nvgQ3W/d4Ia9nXGw=; h=To:cc:From:Reply-to:Subject:In-reply-to:Date; b=lGsQ3ESlR6GtTlKRO5CXmHxDK0ut0OGoMCs5N9Ag76Sodw42RkriNK0A0CPkAkXKm 4sJDoKorco4NGK3x0B4ip2vs1AWEMx3En8ucvL/QqBTMbIQt3+w5p6oxiLpZ5eNdfZ iK3GPZaYyrmnPXdNM4l10tS4DmE1TvEfYwYdxmzSqTwXcJb27ovvcha1dg78xfflgj tK+OILsztpd5BlDcHoLRgTSOSoFBqzT3AiZnz0RRW/owj+aljHIrERJqcGG+CJ/1Wt mBoTi+WBdYDLhNP8gwbxFZG342M/uZRauNV5L6SNVXwdWV4u91iDOKu7o+UNqlFLzo r9OPYciSTRLzg== Received: (from mike@localhost) by mail2.karels.net (8.17.1/8.17.1/Submit) id 36L2bjqk049891; Thu, 20 Jul 2023 21:37:45 -0500 (CDT) (envelope-from mike) Message-Id: <202307210237.36L2bjqk049891@mail2.karels.net> To: Mateusz Guzik cc: Current FreeBSD From: Mike Karels Reply-to: mike@karels.net Subject: Re: confusion about root partition causes panic during startup In-reply-to: Your message of Thu, 20 Jul 2023 23:13:31 +0200. List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <49889.1689907065.1@mail2.karels.net> Content-Transfer-Encoding: quoted-printable Date: Thu, 20 Jul 2023 21:37:45 -0500 X-Spamd-Result: default: False [-2.95 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; NEURAL_HAM_SHORT(-0.95)[-0.947]; FORGED_SENDER(0.30)[mike@karels.net,mike@mail2.karels.net]; R_DKIM_ALLOW(-0.20)[karels.net:s=mail2]; MIME_GOOD(-0.10)[text/plain]; FREEFALL_USER(0.00)[mike]; HAS_REPLYTO(0.00)[mike@karels.net]; FROM_HAS_DN(0.00)[]; DMARC_NA(0.00)[karels.net]; ARC_NA(0.00)[]; BLOCKLISTDE_FAIL(0.00)[3.19.118.201:server fail]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_NEQ_ENVFROM(0.00)[mike@karels.net,mike@mail2.karels.net]; ASN(0.00)[asn:16509, ipnet:3.16.0.0/14, country:US]; RCVD_TLS_LAST(0.00)[]; MID_RHS_MATCH_FROMTLD(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; REPLYTO_ADDR_EQ_FROM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-current@freebsd.org]; TO_DN_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[karels.net:+]; MIME_TRACE(0.00)[0:+]; FREEMAIL_TO(0.00)[gmail.com]; R_SPF_NA(0.00)[no SPF record] X-Rspamd-Queue-Id: 4R6Ycp4tzMz4RWC X-Spamd-Bar: -- Mateusz Guzik wrote: > On 7/20/23, Mike Karels wrote: > > I installed an additional NVME drive on a system, and then booted. It > > turns > > out that the new drive became nda0, renumbering the other drives. The > > loader > > found the correct partition to boot (the only choice), and loaded the > > kernel > > correctly. However, /etc/fstab still had the old name (nvd1p2), which= is > > now drive 2. I expected it to drop into single user, but instead the > > system > > panicked in vfs_mountroot_shuffle trying to switch root devices (see > > below). > > It doesn't seem that having the wrong root device in /etc/fstab should > > cause > > a panic; it makes it harder to patch the system. I was unable to get = the > > system to boot using boot-to-single-user or setting currdev, but I man= aged > > to remember doing "boot -a" from a loader prompt to get the system to = ask > > the root device before mounting it. I can easily reproduce this to te= st. > > Probably the NDFREE_PNBUF() shouldn't happen if namei() returned an er= ror. > > > ye, this should do it (untested): > diff --git a/sys/kern/vfs_mountroot.c b/sys/kern/vfs_mountroot.c > index 956d29e3f084..85398ff781e4 100644 > --- a/sys/kern/vfs_mountroot.c > +++ b/sys/kern/vfs_mountroot.c > @@ -352,13 +352,13 @@ vfs_mountroot_shuffle(struct thread *td, struct > mount *mpdevfs) > NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fsp= ath); > error =3D namei(&nd); > if (error) { > - NDFREE_PNBUF(&nd); > fspath =3D "/mnt"; > NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSP= ACE, > fspath); > error =3D namei(&nd); > } > if (!error) { > + NDFREE_PNBUF(&nd); > vp =3D nd.ni_vp; > error =3D (vp->v_type =3D=3D VDIR) ? 0 : ENOTDIR= ; > if (!error) > @@ -376,7 +376,6 @@ vfs_mountroot_shuffle(struct thread *td, struct > mount *mpdevfs) > } else > vput(vp); > } > - NDFREE_PNBUF(&nd); > if (error) > printf("mountroot: unable to remount previous ro= ot " > @@ -387,6 +386,7 @@ vfs_mountroot_shuffle(struct thread *td, struct > mount *mpdevfs) > NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, "/dev"); > error =3D namei(&nd); > if (!error) { > + NDFREE_PNBUF(&nd); > vp =3D nd.ni_vp; > error =3D (vp->v_type =3D=3D VDIR) ? 0 : ENOTDIR; > if (!error) That was missing the last change, and tabs were expanded. I put it in by hand, and the patch works, at least to avoid this panic. It still insisted on remounting root on nda1p2, which is not a root file system. Remounting /dev still failed without panicking, then it panicked because there was no /sbin/init. Apparently it is necessary to use "boot -a" in this situation. Too bad the loader option menu doesn't include that. Just to be clear what I tested, my patch follows. Mike diff --git a/sys/kern/vfs_mountroot.c b/sys/kern/vfs_mountroot.c index 956d29e3f084..b08b2a3200f8 100644 --- a/sys/kern/vfs_mountroot.c +++ b/sys/kern/vfs_mountroot.c @@ -352,13 +352,13 @@ vfs_mountroot_shuffle(struct thread *td, struct moun= t *mpdevfs) NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspath); error =3D namei(&nd); if (error) { - NDFREE_PNBUF(&nd); fspath =3D "/mnt"; NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspath); error =3D namei(&nd); } if (!error) { + NDFREE_PNBUF(&nd); vp =3D nd.ni_vp; error =3D (vp->v_type =3D=3D VDIR) ? 0 : ENOTDIR; if (!error) @@ -376,7 +376,6 @@ vfs_mountroot_shuffle(struct thread *td, struct mount = *mpdevfs) } else vput(vp); } - NDFREE_PNBUF(&nd); = if (error) printf("mountroot: unable to remount previous root " @@ -387,6 +386,7 @@ vfs_mountroot_shuffle(struct thread *td, struct mount = *mpdevfs) NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, "/dev"); error =3D namei(&nd); if (!error) { + NDFREE_PNBUF(&nd); vp =3D nd.ni_vp; error =3D (vp->v_type =3D=3D VDIR) ? 0 : ENOTDIR; if (!error) @@ -413,7 +413,6 @@ vfs_mountroot_shuffle(struct thread *td, struct mount = *mpdevfs) if (error) printf("mountroot: unable to remount devfs under /dev " "(error %d)\n", error); - NDFREE_PNBUF(&nd); = if (mporoot =3D=3D mpdevfs) { vfs_unbusy(mpdevfs);