From df6b1dd620b2ab233d163c1a9f63644be0649b93 Mon Sep 17 00:00:00 2001 From: torben Date: Thu, 10 Dec 2015 15:20:29 +0100 Subject: Even more fixes in archLinuxStartup.nsh Make KCL reading more resilient. --- .../hooks/cmdline/prepare-kernel-command-line-parameter.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'builder') diff --git a/builder/dnbd3-rootfs/hooks/cmdline/prepare-kernel-command-line-parameter.sh b/builder/dnbd3-rootfs/hooks/cmdline/prepare-kernel-command-line-parameter.sh index 19865586..e81cf43d 100755 --- a/builder/dnbd3-rootfs/hooks/cmdline/prepare-kernel-command-line-parameter.sh +++ b/builder/dnbd3-rootfs/hooks/cmdline/prepare-kernel-command-line-parameter.sh @@ -19,7 +19,8 @@ local parameter for parameter in $(getargs BOOTIF=); do info "PXE given boot interface $parameter" local dracut_interface_name="bootnet:$(echo $parameter | \ - sed --regexp-extended 's/.{2}-((.{2}-){5}.{2})/\1/' | sed s/-/:/g)" + sed --regexp-extended 's/.{2}[:\-]((.{2}[:\-]){5}.{2})/\1/' | \ + sed s/-/:/g)" info "Dracut interface name is: $dracut_interface_name" echo -n " ifname=$dracut_interface_name" >> \ "${writeable_proc_cmdline_path}cmdline" -- cgit v1.2.3-55-g7522 From 25b2e9124e50bb69bc3d39b545560b4dfb53f072 Mon Sep 17 00:00:00 2001 From: torben Date: Thu, 10 Dec 2015 15:27:21 +0100 Subject: Initialize new offline initramfs creation feature. --- builder/build-initramfs.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'builder') diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh index 45a54b2b..f4e7f699 100755 --- a/builder/build-initramfs.sh +++ b/builder/build-initramfs.sh @@ -93,10 +93,11 @@ logging.set_log_level critical build_initramfs_dracut_parameter='--force --no-hostonly' build_initramfs_verbose='no' build_initramfs_debug='no' +build_initramfs_target='' build_initramfs_create_system_image='' build_initramfs_cleanup='no' build_initramfs_dependencies=(bash cpio git test shift echo mktemp cat rm sed \ - gzip curl tar grep make gcc cmake readlink dirname dmsetup) + gzip curl tar grep make gcc cmake readlink dirname dmsetup fakeroot) # endregion @@ -133,6 +134,10 @@ function build_initramfs_print_command_line_option_description() { -i --create-system-image Creates an image under given path from current system. (default: "$build_initramfs_create_system_image"). +-t --target Creates an image against given target template filesystem. If not + explicitly speicifed current system will be used as template system + (default). + Additional dracut parameter and normal parameter can be deleimiter via a single dash (-) (default: "$build_initramfs_dracut_parameter"). EOF @@ -181,6 +186,15 @@ function build_initramfs_parse_command_line() { fi shift ;; + -t|--target) + shift + build_initramfs_target="$1" + if [[ "$build_initramfs_target" == '' ]]; then + logging.critical "This options needs a path create initramfs from." + return 1 + fi + shift + ;; -) shift while [[ "$1" =~ ^.+$ ]]; do @@ -262,6 +276,8 @@ function build_initramfs_cleanup() { # region controller +# TODO handle fakeroot target feature. + utils.dependency_check "${build_initramfs_dependencies[*]}" # TODO check for existing kernel headers. # Find lib locations: $(gcc -print-prog-name=cc1plus) -v -- cgit v1.2.3-55-g7522 From 43c6a1c73ed18cea3c0dedcc2e81a5b7a3d85406 Mon Sep 17 00:00:00 2001 From: torben Date: Thu, 10 Dec 2015 16:55:37 +0100 Subject: More fakechroot features. --- builder/build-initramfs.sh | 76 +++++++++++++++++++++++------------- builder/dnbd3-rootfs/module-setup.sh | 25 ++++++------ 2 files changed, 62 insertions(+), 39 deletions(-) (limited to 'builder') diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh index f4e7f699..dc56def6 100755 --- a/builder/build-initramfs.sh +++ b/builder/build-initramfs.sh @@ -3,16 +3,14 @@ # region header -# Copyright Torben Sickert (t.sickert["~at~"]gmail.com) 29.10.2015 +# Copyright Torben Sickert (info["~at~"]torben.website) 29.10.2015 # Janosch Dobler (TODO) 29.10.2015 # License # ------- - # This library written by Torben Sickert and Janosch Dobler stand under a # creative commons naming 3.0 unported license. # see http://creativecommons.org/licenses/by/3.0/deed.de - # This tool provides a generic way to install systemd based remote linux # initramfs. @@ -52,10 +50,7 @@ # as file name) for lines containing a match to the given # PATTERN. By default, grep prints the matching lines. -# endregion - -# region ensure presence of needed dependencies - +## region ensure presence of needed dependencies set -o errexit build_initramfs__needed_location="$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs" if ! [[ -d "$build_initramfs__needed_location" ]]; then @@ -76,20 +71,19 @@ if ! [[ -d "$build_initramfs__needed_location" ]]; then rm --recursive --force "$build_initramfs__temporary_repository_location" fi set +o errexit - -# endregion +## endregion source "$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs/scripts/rebash/core.sh" core.import exceptions exceptions.activate core.import logging core.import utils +# endregion logging.set_commands_log_level debug logging.set_log_level critical # region properties - build_initramfs_dracut_parameter='--force --no-hostonly' build_initramfs_verbose='no' build_initramfs_debug='no' @@ -97,14 +91,11 @@ build_initramfs_target='' build_initramfs_create_system_image='' build_initramfs_cleanup='no' build_initramfs_dependencies=(bash cpio git test shift echo mktemp cat rm sed \ - gzip curl tar grep make gcc cmake readlink dirname dmsetup fakeroot) - + gzip curl tar grep make gcc cmake readlink dirname dmsetup fakeroot \ + fakechroot chroot qemu-nbd) # endregion - # region functions - ## region command line interface - function build_initramfs_print_usage_message() { # Prints a description about how to use this program. logging.cat << EOF @@ -221,7 +212,7 @@ function build_initramfs_parse_command_line() { } ## endregion - +## region helper function build_initramfs_initialize_dracut() { # Downloads and compiles dracut. # @@ -271,13 +262,10 @@ function build_initramfs_cleanup() { clean return $? } - +## endregion # endregion - # region controller - -# TODO handle fakeroot target feature. - +## region dependency checks utils.dependency_check "${build_initramfs_dependencies[*]}" # TODO check for existing kernel headers. # Find lib locations: $(gcc -print-prog-name=cc1plus) -v @@ -289,15 +277,48 @@ if ! ldconfig --print-cache | grep libz.so; then logging.critical "You have to install the compression library \"libz\". Otherwise we aren't able to compile dnbd3 for your kernel." exit 1 fi +## endregion if ! build_initramfs_parse_command_line "$@"; then build_initramfs_print_help_message "$0" exit 1 fi +## region handle delegated operations to specified target +if [[ "$build_initramfs_target" != '' ]]; then + build_initramfs__target="$build_initramfs_target" + if [[ -f "$build_initramfs_target" ]]; then + build_initramfs__target="$(mktemp --directory)" + # TODO + #qemu-nbd "$build_initramfs_target" "$build_initramfs__target" + fi + if [[ -d "$build_initramfs__target" ]]; then + build_initramfs__temporary_working_directory="${build_initramfs__target:0:-1}$(fakeroot \ + fakechroot chroot "$build_initramfs__target" mktemp --directory)" + mount --bind "$(pwd)" "$build_initramfs__temporary_working_directory" + build_initramfs__parameter_skip=false + build_initramfs__parameter_to_forward=() + for build_initramfs__parameter; do + if $build_initramfs__parameter_skip; then + build_initramfs__parameter_skip=false + elif [[ "$build_initramfs__parameter" == '-t' ]] || \ + [[ "$build_initramfs__parameter" == '--target' ]] + then + build_initramfs__parameter_skip=true + else + build_initramfs__parameter_to_forward+=("$build_initramfs__parameter") + fi + done + "${build_initramfs__temporary_working_directory}/${BASH_SOURCE[0]}" ${build_initramfs__parameter_to_forward[*]} + fi + exit 0 +fi +## endregion +## region handle dependencies which can be resolved automatically logging.info 'Checking dracut.' if ! [[ -d "$(dirname "${BASH_SOURCE[0]}")/dracut" ]]; then logging.info "Dracut isn't available yet loading it." build_initramfs_initialize_dracut fi + build_initramfs__dracut_modules_source='../../dnbd3-rootfs' build_initramfs__dracut_modules_target="$(dirname "${BASH_SOURCE[0]}")/dracut/modules.d/90dnbd3-rootfs" if [[ ! -L "$build_initramfs__dracut_modules_target" || "$(readlink \ @@ -313,6 +334,8 @@ then # ... "$(basename "$build_initramfs__dracut_modules_source")" \ # ... "$build_initramfs__dracut_modules_target" fi +## endregion +## region prepare and perform final dracut call build_initramfs__loglevel='' if [ "$build_initramfs_verbose" == 'yes' ]; then build_initramfs__loglevel='--verbose' @@ -334,18 +357,15 @@ else # NOTE: We deactivate our exception handle since dracut returns "1" if it # is launched with help parameter ("-h" or "--help"). exceptions.deactivate - dracut/dracut.sh --local $build_initramfs__loglevel --modules \ - "$build_initramfs__modules" ${build_initramfs_dracut_parameter[*]} \ - /boot/initramfs-test.img + "$(dirname "${BASH_SOURCE[0]}")/dracut/dracut.sh" --local \ + $build_initramfs__loglevel --modules "$build_initramfs__modules" \ + ${build_initramfs_dracut_parameter[*]} /boot/initramfs-test.img exceptions.activate fi exceptions.deactivate - +## endregion # endregion - # region vim modline - # vim: set tabstop=4 shiftwidth=4 expandtab: # vim: foldmethod=marker foldmarker=region,endregion: - # endregion diff --git a/builder/dnbd3-rootfs/module-setup.sh b/builder/dnbd3-rootfs/module-setup.sh index 9101851c..ead0c99c 100755 --- a/builder/dnbd3-rootfs/module-setup.sh +++ b/builder/dnbd3-rootfs/module-setup.sh @@ -16,13 +16,13 @@ clean() { # dracut itself. if [[ -f "$moddir/binaries/nbd/nbd.ko" ]]; then - utils_clean_nbd "$moddir/binaries/nbd/" + build_clean_nbd "$moddir/binaries/nbd/" fi if [[ -f "$moddir/binaries/dnbd3/build/dnbd3.ko" || ! -f "$moddir/binaries/dnbd3/build/dnbd3-client" ]]; then - utils_clean_dnbd3 "$moddir/binaries/dnbd3/" + build_clean_dnbd3 "$moddir/binaries/dnbd3/" fi if [[ -f "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" ]]; then - utils_clean_systemd_preserve_process_marker \ + build_clean_systemd_preserve_process_marker \ "$moddir/binaries/systemd-preserve-process-marker/" fi return 0 @@ -33,13 +33,15 @@ check() { exceptions.activate if [[ ! -f "$moddir/binaries/nbd/nbd.ko" ]]; then - utils_compile_nbd "$moddir/binaries/nbd/" + build_compile_nbd "$moddir/binaries/nbd/" fi - if [[ ! -f "$moddir/binaries/dnbd3/build/dnbd3.ko" || ! -f "$moddir/binaries/dnbd3/build/dnbd3-client" ]]; then - utils_compile_dnbd3 "$moddir/binaries/dnbd3/" + if [[ ! -f "$moddir/binaries/dnbd3/build/dnbd3.ko" ]] || \ + [[ ! -f "$moddir/binaries/dnbd3/build/dnbd3-client" ]] + then + build_compile_dnbd3 "$moddir/binaries/dnbd3/" fi if [[ ! -f "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" ]]; then - utils_compile_systemd_preserve_process_marker \ + build_compile_systemd_preserve_process_marker \ "$moddir/binaries/systemd-preserve-process-marker/" fi @@ -129,13 +131,14 @@ install() { # region scripts - inst "$moddir/scripts/utils.sh" "/usr/lib/utils.sh" - for file in "$moddir/scripts/rebash/"*; do - inst "$file" "/usr/lib/rebash/$(basename $file)" + local file_path + for file_path in "$moddir/scripts/rebash/"*; do + inst "$file_path" "/usr/lib/rebash/$(basename "$file_path")" done # This script is triggered by udev upon finding the right partitions for # persistent sessions. - inst "$moddir/scripts/prepare-persistent-disks" /sbin/prepare-persistent-disks + inst "$moddir/scripts/prepare-persistent-disks" \ + /sbin/prepare-persistent-disks # endregion -- cgit v1.2.3-55-g7522 From de7e8716be7d441a83faee12f9bf75bf494dbe3a Mon Sep 17 00:00:00 2001 From: torben Date: Thu, 10 Dec 2015 17:10:13 +0100 Subject: more fakeroot support. --- builder/build-initramfs.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'builder') diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh index dc56def6..1d48f5ef 100755 --- a/builder/build-initramfs.sh +++ b/builder/build-initramfs.sh @@ -269,10 +269,6 @@ function build_initramfs_cleanup() { utils.dependency_check "${build_initramfs_dependencies[*]}" # TODO check for existing kernel headers. # Find lib locations: $(gcc -print-prog-name=cc1plus) -v -if false; then - logging.error "You have to install the compression library \"libz\". Otherwise we aren't able to compile dnbd3 for your kernel." - exit 1 -fi if ! ldconfig --print-cache | grep libz.so; then logging.critical "You have to install the compression library \"libz\". Otherwise we aren't able to compile dnbd3 for your kernel." exit 1 @@ -291,9 +287,10 @@ if [[ "$build_initramfs_target" != '' ]]; then #qemu-nbd "$build_initramfs_target" "$build_initramfs__target" fi if [[ -d "$build_initramfs__target" ]]; then - build_initramfs__temporary_working_directory="${build_initramfs__target:0:-1}$(fakeroot \ + build_initramfs__temporary_working_directory="$(fakeroot \ fakechroot chroot "$build_initramfs__target" mktemp --directory)" - mount --bind "$(pwd)" "$build_initramfs__temporary_working_directory" + mount --bind "$(pwd)" \ + "${build_initramfs__target}${build_initramfs__temporary_working_directory}" build_initramfs__parameter_skip=false build_initramfs__parameter_to_forward=() for build_initramfs__parameter; do @@ -307,7 +304,10 @@ if [[ "$build_initramfs_target" != '' ]]; then build_initramfs__parameter_to_forward+=("$build_initramfs__parameter") fi done - "${build_initramfs__temporary_working_directory}/${BASH_SOURCE[0]}" ${build_initramfs__parameter_to_forward[*]} + fakeroot fakechroot chroot "${build_initramfs__target}" \ + "${build_initramfs__temporary_working_directory}/${BASH_SOURCE[0]}" \ + ${build_initramfs__parameter_to_forward[*]} + # TODO grap result from /boot/initramfs-test.img fi exit 0 fi @@ -347,7 +347,6 @@ if [ "$build_initramfs_debug" == 'yes' ]; then fi if [[ "$build_initramfs_create_system_image" != '' ]]; then logging.info 'Create system image.' - echo "$build_initramfs_create_system_image" build_initramfs_create_qcow2_system "$build_initramfs_create_system_image" elif [[ "$build_initramfs_cleanup" == 'yes' ]]; then logging.info 'Removing distribution specific files.' -- cgit v1.2.3-55-g7522