From ad21c12c2baf4e138510f2ffd78679a893ef8933 Mon Sep 17 00:00:00 2001 From: Ricardo Pardini Date: Sat, 8 Oct 2022 13:26:47 +0200 Subject: [PATCH] armbian-next: `extensions` changes - MEGASQUASH - squashed changes from c9cf3fc241cfb4c872f4aef7bbc41d5854db7ea3 to 6809de3d6063cb041205a8318e19da6a4dee68c9 ref extensions_08_10_2022_pre_v30 --- extensions/cleanup-space-final-image.sh | 37 ++++++++ extensions/flash-kernel.sh | 39 ++++----- extensions/gen-sample-extension-docs.sh | 7 +- extensions/grub.sh | 12 +-- extensions/image-output-ovf.sh | 111 ++++++++++++++++++++++++ extensions/image-output-qcow2.sh | 16 ++++ extensions/kernel-localmodconfig.sh | 21 +++++ extensions/nvidia.sh | 22 +++-- extensions/sunxi-tools.sh | 10 +-- extensions/zfs.sh | 16 ++++ 10 files changed, 246 insertions(+), 45 deletions(-) create mode 100644 extensions/cleanup-space-final-image.sh create mode 100644 extensions/image-output-ovf.sh create mode 100644 extensions/image-output-qcow2.sh create mode 100644 extensions/kernel-localmodconfig.sh create mode 100644 extensions/zfs.sh diff --git a/extensions/cleanup-space-final-image.sh b/extensions/cleanup-space-final-image.sh new file mode 100644 index 0000000000..a85e2e6a56 --- /dev/null +++ b/extensions/cleanup-space-final-image.sh @@ -0,0 +1,37 @@ +function add_host_dependencies__cleanup_space_final_image_zerofree() { + export EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} zerofree" +} + +function post_customize_image__998_cleanup_apt_stuff() { + display_alert "Cleaning up apt package lists and cache" "${EXTENSION}" "info" + chroot_sdcard "apt-get clean && rm -rf /var/lib/apt/lists" + + declare -a too_big_firmware=("netronome" "qcom" "mrv" "qed" "mellanox") # maybe: "amdgpu" "radeon" but I have an AMD GPU. + for big_firm in "${too_big_firmware[@]}"; do + local firm_dir="${SDCARD}/usr/lib/firmware/${big_firm}" + if [[ -d "${firm_dir}" ]]; then + display_alert "Cleaning too-big firmware" "${big_firm}" "info" + rm -rf "${firm_dir}" + fi + done +} + +# Zerofree the image early after umounting it +function post_umount_final_image__200_zerofree() { + display_alert "Zerofreeing image" "${EXTENSION}" "info" + for partDev in "${LOOP}"p?; do + local partType + partType="$(file -s "${partDev}" | awk -F ': ' '{print $2}')" + if [[ "${partType}" == *"ext4"* ]]; then + display_alert "Zerofreeing ext4 partition ${partDev}" "${EXTENSION}" "info" + run_host_command_logged zerofree "${partDev}" + else + display_alert "Skipping zerofreeing partition ${partDev} of type '${partType}'" "${EXTENSION}" "info" + fi + done +} + +function pre_umount_final_image__999_show_space_usage() { + display_alert "Calculating used space in image" "${EXTENSION}" "info" + run_host_command_logged "cd ${MOUNT} && " du -h -d 4 -x "." "| sort -h | tail -20" +} diff --git a/extensions/flash-kernel.sh b/extensions/flash-kernel.sh index 283a38bd7c..c5b545c680 100644 --- a/extensions/flash-kernel.sh +++ b/extensions/flash-kernel.sh @@ -17,7 +17,6 @@ function extension_prepare_config__prepare_flash_kernel() { export CLOUD_INIT_CONFIG_LOCATION="/boot/firmware" # use /boot/firmware for cloud-init as well export VER="${FK__PUBLISHED_KERNEL_VERSION}" # For the VERSION export EXTRA_BSP_NAME="${EXTRA_BSP_NAME}-fk${FK__PUBLISHED_KERNEL_VERSION}" # Unique bsp name. - echo "-- starting" > "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log # Zero out the log for this extension. } function post_install_kernel_debs__install_kernel_and_flash_packages() { @@ -25,8 +24,7 @@ function post_install_kernel_debs__install_kernel_and_flash_packages() { if [[ "${FK__EXTRA_PACKAGES}" != "" ]]; then display_alert "Installing flash-kernel extra packages" "${FK__EXTRA_PACKAGES}" - echo "-- install extra pkgs" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log - chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get ${APT_EXTRA_DIST_PARAMS} -yqq --no-install-recommends install ${FK__EXTRA_PACKAGES}" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log || { + chroot_sdcard_apt_get_install "${FK__EXTRA_PACKAGES}" || { display_alert "Failed to install flash-kernel's extra packages." "${EXTENSION}" "err" exit 28 } @@ -34,8 +32,7 @@ function post_install_kernel_debs__install_kernel_and_flash_packages() { if [[ "${FK__KERNEL_PACKAGES}" != "" ]]; then display_alert "Installing flash-kernel kernel packages" "${FK__KERNEL_PACKAGES}" - echo "-- install kernel pkgs" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log - chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get ${APT_EXTRA_DIST_PARAMS} -yqq --no-install-recommends install ${FK__KERNEL_PACKAGES}" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log || { + chroot_sdcard_apt_get_install "${FK__KERNEL_PACKAGES}" || { display_alert "Failed to install flash-kernel's kernel packages." "${EXTENSION}" "err" exit 28 } @@ -47,14 +44,15 @@ function post_install_kernel_debs__install_kernel_and_flash_packages() { umount "${SDCARD}"/sys mkdir -p "${SDCARD}"/sys/firmware/efi - echo "-- install flash-kernel package" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log - chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get ${APT_EXTRA_DIST_PARAMS} -yqq --no-install-recommends install ${FK__TOOL_PACKAGE}" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log || { + chroot_sdcard_apt_get_install "${FK__TOOL_PACKAGE}" || { display_alert "Failed to install flash-kernel package." "${EXTENSION}" "err" exit 28 } # Remove fake /sys/firmware (/efi) directory rm -rf "${SDCARD}"/sys/firmware + + return 0 # prevent future shortcircuits exiting with error } # @TODO: extract u-boot into an extension, so that core bsps don't have this stuff in there to begin with. @@ -69,18 +67,18 @@ post_family_tweaks_bsp__remove_uboot_flash_kernel() { pre_umount_final_image__remove_uboot_initramfs_hook_flash_kernel() { # even if BSP still contained this (cached .deb), make sure by removing from ${MOUNT} [[ -f "$MOUNT"/etc/initramfs/post-update.d/99-uboot ]] && rm -v "$MOUNT"/etc/initramfs/post-update.d/99-uboot + return 0 # shortcircuit above } function pre_update_initramfs__setup_flash_kernel() { local chroot_target=$MOUNT - cp /usr/bin/"$QEMU_BINARY" "$chroot_target"/usr/bin/ + deploy_qemu_binary_to_chroot "${chroot_target}" mount_chroot "$chroot_target/" # this already handles /boot/firmware which is required for it to work. # hack, umount the chroot's /sys, otherwise flash-kernel tries to EFI flash due to the build host (!) being EFI umount "$chroot_target/sys" - echo "-- flash-kernel disabling hooks" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log - chroot "$chroot_target" /bin/bash -c "chmod -v -x /etc/kernel/postinst.d/initramfs-tools" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1 - chroot "$chroot_target" /bin/bash -c "chmod -v -x /etc/initramfs/post-update.d/flash-kernel" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1 + chroot_custom "$chroot_target" chmod -v -x "/etc/kernel/postinst.d/initramfs-tools" + chroot_custom "$chroot_target" chmod -v -x "/etc/initramfs/post-update.d/flash-kernel" export FIRMWARE_DIR="${MOUNT}"/boot/firmware call_extension_method "pre_initramfs_flash_kernel" <<- 'PRE_INITRAMFS_FLASH_KERNEL' @@ -90,9 +88,8 @@ function pre_update_initramfs__setup_flash_kernel() { local update_initramfs_cmd="update-initramfs -c -k all" display_alert "Updating flash-kernel initramfs..." "$update_initramfs_cmd" "" - echo "-- flash-kernel initramfs" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log - chroot "$chroot_target" /bin/bash -c "$update_initramfs_cmd" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1 || { - display_alert "Failed to run '$update_initramfs_cmd'" "Check ${DEST}/"${LOG_SUBPATH}"/flash-kernel.log" "err" + chroot_custom "$chroot_target" "$update_initramfs_cmd" || { + display_alert "Failed to run '$update_initramfs_cmd'" "Check logs" "err" exit 29 } @@ -104,19 +101,17 @@ function pre_update_initramfs__setup_flash_kernel() { local flash_kernel_cmd="FK_FORCE=yes flash-kernel --machine '${FK__MACHINE_MODEL}'" # FK_FORCE=yes is required since flash-kernel 3.104ubuntu14 / 3.106ubuntu7 display_alert "flash-kernel" "${FK__MACHINE_MODEL}" "info" - echo "-- flash-kernel itself" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log - chroot "$chroot_target" /bin/bash -c "${flash_kernel_cmd}" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1 || { - display_alert "Failed to run '${flash_kernel_cmd}'" "Check ${DEST}/"${LOG_SUBPATH}"/flash-kernel.log" "err" + chroot_custom "$chroot_target" "${flash_kernel_cmd}" || { + display_alert "Failed to run '${flash_kernel_cmd}'" "Check logs" "err" exit 29 } display_alert "Re-enabling" "initramfs-tools/flash-kernel hook for kernel" - echo "-- flash-kernel re-enabling hooks" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log - chroot "$chroot_target" /bin/bash -c "chmod -v +x /etc/kernel/postinst.d/initramfs-tools" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1 - chroot "$chroot_target" /bin/bash -c "chmod -v +x /etc/initramfs/post-update.d/flash-kernel" >> "${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1 + chroot_custom "$chroot_target" chmod -v +x "/etc/kernel/postinst.d/initramfs-tools" + chroot_custom "$chroot_target" chmod -v +x "/etc/initramfs/post-update.d/flash-kernel" - umount_chroot "$chroot_target/" - rm "$chroot_target"/usr/bin/"$QEMU_BINARY" + umount_chroot "${chroot_target}/" + undeploy_qemu_binary_from_chroot "${chroot_target}" display_alert "Disabling Armbian-core update_initramfs, was already done above." "${EXTENSION}" unset KERNELSOURCE # ugly. sorry. we'll have better mechanism for this soon. this is tested at lib/debootstrap.sh:844 diff --git a/extensions/gen-sample-extension-docs.sh b/extensions/gen-sample-extension-docs.sh index 7c0851c12d..cea24205de 100644 --- a/extensions/gen-sample-extension-docs.sh +++ b/extensions/gen-sample-extension-docs.sh @@ -5,7 +5,7 @@ function extension_metadata_ready__499_display_docs_generation_start_info() { } function extension_metadata_ready__docs_markdown() { - generate_markdown_docs_to_stdout > "${DEST}/"${LOG_SUBPATH}"/hooks.auto.docs.md" + generate_markdown_docs_to_stdout > "${EXTENSION_MANAGER_TMP_DIR}/hooks.auto.docs.md" } function extension_metadata_ready__docs_sample_extension() { @@ -112,15 +112,12 @@ generate_bash_sample_for_hook_point() { # shellcheck disable=SC2001 local COMMENT_BODY="$(echo "${MARKDOWN_BODY}" | tr '`' '"' | sed -e 's/^/### /')" - local bonus="" - [[ "${HOOK_POINT_COUNTER}" == "1" ]] && bonus="$(echo -e "\n\texport PROGRESS_DISPLAY=verysilent # Example: export a variable. This one silences the built.")" - cat << SAMPLE_BASH_CODE ${COMMENT_HEAD} ${COMMENT_BODY} function ${HOOK_POINT}__be_more_awesome() { # @TODO: Please rename this function to reflect what it does, but preserve the "${HOOK_POINT}__" prefix. - display_alert "Being awesome at \${HOOK_POINT}" "\${EXTENSION}" "info"${bonus} + display_alert "Being awesome at \${HOOK_POINT}" "\${EXTENSION}" "info" } SAMPLE_BASH_CODE diff --git a/extensions/grub.sh b/extensions/grub.sh index d70c5ea529..fc3c7e8310 100644 --- a/extensions/grub.sh +++ b/extensions/grub.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# This runs *after* user_config. Don't change anything not coming from other variables or meant to be configured by the user. +# This runs *after* user_config. Don't change anything not coming from other variables or meant to be configured by the u ser. function extension_prepare_config__prepare_flash_kernel() { # Extension configuration defaults. export DISTRO_GENERIC_KERNEL=${DISTRO_GENERIC_KERNEL:-no} # if yes, does not build our own kernel, instead, uses generic one from distro @@ -78,6 +78,7 @@ post_family_tweaks_bsp__remove_uboot_grub() { pre_umount_final_image__remove_uboot_initramfs_hook_grub() { # even if BSP still contained this (cached .deb), make sure by removing from ${MOUNT} [[ -f "$MOUNT"/etc/initramfs/post-update.d/99-uboot ]] && rm -v "$MOUNT"/etc/initramfs/post-update.d/99-uboot + return 0 # shortcircuit above } pre_umount_final_image__install_grub() { @@ -102,14 +103,14 @@ pre_umount_final_image__install_grub() { if [[ "${UEFI_GRUB_TARGET_BIOS}" != "" ]]; then display_alert "Installing GRUB BIOS..." "${UEFI_GRUB_TARGET_BIOS} device ${LOOP}" "" - chroot "$chroot_target" /bin/bash -c "grub-install --verbose --target=${UEFI_GRUB_TARGET_BIOS} ${LOOP}" >> "$DEST"/"${LOG_SUBPATH}"/install.log 2>&1 || { + chroot_custom "$chroot_target" grub-install --target=${UEFI_GRUB_TARGET_BIOS} "${LOOP}" || { exit_with_error "${install_grub_cmdline} failed!" } fi local install_grub_cmdline="update-grub && grub-install --verbose --target=${UEFI_GRUB_TARGET} --no-nvram --removable" # nvram is global to the host, even across chroot. take care. display_alert "Installing GRUB EFI..." "${UEFI_GRUB_TARGET}" "" - chroot "$chroot_target" /bin/bash -c "$install_grub_cmdline" >> "$DEST"/"${LOG_SUBPATH}"/install.log 2>&1 || { + chroot_custom "$chroot_target" "$install_grub_cmdline" || { exit_with_error "${install_grub_cmdline} failed!" } @@ -125,8 +126,9 @@ pre_umount_final_image__900_export_kernel_and_initramfs() { display_alert "Exporting Kernel and Initrd for" "kexec" "info" # this writes to ${DESTIMG} directly, since debootstrap.sh will move them later. # capture the $MOUNT/boot/vmlinuz and initrd and send it out ${DESTIMG} - cp "$MOUNT"/boot/vmlinuz-* "${DESTIMG}/${version}.kernel" - cp "$MOUNT"/boot/initrd.img-* "${DESTIMG}/${version}.initrd" + run_host_command_logged ls -la "${MOUNT}"/boot/vmlinuz-* "${MOUNT}"/boot/initrd.img-* || true + run_host_command_logged cp -pv "${MOUNT}"/boot/vmlinuz-* "${DESTIMG}/${version}.kernel" || true + run_host_command_logged cp -pv "${MOUNT}"/boot/initrd.img-* "${DESTIMG}/${version}.initrd" || true fi } diff --git a/extensions/image-output-ovf.sh b/extensions/image-output-ovf.sh new file mode 100644 index 0000000000..d3b4617e2b --- /dev/null +++ b/extensions/image-output-ovf.sh @@ -0,0 +1,111 @@ +enable_extension "image-output-qcow2" + +#### *run before installing host dependencies* +function add_host_dependencies__ovf_host_deps() { + export EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} qemu-utils" +} + +#### *allow extensions to prepare their own config, after user config is done* +function extension_prepare_config__prepare_ovf_config() { + export OVF_VM_CPUS="${OVF_VM_CPUS:-4}" # Number of CPUs + export OVF_VM_RAM_GB="${OVF_VM_RAM_GB:-4}" # RAM in Gigabytes + export OVF_KEEP_QCOW2="${OVF_KEEP_QCOW2:-no}" # keep the qcow2 image after conversion to OVF +} + +#### *custom post build hook* +function post_build_image__920_create_ovf() { + local OVF_VM_NAME="${OVF_VM_NAME:-${version}}" # The name of the VM when imported into Fusion/Player/Workstation; no spaces please + local original_qcow2_image="${QCOW2_IMAGE_FILE}" # Original from qcow2 output extension + local temp_qcow2_image="${DESTIMG}/${version}_temp.qcow2" # shadow qcow2 for resize + + local base_vmware_dirname="${OVF_VM_NAME}_vmware" # directory for vmx format, name only + local full_vmware_dirname="${DESTIMG}/${base_vmware_dirname}" # directory for vmx format, full path + local full_vmx_filename="${full_vmware_dirname}/${OVF_VM_NAME}.vmx" # vmx in vmx format dir + local base_file_vmdk="${OVF_VM_NAME}-disk1-efi-rootfs.vmdk" # target temp vmdk (filename) + local full_file_vmdk="${full_vmware_dirname}/${base_file_vmdk}" # target temp vmdk (full path) + local final_vmx_zip_file="${DESTIMG}/${OVF_VM_NAME}.vmware.zip" # final vmx zip artifact - defaults to UEFI boot + mkdir -p "${full_vmware_dirname}" # pre-create it + + display_alert "Converting image to OVF-compatible VMDK format" "${EXTENSION}" "info" + run_host_command_logged qemu-img create -f qcow2 -F qcow2 -b "${original_qcow2_image}" "${temp_qcow2_image}" # create a new, temporary, qcow2 with the original as backing image + run_host_command_logged qemu-img resize "${temp_qcow2_image}" +47G # resize the temporary + run_host_command_logged qemu-img convert -f qcow2 -O vmdk "${temp_qcow2_image}" "${full_file_vmdk}" # convert the big temp to vmdk + run_host_command_logged rm -vf "${temp_qcow2_image}" # remove the temporary large qcow2, free space + if [[ "${OVF_KEEP_QCOW2}" != "yes" ]]; then # check if told to keep the qcow2 image + display_alert "Discarding qcow2 image after" "conversion to VMDK" "debug" # debug + run_host_command_logged rm -vf "${original_qcow2_image}" # remove the original qcow2, free space + fi # /check + run_host_command_logged qemu-img info "${full_file_vmdk}" # show info + + display_alert "Creating .vmx file" "${EXTENSION}" "info" + + cat <<- VMX_FILE > "${full_vmx_filename}" + .encoding = "UTF-8" + displayname = "${OVF_VM_NAME}" + guestos = "ubuntu-64" + virtualhw.version = "18" + config.version = "8" + numvcpus = "${OVF_VM_CPUS}" + cpuid.coresPerSocket = "${OVF_VM_CPUS}" + memsize = "$((OVF_VM_RAM_GB * 1024))" + pciBridge0.present = "TRUE" + pciBridge4.present = "TRUE" + pciBridge4.virtualDev = "pcieRootPort" + pciBridge4.functions = "8" + pciBridge5.present = "TRUE" + pciBridge5.virtualDev = "pcieRootPort" + pciBridge5.functions = "8" + pciBridge6.present = "TRUE" + pciBridge6.virtualDev = "pcieRootPort" + pciBridge6.functions = "8" + pciBridge7.present = "TRUE" + pciBridge7.virtualDev = "pcieRootPort" + pciBridge7.functions = "8" + vmci0.present = "TRUE" + floppy0.present = "FALSE" + mks.enable3d = "true" + scsi0:0.present = "TRUE" + scsi0:0.deviceType = "disk" + scsi0:0.fileName = "${base_file_vmdk}" + scsi0:0.allowguestconnectioncontrol = "false" + scsi0:0.mode = "persistent" + scsi0.virtualDev = "pvscsi" + scsi0.present = "TRUE" + ethernet0.present = "TRUE" + ethernet0.virtualDev = "vmxnet3" + ethernet0.connectionType = "nat" + ethernet0.startConnected = "TRUE" + ethernet0.addressType = "generated" + ethernet0.wakeonpcktrcv = "false" + ethernet0.allowguestconnectioncontrol = "true" + sata0.present = "TRUE" + vmci0.unrestricted = "false" + vcpu.hotadd = "true" + mem.hotadd = "true" + tools.syncTime = "true" + toolscripts.afterpoweron = "true" + toolscripts.afterresume = "true" + toolscripts.beforepoweroff = "true" + toolscripts.beforesuspend = "true" + powerType.powerOff = "soft" + powerType.reset = "soft" + powerType.suspend = "soft" + usb.present = "TRUE" + ehci.present = "TRUE" + usb_xhci.present = "TRUE" + hard-disk.hostBuffer = "enabled" + ulm.disableMitigations = "TRUE" + vhv.enable = "TRUE" + vmx.buildType = "release" + firmware = "efi" + VMX_FILE + + # Now wrap the .vmx in a zip, with minimal compression. (release will .zst it later) + display_alert "Zipping/storing vmx" "${EXTENSION}" "info" + cd "${DESTIMG}" || false + run_host_command_logged zip -0 "${final_vmx_zip_file}" "${base_vmware_dirname}"/* + cd - || false + + display_alert "Done, cleaning up" "${EXTENSION}" "info" + rm -rf "${full_vmware_dirname}" +} diff --git a/extensions/image-output-qcow2.sh b/extensions/image-output-qcow2.sh new file mode 100644 index 0000000000..2633062ed5 --- /dev/null +++ b/extensions/image-output-qcow2.sh @@ -0,0 +1,16 @@ +add_host_dependencies__ovf_host_deps() { + [[ "${SKIP_QCOW2}" == "yes" ]] && return 0 + export EXTRA_BUILD_DEPS="${EXTRA_BUILD_DEPS} qemu-utils" +} + +function post_build_image__900_convert_to_qcow2_img() { + [[ "${SKIP_QCOW2}" == "yes" ]] && return 0 + display_alert "Converting image to qcow2" "${EXTENSION}" "info" + export QCOW2_IMAGE_FILE="${DESTIMG}/${version}.img.qcow2" + run_host_command_logged qemu-img convert -f raw -O qcow2 "${DESTIMG}/${version}.img" "${QCOW2_IMAGE_FILE}" + run_host_command_logged qemu-img info "${QCOW2_IMAGE_FILE}" + if [[ "${QCOW2_RESIZE_AMOUNT}" != "" ]]; then + display_alert "Resizing qcow2 image by '${QCOW2_RESIZE_AMOUNT}' " "${EXTENSION}" "info" + qemu-img resize "${QCOW2_IMAGE_FILE}" "${QCOW2_RESIZE_AMOUNT}" + fi +} diff --git a/extensions/kernel-localmodconfig.sh b/extensions/kernel-localmodconfig.sh new file mode 100644 index 0000000000..40248bafea --- /dev/null +++ b/extensions/kernel-localmodconfig.sh @@ -0,0 +1,21 @@ +function extension_prepare_config__prepare_localmodconfig() { + # If defined, ${KERNEL_CONFIG_FROM_LSMOD} can contain a lsmod to apply to the kernel configuration. + # to get a file for this run 'lsmod > my_machine.lsmod' and then put it in userpatches/lsmod/ + export KERNEL_CONFIG_FROM_LSMOD="${KERNEL_CONFIG_FROM_LSMOD:-}" + display_alert "localmodconfig INIT lsmod" "${KERNEL_CONFIG_FROM_LSMOD}" "warn" + + # If there, make sure it exists + local lsmod_file="${SRC}/userpatches/lsmod/${KERNEL_CONFIG_FROM_LSMOD}.lsmod" + if [[ ! -f "${lsmod_file}" ]]; then + exit_with_error "Can't find lsmod file ${lsmod_file}, configure with KERNEL_CONFIG_FROM_LSMOD=xxx" + fi +} + +# This needs much more love than this. can be used to make "light" versions of kernels, that compile 3x-5x faster or more +function custom_kernel_config_post_defconfig__apply_localmodconfig() { + display_alert "localmodconfig with lsmod" "${KERNEL_CONFIG_FROM_LSMOD}" "warn" + if [[ "a${KERNEL_CONFIG_FROM_LSMOD}a" != "aa" ]]; then + local lsmod_file="${SRC}/userpatches/lsmod/${KERNEL_CONFIG_FROM_LSMOD}.lsmod" + run_kernel_make "LSMOD=${lsmod_file}" localmodconfig + fi +} diff --git a/extensions/nvidia.sh b/extensions/nvidia.sh index 77734bc601..8cf596be7b 100644 --- a/extensions/nvidia.sh +++ b/extensions/nvidia.sh @@ -1,14 +1,20 @@ #!/usr/bin/env bash -function pre_install_kernel_debs__build_nvidia_kernel_module() { - +function extension_finish_config__build_nvidia_kernel_module() { + if [[ "${KERNEL_HAS_WORKING_HEADERS}" != "yes" ]]; then + display_alert "Kernel version has no working headers package" "skipping nVidia for kernel v${KERNEL_MAJOR_MINOR}" "warn" + return 0 + fi export INSTALL_HEADERS="yes" - + declare -g NVIDIA_DRIVER_VERSION="${NVIDIA_DRIVER_VERSION:-"510"}" + display_alert "Forcing INSTALL_HEADERS=yes; using nVidia driver version ${NVIDIA_DRIVER_VERSION}" "${EXTENSION}" "debug" } function post_install_kernel_debs__build_nvidia_kernel_module() { - - display_alert "Build kernel module" "${EXTENSION}" "info" - chroot "${SDCARD}" /bin/bash -c "apt -y -qq install nvidia-dkms-510 nvidia-driver-510 nvidia-settings nvidia-common" >> "$DEST"/"${LOG_SUBPATH}"/install.log 2>&1 || { - exit_with_error "${install_grub_cmdline} failed!" - } + [[ "${INSTALL_HEADERS}" != "yes" ]] || [[ "${KERNEL_HAS_WORKING_HEADERS}" != "yes" ]] && return 0 + display_alert "Install nVidia packages, build kernel module in chroot" "${EXTENSION}" "info" + # chroot_sdcard_apt_get_install() is in lib/logging/runners.sh which handles "running" of stuff nicely. + # chroot_sdcard_apt_get_install() -> chroot_sdcard_apt_get() -> chroot_sdcard() -> run_host_command_logged_raw() + # it handles bash-specific quoting issues, apt proxies, logging, and errors. + declare -agx if_error_find_files_sdcard=("/var/lib/dkms/nvidia/*/build/make.log") + chroot_sdcard_apt_get_install "nvidia-dkms-${NVIDIA_DRIVER_VERSION}" "nvidia-driver-${NVIDIA_DRIVER_VERSION}" nvidia-settings } diff --git a/extensions/sunxi-tools.sh b/extensions/sunxi-tools.sh index 0d33eb0ff8..dc0a2ac436 100644 --- a/extensions/sunxi-tools.sh +++ b/extensions/sunxi-tools.sh @@ -7,12 +7,12 @@ function build_host_tools__compile_sunxi_tools() { # Compile and install only if git commit hash changed cd "${SRC}"/cache/sources/sunxi-tools || exit # need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources - if [[ ! -f .commit_id || $(improved_git rev-parse @ 2> /dev/null) != $(< .commit_id) || ! -f /usr/local/bin/sunxi-fexc ]]; then + if [[ ! -f .commit_id || $(git rev-parse @ 2> /dev/null) != $(< .commit_id) || ! -f /usr/local/bin/sunxi-fexc ]]; then display_alert "Compiling" "sunxi-tools" "info" - make -s clean > /dev/null - make -s tools > /dev/null + run_host_command_logged make -s clean + run_host_command_logged make -s tools mkdir -p /usr/local/bin/ - make install-tools > /dev/null 2>&1 - improved_git rev-parse @ 2> /dev/null > .commit_id + run_host_command_logged make install-tools + git rev-parse @ 2> /dev/null > .commit_id fi } diff --git a/extensions/zfs.sh b/extensions/zfs.sh new file mode 100644 index 0000000000..f1baa63ed0 --- /dev/null +++ b/extensions/zfs.sh @@ -0,0 +1,16 @@ +function extension_finish_config__build_zfs_kernel_module() { + if [[ "${KERNEL_HAS_WORKING_HEADERS}" != "yes" ]]; then + display_alert "Kernel version has no working headers package" "skipping ZFS for kernel v${KERNEL_MAJOR_MINOR}" "warn" + return 0 + fi + export INSTALL_HEADERS="yes" + display_alert "Forcing INSTALL_HEADERS=yes; for use with ZFS" "${EXTENSION}" "debug" +} + +function post_install_kernel_debs__build_zfs_kernel_module() { + [[ "${INSTALL_HEADERS}" != "yes" ]] || [[ "${KERNEL_HAS_WORKING_HEADERS}" != "yes" ]] && return 0 + display_alert "Install ZFS packages, will build kernel module in chroot" "${EXTENSION}" "info" + declare -agx if_error_find_files_sdcard=("/var/lib/dkms/zfs/*/build/*.log") + # See https://github.com/zfsonlinux/pkg-zfs/issues/69 for a bug with leaking env vars. + use_clean_environment="yes" chroot_sdcard_apt_get_install "zfs-dkms zfsutils-linux" +}