Subject: Re: kernel install target (was: CVS commit: syssrc/sys/conf)
To: NetBSD Kernel Technical Discussion List <tech-kern@netbsd.org>
From: Andrew Brown <atatat@atatdot.net>
List: tech-kern
Date: 12/09/2001 00:24:55
[there's no reason for this to go to source-changes]

On Sat, Dec 08, 2001 at 10:53:01PM -0500, Greg A. Woods wrote:
>On Sat, Dec 08, 2001 at 08:54:08PM -0500, Perry E. Metzger wrote:
>> A bad idea. You can easily nuke your running kernel that way by
>> accident. We don't have that functionality by intent. The mechanisms
>> for picking up kernels for snapshots don't need it anyway.
>
>Note the install target does preserve what it no doubt assumes is the
>running kernel, though not in a way I would do it.  The current install
>target does not rename the current kernel image to a name commonly
>loaded as a backup by most boot programs, and it does not install the
>new kernel in a way that makes it easier to preserve a series of kernels
>(i.e. multiple installs between reboots would still trash the running
>kernel's load image).

how do you actually *know* what the running kernel is?  if you can
come up with a 100% fool-proof, cross-platform, cross-architecture
method, please share.  :)

all i'm trying to do here is improve the current method.  at least
this way, you can't accidentally overwrite your netbsd/i386 kernel
with a netbsd/evbarm kernel (provided you've set DESTDIR, which you
really oughta do...in fact, your cross compilation script aid should
do that for you).  that really sucks.  trust me.

>I would suggest something more along these lines:
>
>install-kernel-${MACHINE_NAME}:
>	if [ ! -f /netbsd.old ] ; then mv /netbsd /netbsd.old; fi
>	newkern=netbsd-$$(sh $S/conf/osrelease.sh)-$$(basename $$(pwd))-$$(date '+%Y%m%d%H%M')-$$(cat version); \
>	echo "install -c -m 444 -o root -g wheel netbsd /$$newkern";	\
>	install -c -m 444 -o root -g wheel netbsd /$$newkern;		\
>	rm -f /netbsd;							\
>	echo "ln /$$newkern /netbsd";					\
>	ln /$$newkern /netbsd
>
>(that's the absolute minimum info I'd put in the filename, BTW!)

overkill.  way overkill.  imho, of course.

also note that in your method, there exists a small quantum of time
where /netbsd *does not exist*.  i think that's worse.  the current
install target uses mv (which calls rename(2)) to make that window
much smaller via an "atomic" operation.

i have my own method, which i much prefer, which i don't think
*anyone* else would like.  but it keeps me happy.

>And then perhaps have a script in /etc/rc.d that renames /netbsd.old to
>/netbsd.last (clobbering any previous /netbsd.last unconditionally) as
>the last step in a successful multi-user boot.  Cleaning of old kernel
>image files should probably only be done by hand, though in theory the
>ones older than /netbsd.last and any between /netbsd.last and
>/netbsd.old are usually no longer useful.

that also seems...overkill.\

>This way the last booted kernel is always linked to /netbsd.old until a
>new one boots and successfully "goes live", and if you have to back down
>to a previously stable kernel it should always be the one linked to
>/netbsd.last.

of course, having a link to the kernel isn't as important as having
all the tools that need to do kernel groveling know where (or how) to
find it.

>The above is essentially what I usually do now, by hand.  Having the
>default kernel install target work this way would be nice, and I guess I
>could always override in /etc/mk.conf, but that seems to result in some
>nasty warnings for reasons I can't quite figure out at the moment:
>
>$ make -n install
>make: "/work/woods/NetBSD-src/sys/arch/i386/compile/PROVEN/Makefile" line 683: warning: duplicate script for target "install-kernel-proven" ignored
>make: "/etc/mk.conf" line 65: warning: using previous script for "install-kernel-proven" defined here
>make: "/work/woods/NetBSD-src/sys/arch/i386/compile/PROVEN/Makefile" line 684: warning: duplicate script for target "install-kernel-proven" ignored
>make: "/etc/mk.conf" line 65: warning: using previous script for "install-kernel-proven" defined here
>make: "/work/woods/NetBSD-src/sys/arch/i386/compile/PROVEN/Makefile" line 685: warning: duplicate script for target "install-kernel-proven" ignored
>make: "/etc/mk.conf" line 65: warning: using previous script for "install-kernel-proven" defined here
>make: "/work/woods/NetBSD-src/sys/arch/i386/compile/PROVEN/Makefile" line 686: warning: duplicate script for target "install-kernel-proven" ignored
>make: "/etc/mk.conf" line 65: warning: using previous script for "install-kernel-proven" defined here
>if [ ! -f /netbsd.old ] ; then mv /netbsd /netbsd.old; fi
>newkern=netbsd-$(sh ../../../../conf/osrelease.sh)-$(basename $(pwd))-$(date '+%Y%m%d%H%M')-$(cat version);  echo "install -c -m 444 -o root -g wheel netbsd /$newkern";  install -c -m 444 -o root -g wheel netbsd /$newkern;  rm -f /netbsd;  echo "ln /$newkern /netbsd";  ln /$newkern /netbsd

sounds like you need to upgrade your sources.  those errors should not
occur (at least in that form) with anything current.

>There's always the source that could be modified too....

that's why we call it "open source".  ;-P

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
andrew@crossbar.com       * "information is power -- share the wealth."