On Tue, Sep 06, 2022 at 03:11:45PM +0000, Klemens Nanni wrote:
> On rare occasions, I need 'disable xxx' in /etc/bsd.re-config to be able to
> boot a system, e.g. to ignore quirky devices crashing drivers during attach.
> 
> bsd.re-config(5) currently applies to GENERIC(.MP) /bsd alone, but /bsd.rd
> and /bsd.upgrade RAMDISK kernels will require the same quirks to avoid
> crashes.
> 
> I currently hit this with arc(4) and one specific RAID card on sparc64 where
> manually editing /bsd.upgrade each time I sysupgrade(8) until arc(4) is
> fixed annoys me.
> 
> So copy over the bits from libexec/reorder_kernel/reorder_kernel.sh to make
> sysupgrade produce bootable kernels.

The crucial difference between reorder_kernel.sh and sysupgrade.sh is
that the former links a regular kernel (`make newbsd') while the latter
just copies a ramdisk that may or may not be compressed.

Some but not all ship bsd.rd gzipped.

config(8) expects plain kernels and its lseek(2) SEEK_END call in
exec_elf.c suggests that adding gzip support would be more than adapting
open()/read() -> gzopen()/gzread(), etc.

> reorder_kernel output lands in some log, but running config(8) in sysupgrade
> would print on stdout, which looks ugly, so hide the output we're not really
> interested in, anyway:

I still think that having bsd.re-config(5) support in sysupgrade(8)
outweighs the added logic/code, so here's a new version that
- only changes behaviour if /bsd.re-config is present
- uses a temporary file to leave fetched files unmodified
- transparently decompresses/copies ramdisk kernels in a MI way
- yields a reconfigured ramdisk with the same permissions and fsync(2)
  behaviour as the existing code

'gzip -d | config' will not work since a) only 'gzcat -f' can cope with
both file formats in files with unknown suffixes and b) config seeks the
input file.

First I had the following to avoid a temporary file, but this approach
would write /bsd.upgrade in two steps, meaning failure to apply
bsd.re-config would abort sysupgrade and still leave /bsd.upgrade 

Thoughts?


Index: sysupgrade.sh
===================================================================
RCS file: /cvs/src/usr.sbin/sysupgrade/sysupgrade.sh,v
retrieving revision 1.48
diff -u -p -r1.48 sysupgrade.sh
--- sysupgrade.sh       8 Jun 2022 09:03:11 -0000       1.48
+++ sysupgrade.sh       6 Oct 2022 17:20:45 -0000
@@ -207,7 +207,17 @@ else
 fi
 VNAME="${_NEXTKERNV[0]}" fw_update -p ${FW_URL} || true
 
-install -F -m 700 bsd.rd /bsd.upgrade
+if [ -f /etc/bsd.re-config ]; then
+       echo Reconfiguring kernel.
+       gzip -d -f -c bsd.rd > bsd.rd.config
+       config -e -c /etc/bsd.re-config -f bsd.rd.config >/dev/null
+       install -F -m 700 bsd.rd.config /bsd.upgrade
+       rm -f bsd.rd.config
+       set +x
+else
+       install -F -m 700 bsd.rd /bsd.upgrade
+fi
+
 logger -t sysupgrade -p kern.info "installed new /bsd.upgrade. Old kernel 
version: $(sysctl -n kern.version)"
 sync
 

Reply via email to