Просмотр исходного кода

fix hibernation swap size computation

rename script from vbox to packer

remove cleanup script
Casey DeLorme 4 лет назад
Родитель
Сommit
7ee4845d84
4 измененных файлов с 19 добавлено и 32 удалено
  1. 1 5
      packer.json
  2. 0 14
      setup/clean.sh
  3. 9 13
      setup/install.sh
  4. 9 0
      setup/packer.sh

+ 1 - 5
packer.json

@@ -64,11 +64,7 @@
 		},
 		{
 			"type": "shell",
-			"script": "setup/vbox.sh"
-		},
-		{
-			"type": "shell",
-			"script": "setup/clean.sh"
+			"script": "setup/packer.sh"
 		}
 	],
 	"post-processors": [

+ 0 - 14
setup/clean.sh

@@ -1,14 +0,0 @@
-#!/usr/bin/bash -x
-
-##
-# post execution steps to reduce image size
-##
-
-# Clean the pacman cache.
-yes | pacman -Scc
-
-# Write zeros to improve virtual disk compaction.
-zerofile=$(mktemp /zerofile.XXXXX)
-dd if=/dev/zero of="$zerofile" bs=1M
-rm -f "$zerofile"
-sync

+ 9 - 13
setup/install.sh

@@ -32,11 +32,8 @@ ping -c 3 archlinux.org
 timedatectl set-ntp true
 timedatectl status
 
-# detect disks (if only one exists we can use it)
-# @todo: make sure this ignores optical drives (???)
-export disk=$(lsblk -l | grep disk | awk '{print $1}')
-
 # if more than one disk exists ask which to use:
+export disk=$(lsblk -l | grep disk | awk '{print $1}')
 if [ $(echo "$disk" | wc -l) -gt 1 ]; then
 	echo -e "multiple disks found:\n$disk"
 	read -p "please enter the name of the disk you want to use: " disk
@@ -48,15 +45,14 @@ if [ $(echo "$disk" | wc -l) -gt 1 ]; then
 	fi
 fi
 
-# either use sane default or intelligently size swap for hibernation
+# assume sane default for swap, or intelligently size for hibernation
 export swap_size=2048
 if [ "$enable_hibernation" = "y" ]; then
-	export ram_size=$(numfmt --from-unit=K --from=iec --to-unit=M --to=iec $(cat /proc/meminfo | grep MemTotal | awk '{print $2}'))
-	if [ $ram_size -le $(numfmt --from-unit=1024 --from=iec 4G) ]; then
-		export swap_size=$(printf %.0f $(echo "$ram_size * 1.5" | bc))
+	export ram_size=$(numfmt --to-unit=Mi --from-unit=K $(cat /proc/meminfo | grep MemTotal | awk '{print $2}'))
+	if [ $ram_size -le $(numfmt --to-unit=Mi --from=iec 4G) ]; then
+		export swap_size=$(echo $(($ram_size * 3 / 2)))
 	else
-		export ram_sqrt=$(echo "sqrt($(numfmt --from-unit=M --to-unit=Gi $ram_size))" | bc)
- 		export swap_size=$(printf %.0f $(echo "$ram_size + $(numfmt --from-unit=Gi --to-unit=Mi $ram_sqrt)" | bc))
+		swap_size=$(printf %.0f $(echo "sqrt($ram_size) + $ram_size" | bc))
 	fi
 fi
 
@@ -64,8 +60,8 @@ fi
 parted "/dev/${disk}" -s 'mklabel gpt'
 parted "/dev/${disk}" -s 'mkpart primary fat32 1MiB 1024MiB'
 parted "/dev/${disk}" -s 'set 1 esp on'
-parted "/dev/${disk}" -s "mkpart primary linux-swap 1024MiB ${swap_size}MiB"
-parted "/dev/${disk}" -s "mkpart primary btrfs ${swap_size}MiB 100%"
+parted "/dev/${disk}" -s "mkpart primary linux-swap 1024MiB $((swap_size + 1024))MiB"
+parted "/dev/${disk}" -s "mkpart primary btrfs $((swap_size + 1024))MiB 100%"
 
 # acquire partitions as an array
 export partitions=( $(lsblk -l -xNAME "/dev/${disk}" | grep part | awk '{print $1}') )
@@ -85,7 +81,7 @@ mount "/dev/${partitions[0]}" /mnt/boot
 pacstrap /mnt base base-devel
 genfstab -U -p /mnt >> /mnt/etc/fstab
 
-# this assumes that arch.sh and install/ exists and will copy them to continue
+# this assumes that arch.sh and install/ exist and will copy them to continue
 # @note: would prefer to copy to `/tmp` but `/mnt/tmp` from iso is a separate tmpfs
 mkdir -p /mnt/srv/arch-desktop
 cp -r install /mnt/srv/arch-desktop/

+ 9 - 0
setup/vbox.sh → setup/packer.sh

@@ -7,3 +7,12 @@ echo -e 'vboxguest\nvboxsf\nvboxvideo' > /etc/modules-load.d/virtualbox.conf
 
 systemctl enable vboxservice.service
 systemctl enable rpcbind.service
+
+# Clean the pacman cache.
+yes | pacman -Scc
+
+# Write zeros to improve virtual disk compaction.
+zerofile=$(mktemp /zerofile.XXXXX)
+dd if=/dev/zero of="$zerofile" bs=1M
+rm -f "$zerofile"
+sync