From c8855aa08dafaa02c939039e55e01967bad61c28 Mon Sep 17 00:00:00 2001 From: Derek Date: Sat, 7 May 2022 09:52:31 -0400 Subject: [PATCH] modifications of firstrun scripts (#3642) * modifications of firstrun scripts * Further making use of systemd statements to order firstboot scripts * allow systemd ordering of ssh to avoid restarting in firstrun script * suggested changes, add wants=first-boot-complete * Remove SSH keys in debootstrap process Co-authored-by: Igor Pecovnik --- lib/debootstrap.sh | 3 +++ .../lib/systemd/system/armbian-firstrun-config.service | 6 ++++-- .../common/lib/systemd/system/armbian-firstrun.service | 8 +++++--- .../lib/systemd/system/armbian-resize-filesystem.service | 4 +++- packages/bsp/common/usr/lib/armbian/armbian-firstrun | 4 ++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/debootstrap.sh b/lib/debootstrap.sh index 61e6b8804..566f9b40a 100644 --- a/lib/debootstrap.sh +++ b/lib/debootstrap.sh @@ -74,6 +74,9 @@ PRE_INSTALL_DISTRIBUTION_SPECIFIC # install from apt.armbian.com [[ $EXTERNAL_NEW == prebuilt ]] && chroot_installpackages "yes" + # remove existing ssh keys. They will be created in 1st boot process + rm -f $SDCARD/etc/ssh/ssh_host* + # stage: user customization script # NOTE: installing too many packages may fill tmpfs mount customize_image diff --git a/packages/bsp/common/lib/systemd/system/armbian-firstrun-config.service b/packages/bsp/common/lib/systemd/system/armbian-firstrun-config.service index 20943ec42..08e701d96 100644 --- a/packages/bsp/common/lib/systemd/system/armbian-firstrun-config.service +++ b/packages/bsp/common/lib/systemd/system/armbian-firstrun-config.service @@ -3,13 +3,15 @@ [Unit] Description=Armbian first run optional user configuration -Wants=network-online.target +Wants=network-online.target first-boot-complete.target After=network.target network-online.target +Before=first-boot-complete.target ConditionPathExists=/boot/armbian_first_run.txt ConditionPathExists=/root/.not_logged_in_yet +ConditionFirstBoot=yes [Service] -Type=idle +Type=oneshot RemainAfterExit=yes ExecStart=/usr/lib/armbian/armbian-firstrun-config TimeoutStartSec=2min diff --git a/packages/bsp/common/lib/systemd/system/armbian-firstrun.service b/packages/bsp/common/lib/systemd/system/armbian-firstrun.service index 64a390950..81ce7b4d6 100644 --- a/packages/bsp/common/lib/systemd/system/armbian-firstrun.service +++ b/packages/bsp/common/lib/systemd/system/armbian-firstrun.service @@ -4,14 +4,16 @@ [Unit] Description=Armbian first run tasks -Before=getty.target system-getty.slice +Wants=first-boot-complete.target +Before=getty.target system-getty.slice first-boot-complete.target ssh.service +After=armbian-resize-filesystem.service +ConditionFirstBoot=yes [Service] -Type=simple +Type=oneshot RemainAfterExit=yes ExecStart=/usr/lib/armbian/armbian-firstrun start TimeoutStartSec=2min [Install] WantedBy=multi-user.target - diff --git a/packages/bsp/common/lib/systemd/system/armbian-resize-filesystem.service b/packages/bsp/common/lib/systemd/system/armbian-resize-filesystem.service index 5c8117841..3ac555f94 100644 --- a/packages/bsp/common/lib/systemd/system/armbian-resize-filesystem.service +++ b/packages/bsp/common/lib/systemd/system/armbian-resize-filesystem.service @@ -4,9 +4,11 @@ [Unit] Description=Armbian filesystem resize -Before=basic.target +Wants=first-boot-complete.target +Before=basic.target first-boot-complete.target After=sysinit.target local-fs.target DefaultDependencies=no +ConditionFirstBoot=yes [Service] Type=oneshot diff --git a/packages/bsp/common/usr/lib/armbian/armbian-firstrun b/packages/bsp/common/usr/lib/armbian/armbian-firstrun index 975bafef2..a01caa210 100755 --- a/packages/bsp/common/usr/lib/armbian/armbian-firstrun +++ b/packages/bsp/common/usr/lib/armbian/armbian-firstrun @@ -56,7 +56,7 @@ case "$1" in rm -f /etc/ssh/ssh_host* read entropy_before /dev/null 2>&1 - service sshd restart + read entropy_after >${Log} @@ -129,7 +129,7 @@ case "$1" in [[ $BRANCH == dev && $LINUXFAMILY == rockchip ]] && set_fixed_mac [[ $BRANCH == current && $LINUXFAMILY == odroidc1 ]] && set_fixed_mac [[ $LINUXFAMILY == meson64 ]] && set_fixed_mac - systemctl disable armbian-firstrun + exit 0 ;;