Bug 290393 - 15.0-BETA4: pkg blocks boot process waiting for console input
Summary: 15.0-BETA4: pkg blocks boot process waiting for console input
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Mark Johnston
URL:
Keywords: patch, regression
Depends on:
Blocks: 15.0-metabug
  Show dependency treegraph
 
Reported: 2025-10-20 22:06 UTC by Jimmy Olgeni
Modified: 2025-11-10 18:55 UTC (History)
2 users (show)

See Also:
linimon: maintainer-feedback? (pkg)


Attachments
Swap -r and -N in pkg call (407 bytes, patch)
2025-11-02 13:34 UTC, Jimmy Olgeni
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jimmy Olgeni freebsd_committer freebsd_triage 2025-10-20 22:06:41 UTC
During boot of FreeBSD 15.0-BETA2 VM image, the pkg process enters ttyin state
and blocks boot completion until manual input is provided on console.

After the system completes network configuration and starts syslogd, the
boot process hangs indefinitely. Using Ctrl+T reveals that pkg is stuck in [ttyin] state, waiting for terminal input.

load: 1.32  cmd: pkg 1633 [ttyin] 27.18r 0.00u 0.00s 0% 6084k

The system will not proceed with boot until ENTER is pressed on the
console, which allows pkg to continue and boot to complete normally (best
guess is that it sends a "N" reply to pkg bootstrap).

Console Log:

DHCPDECLINE from 169.254.169.253
DHCPREQUEST on vtnet0 to 255.255.255.255 port 67
DHCPACK from 169.254.169.253
bound to 68.183.67.170 -- renewal in 43200 seconds.
Starting dhclient.
DHCPDISCOVER on vtnet1 to 255.255.255.255 port 67 interval 6
DHCPOFFER from 169.254.169.253
DHCPREQUEST on vtnet1 to 255.255.255.255 port 67
DHCPACK from 169.254.169.253
bound to 10.114.0.8 -- renewal in 43200 seconds.
route: message indicates error: File exists
add host 127.0.0.1: gateway lo0 fib 0: route already in table
route: message indicates error: File exists
add host ::1: gateway lo0 fib 0: route already in table
add net fe80::: gateway ::1
add net ff02::: gateway ::1
add net ::ffff:0.0.0.0: gateway ::1
add net ::0.0.0.0: gateway ::1
Creating and/or trimming log files.
Clearing /tmp (X related).
Updating /var/run/os-release done.
Updating motd:.
Starting syslogd.
load: 1.32  cmd: pkg 1633 [ttyin] 27.18r 0.00u 0.00s 0% 6084k
[SYSTEM HANGS HERE - ENTER must be pressed to continue]
Comment 1 Jimmy Olgeni freebsd_committer freebsd_triage 2025-10-26 10:35:34 UTC
Still applies to 15.0-BETA3 (tested on UFS cloudinit image).
Comment 2 Baptiste Daroussin freebsd_committer freebsd_triage 2025-10-31 16:51:30 UTC
this is probably more related to nuageinit than pkg. what is your cloudinit config?
Comment 3 Jimmy Olgeni freebsd_committer freebsd_triage 2025-11-02 11:55:59 UTC
I tried with both an empty #!/bin/sh script and with no script: in the no script case nuageinit crashes on PR 290395 so it's something that comes far later in the process.

Looks like freebsd-update is not passing -y to bootstrap:

===
Updating motd:/etc/rc: DEBUG: checkjesno: rc_startmsgs is set to YES.
/etc/rc: DEBUG: checkjesno: nuageinit_enable is set to YES.
/etc/rc: DEBUG: checkjesno: nuageinit_post_net_svc_j is set to NO.
/etc/rc: DEBUG: run_rc_command: doit: _execute_post_net
/usr/libexec/flua: /usr/libexec/nuageinit:716: attempt to index a nil value (loc
al 'line')
stack traceback:
    /usr/libexec/nuageinit:716: in main chunk
    [C]: in ?
/etc/rc: DEBUG: checkjesno: syslogd_enable is set to YES.
/etc/rc: DEBUG: run_rc_command: start_precmd: syslogd_precmd
/etc/rc: DEBUG: checkjesno: syslogd_svc_j is set to NO.
/etc/rc: DEBUG: checkjesno: rc_startmsgs is set to YES.
Starting syslogd.
/etc/rc: DEBUG: checkjesno: syslogd_svc_j is set to NO.
/etc/rc: DEBUG: run_rc_command: doit:    limits -C daemon    /usr/sbin/syslogd -s
/etc/rc: DEBUG: checkjesno: syslogd_svc_j is set to NO.
/etc/rc: DEBUG: checkjesno: bsnmpd_enable is set to NO.
/etc/rc: DEBUG: checkjesno: firstboot_freebsd_update_enable is set to YES.
/etc/rc: DEBUG: checkjesno: firstboot_freebsd_update_svc_j is set to NO.
/etc/rc: DEBUG: run_rc_command: doit:    firstboot_freebsd_update_run | logger -s
-t 'freebsd-update'
/etc/rc: DEBUG: checkjesno: firstboot_freebsd_update_nonstandard is set to NO.
[halts]
===

Trying on console:

===
[...]
  -j jail      -- Operate on the given jail specified by jid or name
  -k KEY       -- Trust an RSA key with SHA256 hash of KEY
  -r release   -- Target for upgrade (e.g. 13.2-RELEASE)
  -s server    -- Server from which to fetch updates
                  (default: update.FreeBSD.org)
  -t address   -- Mail output of cron command, if any, to address
                  (default: root)
  --not-running-from-cron
               -- Run without a tty, for use by automated tools
  --currently-running release
               -- Update as if currently running this release
Commands:
  fetch        -- Fetch updates from server
  cron         -- Sleep rand(3600) seconds, fetch updates, and send an
                  email if updates were found
  upgrade      -- Fetch upgrades to FreeBSD version specified via -r option
  updatesready -- Check if there are fetched updates ready to install
  install      -- Install downloaded updates or upgrades
  rollback     -- Uninstall most recently installed updates
  IDS          -- Compare the system against an index of "known good" files
  showconfig   -- Show configuration
root@freebsd-45:~ # freebsd-update fetch
[halts]
load: 0.30  cmd: pkg 4317 [ttyin] 7.20p 0.00u 0.00s 0% 8732k
[gotcha]
===

But pkg message is suppressed, so you have to guess what it's doing :)
Comment 4 Jimmy Olgeni freebsd_committer freebsd_triage 2025-11-02 12:41:30 UTC
Made a quick experiment to get some more info. This put it back into shape:

==========
diff --git a/usr.sbin/freebsd-update/freebsd-update.sh b/usr.sbin/freebsd-update/freebsd-update.sh
index 7815502dba39..85ed026b6aae 100644
--- a/usr.sbin/freebsd-update/freebsd-update.sh
+++ b/usr.sbin/freebsd-update/freebsd-update.sh
@@ -667,9 +667,15 @@ upgrade_check_kmod_ports() {
 	local report
 	local w
 
-	if ! pkg -N 2>/dev/null; then
-		echo "Skipping kernel modules check. pkg(8) not present."
-		return
+	# Check if the real pkg binary exists (not just the bootstrap wrapper)
+	# /usr/sbin/pkg is the bootstrap wrapper, /usr/local/sbin/pkg is the real pkg
+	if [ ! -x /usr/local/sbin/pkg ]; then
+		echo "pkg is not bootstrapped. Attempting to bootstrap..."
+		if ! env ASSUME_ALWAYS_YES=yes pkg bootstrap >/dev/null 2>&1; then
+			echo "Failed to bootstrap pkg. Skipping kernel modules check."
+			return
+		fi
+		echo "pkg successfully bootstrapped."
 	fi
 
 	# Most modules are in /boot/modules but we should actually look
@@ -1102,13 +1108,23 @@ IDS_check_params () {
 # Return 0 if the system is managed using pkgbase, 1 otherwise.
 check_pkgbase()
 {
-	# Packaged base requires that pkg is bootstrapped.
-	if ! pkg -r ${BASEDIR} -N >/dev/null 2>/dev/null; then
+	# Check if the real pkg binary exists (not just the bootstrap wrapper)
+	# /usr/sbin/pkg is the bootstrap wrapper, /usr/local/sbin/pkg is the real pkg
+	if [ ! -x "${BASEDIR}/usr/local/sbin/pkg" ]; then
+		# pkg is not bootstrapped, attempt to bootstrap it non-interactively
+		if ! env ASSUME_ALWAYS_YES=yes pkg -r ${BASEDIR} bootstrap >/dev/null 2>&1; then
+			return 1
+		fi
+	fi
+
+	# Verify pkg is functional
+	if ! pkg -N >/dev/null 2>&1; then
 		return 1
 	fi
+
 	# uname(1) is used by pkg to determine ABI, so it should exist.
 	# If it comes from a package then this system uses packaged base.
-	if ! pkg -r ${BASEDIR} which /usr/bin/uname >/dev/null; then
+	if ! pkg -r ${BASEDIR} which /usr/bin/uname >/dev/null 2>&1; then
 		return 1
 	fi
 	return 0
==========

Then I found the issue! :D

root@freebsd-15:/usr/sbin # pkg -N
pkg: pkg is not installed
root@freebsd-15:/usr/sbin # pkg -N -r /
pkg: pkg is not installed
root@freebsd-15:/usr/sbin # pkg -r / -N
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]:

-N is not happy about the positioning of -r, so the "pkg -r ${BASEDIR} -N" is causing the hang.
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2025-11-02 13:21:12 UTC
^Triage: note that there is an inline patch.
Comment 6 Jimmy Olgeni freebsd_committer freebsd_triage 2025-11-02 13:34:58 UTC
Created attachment 265106 [details]
Swap -r and -N in pkg call

This is the actual fix - smaller.
Comment 7 commit-hook freebsd_committer freebsd_triage 2025-11-06 16:10:38 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=645352316be6901077dc1a3ce26f41934136f412

commit 645352316be6901077dc1a3ce26f41934136f412
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-11-06 16:06:12 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-11-06 16:06:12 +0000

    freebsd-update: Swap pkg(8) flags in check_pkgbase()

    Unbootstrapped pkg will ignore -N if -r is specified first.  Flip the
    order.

    Prior to commit 66c75fa63aff this worked by accident.

    PR:             290393
    Reported by:    olgeni
    MFC after:      3 days
    Fixes:          66c75fa63aff ("freebsd-update: Fix the pkgbase check")

 usr.sbin/freebsd-update/freebsd-update.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2025-11-08 19:14:04 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=addc0556ce547425f9810fe081b46e8472340333

commit addc0556ce547425f9810fe081b46e8472340333
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-11-06 16:06:12 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-11-08 19:10:18 +0000

    freebsd-update: Swap pkg(8) flags in check_pkgbase()

    Unbootstrapped pkg will ignore -N if -r is specified first.  Flip the
    order.

    Prior to commit 66c75fa63aff this worked by accident.

    PR:             290393
    Reported by:    olgeni
    MFC after:      3 days
    Fixes:          66c75fa63aff ("freebsd-update: Fix the pkgbase check")

    (cherry picked from commit 645352316be6901077dc1a3ce26f41934136f412)

 usr.sbin/freebsd-update/freebsd-update.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 9 commit-hook freebsd_committer freebsd_triage 2025-11-10 18:54:06 UTC
A commit in branch releng/15.0 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ee234a8f17039ca770fda42e45ba9559bc2eb24a

commit ee234a8f17039ca770fda42e45ba9559bc2eb24a
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-11-06 16:06:12 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-11-10 18:49:08 +0000

    freebsd-update: Swap pkg(8) flags in check_pkgbase()

    Unbootstrapped pkg will ignore -N if -r is specified first.  Flip the
    order.

    Prior to commit 66c75fa63aff this worked by accident.

    Approved by:    re (cperciva)
    PR:             290393
    Reported by:    olgeni
    MFC after:      3 days
    Fixes:          66c75fa63aff ("freebsd-update: Fix the pkgbase check")

    (cherry picked from commit 645352316be6901077dc1a3ce26f41934136f412)
    (cherry picked from commit addc0556ce547425f9810fe081b46e8472340333)

 usr.sbin/freebsd-update/freebsd-update.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)