From 5c62f25a1d2f34f6506c015e0d2a07e29528bf58 Mon Sep 17 00:00:00 2001 From: WereCatf Date: Sun, 13 Mar 2016 10:14:34 +0200 Subject: [PATCH 1/2] Greatly speed up firstrun Use fallocate to create swap instead of dd and only fall back to dd if it fails. fallocate takes < 1 second to create the file, even on very slow media. --- scripts/firstrun | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/firstrun b/scripts/firstrun index 596e447f4..fe8c464c0 100644 --- a/scripts/firstrun +++ b/scripts/firstrun @@ -35,7 +35,8 @@ dpkg-reconfigure openssh-server >/dev/null 2>&1 MEMTOTAL=$(( $(awk -F" " '/^MemTotal/ {print $2}' /dev/null 2>&1 +fallocate -l 128M /var/swap >/dev/null 2>&1 +if [ $? -eq 1 ]; then dd if=/dev/zero of=/var/swap bs=1024 count=131072 status=noxfer >/dev/null 2>&1; fi chown root:root /var/swap chmod 0600 /var/swap mkswap /var/swap >/dev/null 2>&1 From 91eae35f3cab3425864eded0efc8ecd6c5b4aad6 Mon Sep 17 00:00:00 2001 From: WereCatf Date: Sun, 13 Mar 2016 10:34:25 +0200 Subject: [PATCH 2/2] Fix race-condition with create_swap.sh Stupid code just relied on create_swap.sh taking a long time to execute. --- scripts/firstrun | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/firstrun b/scripts/firstrun index fe8c464c0..b5c47c615 100644 --- a/scripts/firstrun +++ b/scripts/firstrun @@ -62,6 +62,7 @@ if [[ "$(apt-cache policy ramlog | grep Installed)" != "" ]]; then fi fi fi +while [ -f /tmp/firstrun_running ]; do sleep 1; done if [ -f "/var/run/reboot" ]; then reboot; fi rm -f /tmp/create_swap.sh EOT @@ -201,6 +202,7 @@ main() { display_alert "Creating 128Mb emergency swap area" display_alert "SSH keys recreation. One moment please" display_alert "Updating packages" + touch /tmp/firstrun_running /tmp/create_swap.sh & if [ "X${HARDWARE}" = "Xsun8i" -o "X${HARDWARE}" = "Xsun7i" ]; then @@ -209,6 +211,7 @@ main() { update-rc.d -f firstrun remove >/dev/null 2>&1 sed -i 's/allow-hotplug\ eth0/auto eth0/' /etc/network/interfaces.default + rm /tmp/firstrun_running } # main main