From nobody Sun Jul 23 02:43:39 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 4R7nfq39fGz4nXWM for ; Sun, 23 Jul 2023 02:43:47 +0000 (UTC) (envelope-from mike@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 4R7nfp48nGz4Hf7 for ; Sun, 23 Jul 2023 02:43:46 +0000 (UTC) (envelope-from mike@karels.net) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=karels.net header.s=mail2 header.b="LPpCG/LU"; spf=pass (mx1.freebsd.org: domain of mike@karels.net designates 3.19.118.201 as permitted sender) smtp.mailfrom=mike@karels.net; dmarc=none Received: from mail2.karels.net (localhost [IPv6:0:0:0:0:0:0:0:1]) by mail2.karels.net (8.17.1/8.17.1) with ESMTP id 36N2hdHt061287; Sat, 22 Jul 2023 21:43:40 -0500 (CDT) (envelope-from mike@karels.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karels.net; s=mail2; t=1690080220; bh=ynAOfYgu3VNs8WZYlB+uF6TL2d7rJGoJLxpdiMm28dY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LPpCG/LUjfzWp1qNrDQ8HYCT7YJrFuhAhlI/LZq3xdSpCvksVlCAxzc2HsPICB34B kBQPFnpDyMKZ0UxzgjoP2m5vr0KpUVtOFl+qpeECeaTP4pFutoerXtAGITDpntcMTS duLK95A8kZwheHIHSDeIrPSC8lWRw+kPzHwaqcSbhs6v0V6nzccKI6OnKUx9FfuB5l d706RbdEU4k0BAXfQ+tdlCJYiKAoG07FGrh0jtSgoitZWb4n6xCvgkLylgqT3DKl0T RxUAiD2vpdNcOenMmBGeLCtKC3MCZFC0eDDkPn7FrHadGOVuPwyQ9R5fEMKUZxQOst RThjSyueIEgJw== Received: from [10.0.2.130] ([73.62.165.147]) by mail2.karels.net with ESMTPSA id x6NbNduTvGRl7wAAs/W3XQ (envelope-from ); Sat, 22 Jul 2023 21:43:39 -0500 From: Mike Karels To: Mateusz Guzik Cc: Current FreeBSD Subject: Re: confusion about root partition causes panic during startup Date: Sat, 22 Jul 2023 21:43:39 -0500 X-Mailer: MailMate (1.14r5964) Message-ID: <6DAF78D1-BAFF-49E4-9B42-9480A901A05A@karels.net> In-Reply-To: <202307210237.36L2bjqk049891@mail2.karels.net> References: <202307210237.36L2bjqk049891@mail2.karels.net> 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 X-Spamd-Result: default: False [-3.38 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-0.998]; NEURAL_HAM_SHORT(-0.88)[-0.884]; R_SPF_ALLOW(-0.20)[+ip4:3.19.118.201]; R_DKIM_ALLOW(-0.20)[karels.net:s=mail2]; MIME_GOOD(-0.10)[text/plain]; FREEMAIL_TO(0.00)[gmail.com]; MLMMJ_DEST(0.00)[freebsd-current@freebsd.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_TRACE(0.00)[karels.net:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ASN(0.00)[asn:16509, ipnet:3.16.0.0/14, country:US]; FREEFALL_USER(0.00)[mike]; ARC_NA(0.00)[]; TO_DN_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DMARC_NA(0.00)[karels.net]; MID_RHS_MATCH_FROM(0.00)[] X-Rspamd-Queue-Id: 4R7nfp48nGz4Hf7 X-Spamd-Bar: --- Are you planning to commit the change to mountroot? Mike On 20 Jul 2023, at 21:37, Mike Karels wrote: > 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 managed >>> 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 test. >>> Probably the NDFREE_PNBUF() shouldn't happen if namei() returned an error. >>> > >> 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, fspath); >> error = namei(&nd); >> if (error) { >> - NDFREE_PNBUF(&nd); >> fspath = "/mnt"; >> NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, >> fspath); >> error = namei(&nd); >> } >> if (!error) { >> + NDFREE_PNBUF(&nd); >> vp = nd.ni_vp; >> error = (vp->v_type == 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 = namei(&nd); >> if (!error) { >> + NDFREE_PNBUF(&nd); >> vp = nd.ni_vp; >> error = (vp->v_type == 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 mount *mpdevfs) > NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspath); > error = namei(&nd); > if (error) { > - NDFREE_PNBUF(&nd); > fspath = "/mnt"; > NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, > fspath); > error = namei(&nd); > } > if (!error) { > + NDFREE_PNBUF(&nd); > vp = nd.ni_vp; > error = (vp->v_type == 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 = namei(&nd); > if (!error) { > + NDFREE_PNBUF(&nd); > vp = nd.ni_vp; > error = (vp->v_type == 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 == mpdevfs) { > vfs_unbusy(mpdevfs);