From 9b724c0dcb2b9548a82d28d97e34375f64668669 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 26 Oct 2018 18:33:57 -0700 Subject: [PATCH] build - refactor rescue and initrd handling * buildworld now builds the rescue directory tree and initrd image in /usr/obj. * installworld will install the rescue and initrd stuff if it does not exist on the destination. If rescue or initrd stuff is already installed, it is not overwritten. * Add 'installrescue' and 'installinitrd' targets. These will copy the rescue and initrd image built by buildworld. * The normal 'rescue' and 'initrd' targets are unchanged and should build (from scratch) and install the rescue and initrd stuff. * NOTE: crunchgen is currently hacked to add system paths when WORLDBUILD is defined, in order to access native binaries for 'uniq' and a few others, instead of building them in cross-tools. In particular, we have to use the native 'vnconfig' binary as building one in crosstools might not be compatible with the currently running system. buildworld now uses 'vn' to create the initrd image. Possibly needs some work. --- Makefile | 19 ++++++------- Makefile.inc1 | 67 +++++++++++++++++++++++++++++++++++---------- initrd/Makefile | 9 +++--- initrd/Makefile.inc | 8 ++++++ initrd/mkinitrd.sh | 5 ++++ 5 files changed, 80 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 91cb68d882..7ec8ebc22f 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,11 @@ # realquickworld - Skip above steps, plus depend. # crossworld - Just do the bootstrap, build, and cross-build steps. # installworld - Install everything built by "buildworld". +# (includes rescue and initrd image) # installworld-force - Install everything built by "buildworld"; # special case for old systems. +# installrescue - Install /rescue built by buildworld +# installinitrd - Install initrd image built by buildworld # world - buildworld + installworld. # buildkernel - Rebuild the kernel and the kernel-modules from scratch # using build/bootstrap/cross tools from the last @@ -59,12 +62,13 @@ # # 1. `cd /usr/src' (or to the directory containing your source tree). # 2. `make buildworld' -# 3. `make buildkernel KERNCONF=YOUR_KERNEL_HERE' (default is X86_64_GENERIC). -# 4. `make installkernel KERNCONF=YOUR_KERNEL_HERE' (default is X86_64_GENERIC). +# 3. `make buildkernel KERNCONF=YOUR_KERNEL_HERE' (default X86_64_GENERIC). +# 4. `make installkernel KERNCONF=YOUR_KERNEL_HERE' (default X86_64_GENERIC). # 5. `make installworld' # 6. `make upgrade' # 7. `reboot' -# 8. `make initrd' (after making sure that the new world works well). +# 8. `make installrescue' (after making sure that the new world works well). +# 9. `make installinitrd' (after making sure that the new world works well). # # If TARGET_ARCH=arch (e.g. x86_64) is specified you can # cross build world for other architectures using the buildworld target, @@ -79,6 +83,8 @@ TGTS= all all-man buildkernel quickkernel realquickkernel nativekernel \ cleandepend cleandir depend everything \ hierarchy install installcheck installkernel \ reinstallkernel installworld installworld-force \ + rescue initrd \ + quickrescue quickinitrd installrescue installinitrd \ libraries lint maninstall \ manlint mk obj objlink regress rerelease tags \ backupworld restoreworld restoreworld-auto \ @@ -212,10 +218,3 @@ upgrade: @echo "You also need to upgrade the 3rd-party packages with:" @echo " # pkg update; pkg [-f] upgrade" @echo "--------------------------------------------------------------" - -# -# Build and install the statically linked rescue tools, and create the -# initrd image. -# -rescue initrd quickrescue quickinitrd: .PHONY - (cd ${.CURDIR}/initrd; make ${.TARGET}) diff --git a/Makefile.inc1 b/Makefile.inc1 index 84ae733d4a..3bf48f2d2d 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -295,6 +295,7 @@ CROSSENV= MAKEOBJDIRPREFIX=${WORLDDEST} \ HOST_CCVER=${HOST_CCVER} \ CCVER=${WORLD_CCVER} \ LDVER=${WORLD_LDVER} \ + WORLDBUILD=1 \ BINUTILSVER=${WORLD_BINUTILSVER} WMAKEENV= ${CROSSENV} \ @@ -349,6 +350,10 @@ _mtreetmp: -p ${WORLDDEST}/usr/include > /dev/null ${LN} -sf ${.CURDIR}/sys ${WORLDDEST} +_bwinit: + @echo "--------------------------------------------------------------" + @echo ">>> starting buildworld target" + @echo "--------------------------------------------------------------" _bootstrap-tools: @echo @echo "--------------------------------------------------------------" @@ -403,10 +408,18 @@ everything: @echo ">>> stage 4d: building everything.." @echo "--------------------------------------------------------------" cd ${.CURDIR}; ${WMAKE} all -_bwinit: +_rescue: + @echo @echo "--------------------------------------------------------------" - @echo ">>> starting buildworld target" + @echo ">>> stage 5a: building rescue topology" + @echo "--------------------------------------------------------------" + cd ${.CURDIR}; ${WMAKE} quickrescue +_initrd: + @echo @echo "--------------------------------------------------------------" + @echo ">>> stage 5b: building initrd topology" + @echo "--------------------------------------------------------------" + cd ${.CURDIR}; ${WMAKE} quickinitrd _bwdone: @echo "--------------------------------------------------------------" @echo ">>> buildworld target complete" @@ -443,10 +456,19 @@ WMAKE_TGTS+= _obj _build-tools WMAKE_TGTS+= _cross-tools .endif WMAKE_TGTS+= _includes _libraries _depend everything +WMAKE_TGTS+= _rescue _initrd + +.if defined(WMAKE_TGTS_OVERRIDE) +SUBDIR= +WMAKE_TGTS= ${WMAKE_TGTS_OVERRIDE} +.endif + +QMAKE_TGTS= _mtreetmp _obj _includes _libraries _depend everything +QMAKE_TGTS+= _rescue _initrd buildworld: _bwinit ${WMAKE_TGTS} _bwdone -quickworld: _qwinit _mtreetmp _obj _includes _libraries _depend everything _qwdone +quickworld: _qwinit ${QMAKE_TGTS} _qwdone realquickworld: _qwinit _mtreetmp _obj _includes _libraries everything _qwdone @@ -474,12 +496,17 @@ installcheck: _iwinit .endif .endif -# # installworld # # Backs up the current world if ${AUTO_BACKUP} is writable. # Installs everything compiled by a 'buildworld'. # +.if (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/") +DESTDIR_RESCUE=/ +.else +DESTDIR_RESCUE=${DESTDIR} +.endif + installworld: installcheck -@mkdir -p ${AUTO_BACKUP} > /dev/null 2>&1 @cd ${.CURDIR}; \ @@ -491,18 +518,17 @@ installworld: installcheck ${INSTALL} -o root -g wheel -m 644 ${.CURDIR}/Makefile_upgrade.inc \ ${DESTDIR}/etc/upgrade/ -.if !exists(/rescue/rescue) && \ - (!defined(DESTDIR) || ${DESTDIR} == "" || ${DESTDIR} == "/") - # Do not leave an empty '/rescue' directory when switching the rescue - # tools from '/usr/share/initrd' to '/rescue'. +.if !exists(${DESTDIR_RESCUE}/rescue/rescue) @echo "--------------------------------------------------------------" - @echo ">>> we have to run make upgrade to transition rescue tools" + @echo ">>> /rescue is empty, setting up" @echo "--------------------------------------------------------------" - (cd ${.CURDIR} && make upgrade) + (cd ${.CURDIR} && make installrescue) +.endif +.if !exists(${DESTDIR_RESCUE}/boot/kernel/initrd.img.gz) @echo "--------------------------------------------------------------" - @echo ">>> build and install rescue tools" + @echo ">>> /boot/kernel has no initrd.img.gz, setting up" @echo "--------------------------------------------------------------" - (cd ${.CURDIR} && make rescue) + (cd ${.CURDIR} && make installinitrd) .endif sync @@ -510,6 +536,13 @@ installworld: installcheck @echo ">>> installworld target complete" @echo "--------------------------------------------------------------" +installrescue: + cpdup -i0 ${WORLDDEST}/rescue ${DESTDIR}/rescue + +installinitrd: + ${INSTALL} -o root -g wheel -m 644 \ + ${WORLDDEST}/boot/kernel/initrd.img.gz ${DESTDIR}/boot/kernel/ + installworld-force: @echo "Doing a forced installworld. This will install to a temporary directory," @echo "then copy the main binaries and libraries with a static cpdup to ${DESTDIR}/" @@ -843,9 +876,9 @@ BSTRAPDIRS2= \ usr.bin/cmp usr.bin/xargs usr.bin/id usr.bin/env usr.bin/dirname \ usr.bin/tail usr.bin/unifdef \ usr.sbin/chown usr.sbin/mtree usr.sbin/config \ - usr.sbin/zic usr.sbin/makewhatis \ + usr.sbin/zic usr.sbin/makewhatis usr.sbin/pwd_mkdb \ gnu/usr.bin/grep usr.bin/sort usr.bin/gzip \ - usr.bin/mkcsmapper usr.bin/mkesdb + usr.bin/mkcsmapper usr.bin/mkesdb usr.bin/crunch bootstrap-tools: bootstrap-tools-before bootstrap-tools-targets1 bootstrap-tools-targets2 touch ${BTOOLSDEST}/.bootstrap_done @@ -1201,6 +1234,12 @@ backup-auto-clean: backup-clean: rm -f ${WORLD_BACKUP}/binaries.tar.gz +# Build and install the statically linked rescue tools, and create the +# initrd image. +# +rescue initrd quickrescue quickinitrd: .PHONY + (cd ${.CURDIR}/initrd; make ${.TARGET}) + restoreworld: .if !exists(${WORLD_BACKUP}/binaries.tar.gz) @echo "There does not seem to be a valid archive present." diff --git a/initrd/Makefile b/initrd/Makefile index dbf3cdacb4..e220a3958b 100644 --- a/initrd/Makefile +++ b/initrd/Makefile @@ -53,15 +53,16 @@ _clean_initrd: clean: _clean_rescue _clean_initrd -quickrescue: _build_rescue _install_rescue -rescue: _clean_rescue quickrescue .PHONY +_quickrescue: _build_rescue _install_rescue +rescue: _clean_rescue _quickrescue .PHONY .ORDER: _clean_rescue _build_rescue _install_rescue _quickinitrd: _stage_initrd _make_initrd _initrd: _clean_initrd _quickinitrd .ORDER: _clean_initrd _stage_initrd _make_initrd -quickinitrd: quickrescue _quickinitrd +quickrescue: _quickrescue +quickinitrd: _quickrescue _quickinitrd initrd: rescue _initrd -.ORDER: quickrescue _quickinitrd +.ORDER: _quickrescue _quickinitrd .ORDER: rescue _initrd diff --git a/initrd/Makefile.inc b/initrd/Makefile.inc index 7130910537..b7799f4e1f 100644 --- a/initrd/Makefile.inc +++ b/initrd/Makefile.inc @@ -6,9 +6,17 @@ WARNS?= 6 CRUNCH_BUILDOPTS+= -DRESCUE CRUNCH_CFLAGS+= -DRESCUE +# Crunchgen needs to use the right libraries. Normally if DESTDIR is +# specified it should also use the target binaries, however if run +# from buildworld DESTDIR points to the obj world_x86_64 which is not +# entirely populated. In that situation we leave the path alone, it +# will point to the cross tools. +# .if defined(DESTDIR) && ${DESTDIR} != "" && ${DESTDIR} != "/" +.if !defined(WORLDBUILD) CRUNCH_CFLAGS+= --sysroot=${DESTDIR} CRUNCHENV+= PATH=${DESTDIR}/sbin:${DESTDIR}/bin:${DESTDIR}/usr/sbin:${DESTDIR}/usr/bin +.endif _SHLIBDIRPREFIX= ${DESTDIR} .endif diff --git a/initrd/mkinitrd.sh b/initrd/mkinitrd.sh index 14d10910bb..c6b4305179 100755 --- a/initrd/mkinitrd.sh +++ b/initrd/mkinitrd.sh @@ -65,6 +65,11 @@ BOOT_DIR="/boot" # Maximum size (number of MB) allowed for the initrd image INITRD_SIZE_MAX="15" # MB +# When run from the buildworld environment do not require that +# things like uniq, kldload, mount, newfs, etc be in the cross-tools. +# These must run natively for the current system version. +# +PATH=${PATH}:/sbin:/usr/sbin:/bin:/usr/bin # # Helper functions -- 2.28.0