diff options
author | 2023-08-01 11:18:31 +0300 | |
---|---|---|
committer | 2023-08-22 22:36:37 +0200 | |
commit | 3d4fb24383716958dadea95d100911037bb2b557 (patch) | |
tree | 88825ab2e7371fa54bb812281875bae49e6c9349 | |
parent | Add configuration options and code to write out binrepos.conf (diff) | |
download | catalyst-3d4fb24383716958dadea95d100911037bb2b557.tar.gz catalyst-3d4fb24383716958dadea95d100911037bb2b557.tar.bz2 catalyst-3d4fb24383716958dadea95d100911037bb2b557.zip |
Implementing distkernel installation
Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
-rw-r--r-- | catalyst/base/stagebase.py | 22 | ||||
-rwxr-xr-x | targets/livecd-stage2/controller.sh | 5 | ||||
-rwxr-xr-x | targets/support/bootloader-setup.sh | 19 | ||||
-rwxr-xr-x | targets/support/kmerge.sh | 85 | ||||
-rw-r--r-- | targets/support/pre-distkmerge.sh | 7 |
5 files changed, 116 insertions, 22 deletions
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index a9147241..fe307eab 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -694,6 +694,8 @@ class StageBase(TargetBase, ClearBase, GenBase): "boot/kernel/" + x + "/aliases", "boot/kernel/" + x + "/config", "boot/kernel/" + x + "/console", + "boot/kernel/" + x + "/distkernel", + "boot/kernel/" + x + "/dracut_args", "boot/kernel/" + x + "/extraversion", "boot/kernel/" + x + "/gk_action", "boot/kernel/" + x + "/gk_kernargs", @@ -716,6 +718,11 @@ class StageBase(TargetBase, ClearBase, GenBase): self.settings["gk_mainargs"] = self.settings[gk_mainargs] del self.settings[gk_mainargs] + dracut_mainargs = prefix + "/dracut_args" + if dracut_mainargs in self.settings: + self.settings["dracut_args"] = self.settings[dracut_mainargs] + del self.settings[dracut_mainargs] + # Ask genkernel to include b2sum if <target>/verify is set verify = prefix + "/verify" if verify in self.settings: @@ -1584,7 +1591,7 @@ class StageBase(TargetBase, ClearBase, GenBase): self.resume.enable("build_packages") def build_kernel(self): - '''Build all configured kernels''' + """Build all configured kernels""" if "autoresume" in self.settings["options"] \ and self.resume.is_enabled("build_kernel"): log.notice( @@ -1595,19 +1602,23 @@ class StageBase(TargetBase, ClearBase, GenBase): mynames = self.settings["boot/kernel"] if isinstance(mynames, str): mynames = [mynames] - # Execute the script that sets up the kernel build environment - cmd([self.settings['controller_file'], 'pre-kmerge'], env=self.env) for kname in [sanitize_name(name) for name in mynames]: + if "boot/kernel/" + kname + "/distkernel" in self.settings: + cmd([self.settings['controller_file'], 'pre-distkmerge'], env=self.env) + else: + # Execute the script that sets up the kernel build environment + cmd([self.settings['controller_file'], 'pre-kmerge'], env=self.env) self._build_kernel(kname=kname) self.resume.enable("build_kernel") def _build_kernel(self, kname): - "Build a single configured kernel by name" + """Build a single configured kernel by name""" if "autoresume" in self.settings["options"] \ and self.resume.is_enabled("build_kernel_" + kname): log.notice('Resume point detected, skipping build_kernel ' 'for %s operation...', kname) return + self._copy_kernel_config(kname=kname) key = 'boot/kernel/' + kname + '/extraversion' @@ -1617,8 +1628,7 @@ class StageBase(TargetBase, ClearBase, GenBase): self._copy_initramfs_overlay(kname=kname) # Execute the script that builds the kernel - cmd([self.settings['controller_file'], 'kernel', kname], - env=self.env) + cmd([self.settings['controller_file'], 'kernel', kname], env=self.env) if "boot/kernel/" + kname + "/initramfs_overlay" in self.settings: log.notice('Cleaning up temporary overlay dir') diff --git a/targets/livecd-stage2/controller.sh b/targets/livecd-stage2/controller.sh index f6522e63..57d947a1 100755 --- a/targets/livecd-stage2/controller.sh +++ b/targets/livecd-stage2/controller.sh @@ -20,6 +20,11 @@ case $1 in extract_modules ${clst_chroot_path} ${kname} ;; + pre-distkmerge) + # Install dracut + exec_in_chroot ${clst_shdir}/support/pre-distkmerge.sh + ;; + preclean) # Move over the motd (if applicable) case ${clst_livecd_type} in diff --git a/targets/support/bootloader-setup.sh b/targets/support/bootloader-setup.sh index d6d5f96e..455a4f07 100755 --- a/targets/support/bootloader-setup.sh +++ b/targets/support/bootloader-setup.sh @@ -54,6 +54,7 @@ memtest_grub() { } default_append_line=(${cmdline_opts[@]} cdroot) +default_dracut_append_line=(root=live:CDLABEL=ISOIMAGE rd.live.dir=/ rd.live.squashimg=image.squashfs) case ${clst_hostarch} in alpha) @@ -115,14 +116,28 @@ case ${clst_hostarch} in for x in ${clst_boot_kernel} do eval "kernel_console=\$clst_boot_kernel_${x}_console" + eval "distkernel=\$clst_boot_kernel_${x}_distkernel" echo "menuentry 'Boot LiveCD (kernel: ${x})' --class gnu-linux --class os {" >> ${iacfg} - echo " linux ${kern_subdir}/${x} ${default_append_line[@]}" >> ${iacfg} + if [ ${distkernel} = "yes" ] + then + echo " search --no-floppy --set=root -l 'ISOIMAGE'" >> ${iacfg} + echo " linux ${kern_subdir}/${x} ${default_dracut_append_line[@]}" >> ${iacfg} + else + echo " linux ${kern_subdir}/${x} ${default_append_line[@]}" >> ${iacfg} + fi echo " initrd ${kern_subdir}/${x}.igz" >> ${iacfg} echo "}" >> ${iacfg} echo "" >> ${iacfg} echo "menuentry 'Boot LiveCD (kernel: ${x}) (cached)' --class gnu-linux --class os {" >> ${iacfg} - echo " linux ${kern_subdir}/${x} ${default_append_line[@]} docache" >> ${iacfg} + if [ ${distkernel} = "yes" ] + then + echo " search --no-floppy --set=root -l 'ISOIMAGE'" >> ${iacfg} + echo " linux ${kern_subdir}/${x} ${default_dracut_append_line[@]} rd.live.ram=1" >> ${iacfg} + else + echo " linux ${kern_subdir}/${x} ${default_append_line[@]} docache" >> ${iacfg} + fi + echo " initrd ${kern_subdir}/${x}.igz" >> ${iacfg} echo "}" >> ${iacfg} if [ -n "${kernel_console}" ] diff --git a/targets/support/kmerge.sh b/targets/support/kmerge.sh index 20b471f1..c5beddc9 100755 --- a/targets/support/kmerge.sh +++ b/targets/support/kmerge.sh @@ -4,6 +4,29 @@ source /tmp/chroot-functions.sh install -d /tmp/kerncache +distkmerge_get_image_path() { + case ${clst_basearch} in + amd64|x86) + echo arch/x86/boot/bzImage + ;; + arm64) + echo arch/arm64/boot/Image.gz + ;; + arm) + echo arch/arm/boot/zImage + ;; + hppa|ppc|ppc64) + echo ./vmlinux + ;; + riscv) + echo arch/riscv/boot/Image.gz + ;; + *) + die "unsupported ARCH=${clst_basearch}" + ;; + esac +} + genkernel_compile() { # default genkernel args GK_ARGS=( @@ -78,8 +101,15 @@ eval "initramfs_overlay=\$clst_boot_kernel_${kname}_initramfs_overlay" eval "kernel_merge=\$clst_boot_kernel_${kname}_packages" eval "kernel_use=\$clst_boot_kernel_${kname}_use" eval eval kernel_gk_kernargs=( \$clst_boot_kernel_${kname}_gk_kernargs ) +eval eval kernel_dracut_kernargs=( \$clst_boot_kernel_${kname}_dracut_args ) eval "ksource=\$clst_boot_kernel_${kname}_sources" -[[ -z ${ksource} ]] && ksource="sys-kernel/gentoo-sources" +eval "distkernel=\$clst_boot_kernel_${kname}_distkernel" + +if [[ ${distkernel} = "yes" ]] ; then + [[ -z ${ksource} ]] && ksource="sys-kernel/gentoo-kernel" +else + [[ -z ${ksource} ]] && ksource="sys-kernel/gentoo-sources" +fi kernel_version=$(portageq best_visible / "${ksource}") @@ -103,7 +133,11 @@ if [[ -n ${clst_KERNCACHE} ]]; then fi if [[ ! ${cached_kernel_found} ]]; then - USE=symlink run_merge --update "${ksource}" + if [[ ${distkernel} = "yes" ]] ; then +USE="-initramfs" run_merge --update "${ksource}" + else +USE="symlink" run_merge --update "${ksource}" + fi fi if [[ -n ${clst_KERNCACHE} ]]; then @@ -117,20 +151,43 @@ if [[ -n ${clst_KERNCACHE} ]]; then ln -snf "${SOURCESDIR}" /usr/src/linux fi -if [[ -n ${clst_kextraversion} ]]; then - echo "Setting EXTRAVERSION to ${clst_kextraversion}" - - if [[ -e /usr/src/linux/Makefile.bak ]]; then - cp /usr/src/linux/Makefile{.bak,} - else - cp /usr/src/linux/Makefile{,.bak} - fi - sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextraversion}:" \ - /usr/src/linux/Makefile +if [[ ${distkernel} = "yes" ]] ; then + # Kernel already built, let's run dracut to make initramfs + distkernel_source_path=$(equery -Cq f ${ksource} | grep "/usr/src/linux-" -m1) + distkernel_image_path=$(distkmerge_get_image_path) + distkernel_version=${distkernel_source_path##"/usr/src/linux-"} + + DRACUT_ARGS=( + "${kernel_dracut_kernargs[@]}" + --force + --kernel-image="${distkernel_source_path}/${distkernel_image_path}" + --kver="${distkernel_version}" + ) + + dracut "${DRACUT_ARGS[@]}" || exit 1 + + # Create minkernel package to mimic genkernel's behaviour + cd /boot + tar jcvf /tmp/kerncache/${kname}-kernel-initrd-${clst_version_stamp}.tar.bz2 System.map* config* initramfs* vmlinuz* + cd / + tar jcvf /tmp/kerncache/${kname}-modules-${clst_version_stamp}.tar.bz2 lib/modules + +else + if [[ -n ${clst_kextraversion} ]]; then + echo "Setting EXTRAVERSION to ${clst_kextraversion}" + + if [[ -e /usr/src/linux/Makefile.bak ]]; then + cp /usr/src/linux/Makefile{.bak,} + else + cp /usr/src/linux/Makefile{,.bak} + fi + sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextraversion}:" \ + /usr/src/linux/Makefile + fi + + genkernel_compile fi -genkernel_compile - # Write out CONFIG, USE, VERSION, and EXTRAVERSION files if [[ -n ${clst_KERNCACHE} && ! ${cached_kernel_found} ]]; then pushd "/tmp/kerncache/${kname}" >/dev/null diff --git a/targets/support/pre-distkmerge.sh b/targets/support/pre-distkmerge.sh new file mode 100644 index 00000000..08409a93 --- /dev/null +++ b/targets/support/pre-distkmerge.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +RUN_DEFAULT_FUNCS="yes" + +source /tmp/chroot-functions.sh + +run_merge --oneshot sys-kernel/dracut |