summaryrefslogtreecommitdiffstats
path: root/builder/build-initramfs.sh
diff options
context:
space:
mode:
authortorben2015-12-18 16:36:13 +0100
committertorben2015-12-18 16:36:13 +0100
commit20718e888d32ff94fa5f5e9589e7ed11651c74ff (patch)
tree7e731042f716636eebbfd6c19a62ca1d1e962c0a /builder/build-initramfs.sh
parentRemove fakeroot to switch root. (diff)
downloadsystemd-init-20718e888d32ff94fa5f5e9589e7ed11651c74ff.tar.gz
systemd-init-20718e888d32ff94fa5f5e9589e7ed11651c74ff.tar.xz
systemd-init-20718e888d32ff94fa5f5e9589e7ed11651c74ff.zip
Provide new change root remote building approach.
Diffstat (limited to 'builder/build-initramfs.sh')
-rwxr-xr-xbuilder/build-initramfs.sh85
1 files changed, 45 insertions, 40 deletions
diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh
index 6a81eccf..26293ebe 100755
--- a/builder/build-initramfs.sh
+++ b/builder/build-initramfs.sh
@@ -51,6 +51,7 @@
# PATTERN. By default, grep prints the matching lines.
## 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
@@ -71,6 +72,7 @@ if ! [[ -d "$build_initramfs__needed_location" ]]; then
rm --recursive --force "$build_initramfs__temporary_repository_location"
fi
set +o errexit
+
## endregion
source "$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs/scripts/rebash/core.sh"
@@ -78,12 +80,15 @@ core.import exceptions
exceptions.activate
core.import logging
core.import utils
+core.import change_root
+
# endregion
logging.set_commands_log_level debug
logging.set_log_level critical
# region properties
+
build_initramfs_file_path='/boot/initramfs.img'
build_initramfs_dracut_parameter='--force --no-hostonly'
build_initramfs_verbose='no'
@@ -93,9 +98,13 @@ build_initramfs_create_system_image=''
build_initramfs_cleanup='no'
build_initramfs_dependencies=(cpio git test shift mktemp cat rm sed gzip curl \
tar grep make gcc cmake readlink dirname dmsetup 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
@@ -231,7 +240,9 @@ function build_initramfs_parse_command_line() {
}
## endregion
+
## region helper
+
function build_initramfs_initialize_dracut() {
# Downloads and compiles dracut.
#
@@ -284,10 +295,15 @@ function build_initramfs_cleanup() {
clean
return $?
}
+
## endregion
+
# endregion
+
# region controller
+
## region dependency checks
+
utils.dependency_check "${build_initramfs_dependencies[*]}"
# TODO check for existing kernel headers.
# Find lib locations: $(gcc -print-prog-name=cc1plus) -v
@@ -295,12 +311,16 @@ 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
@@ -313,24 +333,6 @@ if [[ "$build_initramfs_target" != '' ]]; then
"$build_initramfs__target" mktemp --directory)"
mount --bind "$(pwd)" \
"${build_initramfs__target}${build_initramfs__temporary_working_directory}"
-
- # TODO implement a more nice chroot method
- mkdir --parents "${build_initramfs__temporary_working_directory}/proc"
- mount /proc \
- "${build_initramfs__temporary_working_directory}/proc" --types \
- proc --options nosuid,noexec,nodev
- mkdir --parents "${build_initramfs__temporary_working_directory}/dev"
- mount udev "${build_initramfs__temporary_working_directory}/dev" \
- --types devtmpfs --options mode=0755,nosuid
- mkdir --parents \
- "${build_initramfs__temporary_working_directory}/dev/pts"
- mount devpts "${build_initramfs__temporary_working_directory}/dev/pts" \
- --types devpts --options mode=0620,gid=5,nosuid,noexec
- mkdir --parents \
- "${build_initramfs__temporary_working_directory}/dev/shm"
- mount shm "${build_initramfs__temporary_working_directory}/dev/shm" \
- --types tmpfs --options mode=1777,nosuid,nodev
-
build_initramfs__parameter_skip=false
build_initramfs__parameter_to_forward=()
for build_initramfs__parameter; do
@@ -344,37 +346,32 @@ if [[ "$build_initramfs_target" != '' ]]; then
build_initramfs__parameter_to_forward+=("$build_initramfs__parameter")
fi
done
- # NOTE: We temporary patch dracut to avoid removing the environment
- # variables "LD_LIBRARY_PATH" and "LD_PRELOAD" to get "fakechroot"
- # working with dracut. So we should remove this variables before
- # running the patched dracut version to follow the initial intention.
- unset LD_LIBRARY_PATH
- unset LD_PRELOAD
- # TODO
- # patch dracut.sh temporary:
- # unset LD_LIBRARY_PATH
- # unset LD_PRELOAD
- # have to be removed! Since they broke the fakechroot environment.
- # TODO check FAKECHROOT_CMD_SUBST
- FAKECHROOT_CMD_SUBST=/usr/bin/ldconfig=/usr/bin/ldconfig fakeroot \
- fakechroot chroot "${build_initramfs__target}" \
+ # NOTE: We would have to temporary patch dracut to avoid removing the
+ # environment variables "LD_LIBRARY_PATH" and "LD_PRELOAD" to get
+ # "fakechroot" working with dracut. So we should remove this variables
+ # before running the patched dracut version to follow the initial
+ # intention. You should first do:
+ # >>> unset LD_LIBRARY_PATH
+ # >>> unset LD_PRELOAD
+ # and patch "dracut.sh" temporary to comment out:
+ # >>> unset LD_LIBRARY_PATH
+ # >>> unset LD_PRELOAD
+ # To avoid to broke the "fakechroot" environment pipe the ldconfig call
+ # to the native one:
+ # >>> FAKECHROOT_CMD_SUBST=/usr/bin/ldconfig=/usr/bin/ldconfig
+ change_root "${build_initramfs__target}" \
"${build_initramfs__temporary_working_directory}/${BASH_SOURCE[0]}" \
${build_initramfs__parameter_to_forward[*]}
-
- umount /proc
- umount /dev
- umount /dev/pts
- umount /dev/shm
-
- umount "${build_initramfs__target}${build_initramfs__temporary_working_directory}"
-
mv "${build_initramfs__target}/$build_initramfs_file_path" \
"$build_initramfs_file_path"
fi
exit 0
fi
+
## endregion
+
## region handle dependencies which can be resolved automatically
+
logging.info 'Checking dracut.'
if ! [[ -f "$(dirname "${BASH_SOURCE[0]}")/dracut/dracut-install" ]]; then
logging.info "Dracut isn't available yet loading it."
@@ -398,8 +395,11 @@ then
"$build_initramfs__dracut_modules_target"
fi
fi
+
## endregion
+
## region prepare and perform final dracut call
+
build_initramfs__loglevel=''
if [ "$build_initramfs_verbose" == 'yes' ]; then
build_initramfs__loglevel='--verbose'
@@ -426,9 +426,14 @@ else
exceptions.activate
fi
exceptions.deactivate
+
## endregion
+
# endregion
+
# region vim modline
+
# vim: set tabstop=4 shiftwidth=4 expandtab:
# vim: foldmethod=marker foldmarker=region,endregion:
+
# endregion