Bug 221550 - kern.bootfile returns only /kernel on mips64 (ERL) platform
Summary: kern.bootfile returns only /kernel on mips64 (ERL) platform
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: mips Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-15 23:07 UTC by Kurt Lidl
Modified: 2019-05-16 00:53 UTC (History)
3 users (show)

See Also:
gonzo: mfc-stable11?
gonzo: mfc-stable12?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kurt Lidl freebsd_committer 2017-08-15 23:07:15 UTC
The kern.bootfile sysctl returns just /kernel on an ERL, using the stock
configuration where the boot filesystem (a FAT32 filesystem) is mounted
into /boot.

root@erl2-148: df
Filesystem  1K-blocks    Used    Avail Capacity  Mounted on
/dev/da0s2a  28810359 9965044 16540487    38%    /
devfs               1       1        0   100%    /dev
/dev/da0s1     262008  181248    80760    69%    /boot
fdescfs             1       1        0   100%    /dev/fd
tmpfs         2062880       4  2062876     0%    /tmp

From the perspective of the uboot system, this is correct, as my uboot
boot command is similar to the ones referenced at rtfm.net:

setenv boot_freebsd 'fatload usb 0 $loadaddr kernel/kernel ; bootoctlinux $loadaddr coremask=0x3'

However, since the uboot boot partition is mounted as /boot, the sysctl answer
is wrong.

Why do I care?

Because the logic that backs up the old kernel to kernel.old when running
'make installkernel' doesn't work right - my existing kernel is always
destroyed and the new kernel installed as /boot/kernel.

e.g.:

thiskernel=`sysctl -n kern.bootfile` ;  if [ ! "`dirname "$thiskernel"`" -ef /boot/kernel ] ; then  chflags -R noschg /boot/kernel ;  rm -rf /boot/kernel ;  rm -rf /usr/lib/debug/boot/kernel ;  else  if [ -d /boot/kernel.old ] ; then  chflags -R noschg /boot/kernel.old ;  rm -rf /boot/kernel.old ;  fi ;  mv /boot/kernel /boot/kernel.old ;  if [ -n "/usr/lib/debug" -a  -d /usr/lib/debug/boot/kernel ]; then  rm -rf /usr/lib/debug/boot/kernel.old ;  mv /usr/lib/debug/boot/kernel /usr/lib/debug/boot/kernel.old ;  fi ;  sysctl kern.bootfile=/boot/kernel.old/"`basename "$thiskernel"`" ;  fi
mkdir -p /boot/kernel
install -p -m 555 -o root -g wheel kernel /boot/kernel/
Comment 1 Kurt Lidl freebsd_committer 2017-09-13 21:47:54 UTC
It's probably obvious, but I'll post a workaround here too -
since the edgerouter pretty much always boots the same
kernel file...

Most people setup the boot command to do something like this:

boot_freebsd=fatload usb 0 $loadaddr kernel/kernel ; bootoctlinux $loadaddr coremask=0x3

And then they have the msdos filesystem holding the kernel mounted as
/boot:

The right thing for kern.bootfile ought to be set to
/boot/kernel/kernel, so just do the following:

echo 'kern.bootfile=/boot/kernel/kernel' >> /etc/sysctl.conf
sysctl kern.bootfile=/boot/kernel/kernel

And then 'make installkernel' will do the right thing...
Comment 2 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2019-01-20 18:44:36 UTC
I wasn't going to close this PR yet, it was accidental. Re-opening.
Comment 3 commit-hook freebsd_committer 2019-03-26 18:04:11 UTC
A commit references this bug:

Author: gonzo
Date: Tue Mar 26 18:03:18 UTC 2019
New revision: 345550
URL: https://svnweb.freebsd.org/changeset/base/345550

Log:
  Change default value of kern.bootfile to reflect reality

  In most cases kernel.bootfile is populated from the information
  provided by loader(8). There are certain scenarios when loader
  is not available, for instance when kernel is loaded by u-boot
  or some other BootROM directly. In this case the default value
  "/kernel" points to invalid location and breaks some functinality,
  like using installkernel on self-hosted system or dtrace's CTF
  lookup. This can be fixed by setting the value manually but the
  default that reflects correct location is better than default that
  points to invalid one.

  Current default was set around FreeBSD 1, when "/kernel" was the
  actual path. Transition to /boot/kernel/kernel happened circa FreeBSD 3.

  PR:		221550
  Reviewed by:	ian, imp
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D18902

Changes:
  head/sys/kern/kern_mib.c
Comment 4 commit-hook freebsd_committer 2019-05-15 18:57:16 UTC
A commit references this bug:

Author: gonzo
Date: Wed May 15 18:56:43 UTC 2019
New revision: 347629
URL: https://svnweb.freebsd.org/changeset/base/347629

Log:
  MFC r345550:

  Change default value of kern.bootfile to reflect reality

  In most cases kernel.bootfile is populated from the information
  provided by loader(8). There are certain scenarios when loader
  is not available, for instance when kernel is loaded by u-boot
  or some other BootROM directly. In this case the default value
  "/kernel" points to invalid location and breaks some functinality,
  like using installkernel on self-hosted system or dtrace's CTF
  lookup. This can be fixed by setting the value manually but the
  default that reflects correct location is better than default that
  points to invalid one.

  Current default was set around FreeBSD 1, when "/kernel" was the
  actual path. Transition to /boot/kernel/kernel happened circa FreeBSD 3.

  PR:		221550
  Reviewed by:	ian, imp
  Differential Revision:	https://reviews.freebsd.org/D18902

Changes:
_U  stable/12/
  stable/12/sys/kern/kern_mib.c
Comment 5 commit-hook freebsd_committer 2019-05-16 00:53:59 UTC
A commit references this bug:

Author: gonzo
Date: Thu May 16 00:53:55 UTC 2019
New revision: 347637
URL: https://svnweb.freebsd.org/changeset/base/347637

Log:
  MFC r345550:

  Change default value of kern.bootfile to reflect reality

  In most cases kernel.bootfile is populated from the information
  provided by loader(8). There are certain scenarios when loader
  is not available, for instance when kernel is loaded by u-boot
  or some other BootROM directly. In this case the default value
  "/kernel" points to invalid location and breaks some functinality,
  like using installkernel on self-hosted system or dtrace's CTF
  lookup. This can be fixed by setting the value manually but the
  default that reflects correct location is better than default that
  points to invalid one.

  Current default was set around FreeBSD 1, when "/kernel" was the
  actual path. Transition to /boot/kernel/kernel happened circa FreeBSD 3.

  PR:		221550
  Reviewed by:	ian, imp
  Differential Revision:	https://reviews.freebsd.org/D18902

Changes:
_U  stable/11/
  stable/11/sys/kern/kern_mib.c