From 3a7d36e9e8b6c8ad367b654de0398375f2c28ec9 Mon Sep 17 00:00:00 2001 From: jandob Date: Wed, 2 Mar 2016 09:36:55 +0100 Subject: handle situations when dracut is already installed in the target system --- .../copy-dracut-systemd-files-into-newroot.sh | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'builder') diff --git a/builder/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh b/builder/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh index 1bce5ffb..d308decd 100755 --- a/builder/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh +++ b/builder/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh @@ -10,6 +10,13 @@ exceptions.activate logging.set_commands_level debug logging.set_level debug +# Needed to be able to go back to dracut at system shutdown. +temporary_directory_path="$(mktemp --directory)" +mount --options bind / "$temporary_directory_path" +cp --recursive --no-target-directory "$temporary_directory_path" /run/initramfs +umount "$temporary_directory_path" +rm --dir "$temporary_directory_path" + # Dracut may not be installed on the new root. Thus copy all services over. systemd_system_unit_path="$(dirname "$(find / -name dracut-mount.service \ -type f -print -quit)")" @@ -25,19 +32,21 @@ for file in \ dracut-pre-trigger.service \ dracut-pre-udev.service do - cp "${systemd_system_unit_path}/${file}" \ - "${new_systemd_system_unit_path}/${file}" - ln --symbolic "../${file}" \ - "${new_systemd_system_unit_path}/initrd.target.wants/${file}" + exceptions.try + { + cp "${systemd_system_unit_path}/${file}" \ + "${new_systemd_system_unit_path}/${file}" + # ln returns an error if the link already exists + ln --symbolic "../${file}" \ + "${new_systemd_system_unit_path}/initrd.target.wants/${file}" + } + exceptions.catch + { + logging.warn "failed to copy dracut service files to NEWROOT, " \ + "maybe they already is already installed in the template system" + } done -# Needed to be able to go back to dracut at system shutdown. -temporary_directory_path="$(mktemp --directory)" -mount --options bind / "$temporary_directory_path" -cp --recursive --no-target-directory "$temporary_directory_path" /run/initramfs -umount "$temporary_directory_path" -rm --dir "$temporary_directory_path" - ); result=$?; exceptions.deactivate; [[ $result == 0 ]] || exit 1 # region vim modline -- cgit v1.2.3-55-g7522