Date: Thu, 15 Apr 2004 16:29:13 +0200 From: des@des.no (=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=) To: arch@freebsd.org Subject: installing multiple kernels Message-ID: <xzpfzb5qpqe.fsf@dwp.des.no>
next in thread | raw e-mail | index | archive | help
--=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Currently, Makefile.inc1 will only install a single kernel. If KERNCONF specifies multiple kernel configs, they are all built, but only the first one is installed. This makes sense since otherwise the last one installed would simply clobber all the other ones. The attached patch changes that. It modifies kern.pre.mk to install each kernel in /boot/<kernelname> instead of /boot/kernel. It also modifies Makefile.inc1 to build and install all kernel configs listed in KERNCONF. It also adds a script, sys/conf/regkernel.sh, which keeps a list of installed kernels in /boot/kernels, making sure that the last one installed is always listed last. The only missing element is to make the loader read /boot/kernels and have $kernel default to the last kernel listed there (i.e. the most recently installed) instead of "kernel". It would also be nice to offer a kernel selection menu for the CLI-impaired. Unfortunately, I'm afraid my forth skills aren't quite up to the task. Any takers? DES --=20 Dag-Erling Sm=F8rgrav - des@des.no --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=kernels.diff Index: Makefile.inc1 =================================================================== RCS file: /home/ncvs/src/Makefile.inc1,v retrieving revision 1.423 diff -u -r1.423 Makefile.inc1 --- Makefile.inc1 14 Apr 2004 16:06:17 -0000 1.423 +++ Makefile.inc1 15 Apr 2004 14:08:56 -0000 @@ -500,7 +500,6 @@ .else KERNCONF?= GENERIC .endif -INSTKERNNAME?= kernel KERNSRCDIR?= ${.CURDIR}/sys KRNLCONFDIR= ${KERNSRCDIR}/${TARGET}/conf @@ -508,13 +507,9 @@ KERNCONFDIR?= ${KRNLCONFDIR} BUILDKERNELS= -INSTALLKERNEL= .for _kernel in ${KERNCONF} .if exists(${KERNCONFDIR}/${_kernel}) BUILDKERNELS+= ${_kernel} -.if empty(INSTALLKERNEL) -INSTALLKERNEL= ${_kernel} -.endif .endif .endfor @@ -557,7 +552,7 @@ @echo ">>> stage 2.1: cleaning up the object tree" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${_kernel}; \ - ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} ${CLEANDIR} + ${KMAKEENV} ${MAKE} ${CLEANDIR} .endif @echo @echo "--------------------------------------------------------------" @@ -586,14 +581,14 @@ @echo ">>> stage 3.1: making dependencies" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${_kernel}; \ - ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} depend -DNO_MODULES_OBJ + ${KMAKEENV} ${MAKE} depend -DNO_MODULES_OBJ .endif @echo @echo "--------------------------------------------------------------" @echo ">>> stage 3.2: building everything" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${_kernel}; \ - ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} all -DNO_MODULES_OBJ + ${KMAKEENV} ${MAKE} all -DNO_MODULES_OBJ @echo "--------------------------------------------------------------" @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`" @echo "--------------------------------------------------------------" @@ -602,13 +597,13 @@ # # installkernel, etc. # -# Install the kernel defined by INSTALLKERNEL +# Install the kernels # installkernel installkernel.debug \ reinstallkernel reinstallkernel.debug: ${SPECIAL_INSTALLCHECKS} -.if empty(INSTALLKERNEL) - @echo "ERROR: No kernel \"${KERNCONF}\" to install." - false +.if empty(BUILDKERNELS) + @echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; + @false .endif @echo "--------------------------------------------------------------" @echo ">>> Making hierarchy" @@ -619,9 +614,11 @@ @echo "--------------------------------------------------------------" @echo ">>> Installing kernel" @echo "--------------------------------------------------------------" - cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \ +.for _kernel in ${BUILDKERNELS} + cd ${KRNLOBJDIR}/${_kernel}; \ ${CROSSENV} PATH=${TMPPATH} \ - ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//} + ${MAKE} ${.TARGET:S/kernel//} +.endfor # # update Index: sys/conf/kern.post.mk =================================================================== RCS file: /home/ncvs/src/sys/conf/kern.post.mk,v retrieving revision 1.65 diff -u -r1.65 kern.post.mk --- sys/conf/kern.post.mk 22 Mar 2004 15:45:17 -0000 1.65 +++ sys/conf/kern.post.mk 15 Apr 2004 14:09:40 -0000 @@ -206,6 +206,7 @@ .else ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR} .endif + sh $S/conf/regkernel.sh ${DESTDIR}${KODIR} kernel-reinstall: @-chflags -R noschg ${DESTDIR}${KODIR} @@ -214,6 +215,7 @@ .else ${INSTALL} -p -m 555 -o root -g wheel ${KERNEL_KO} ${DESTDIR}${KODIR} .endif + sh $S/conf/regkernel.sh ${DESTDIR}${KODIR} config.o env.o hints.o majors.o vers.o vnode_if.o: ${NORMAL_C} Index: sys/conf/kern.pre.mk =================================================================== RCS file: /home/ncvs/src/sys/conf/kern.pre.mk,v retrieving revision 1.50 diff -u -r1.50 kern.pre.mk --- sys/conf/kern.pre.mk 29 Mar 2004 01:15:39 -0000 1.50 +++ sys/conf/kern.pre.mk 29 Mar 2004 14:24:18 -0000 @@ -6,7 +6,8 @@ # Can be overridden by makeoptions or /etc/make.conf KERNEL_KO?= kernel KERNEL?= kernel -KODIR?= /boot/${KERNEL} +KODIR?= /boot/${KERN_IDENT} +BOOTKODIR?= /boot/${KERNEL} M= ${MACHINE_ARCH} Index: sys/conf/regkernel.sh =================================================================== RCS file: sys/conf/regkernel.sh diff -N sys/conf/regkernel.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sys/conf/regkernel.sh 15 Apr 2004 14:26:52 -0000 @@ -0,0 +1,41 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +set -e + +error() { + echo "$@" 1>&2 + exit 1 +} + +if [ $# -ne 1 ] ; then + error "usage: $(basename $0) kernel-directory" 1>&2 +fi + +kodir="$1" +kernel=$(basename "${kodir}") +bootdir=$(dirname "${kodir}") +kernlist="${bootdir}/kernels" + +if [ ! -d "${kodir}" ] ; then + error "${kodir} is not a directory" +fi + +if [ ! -f "${kodir}/kernel" ] ; then + error "${kodir} does not seem to contain a kernel" +fi + +if [ -f "${kernlist}" ] ; then + mv "${kernlist}" "${kernlist}.old" +else + echo '# These are your installed kernels' >"${kernlist}.old" + basename $(dirname $(sysctl -n kern.bootfile)) >>"${kernlist}.old" +fi + +fgrep -xv -e "${kernel}" -e "${kernel}.old" "${kernlist}.old" >"${kernlist}" +if [ -d "${kodir}.old" -a -f "${kodir}.old/kernel" ] ; then + echo "${kernel}.old" >>"${kernlist}" +fi +echo "${kernel}" >>"${kernlist}" --=-=-=--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpfzb5qpqe.fsf>