From a65402ad0ecafe6bff1978ad46d9cb800582db9f Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Thu, 3 Jun 2021 16:18:26 +0530 Subject: [PATCH 1/3] systemvmtemplate: reduce template by using cloud kernel This switches the systemvmtemplate to use the default linux-image-cloud kernel from Debian backports (v5.10), we don't really need many of the kernel modules such as sound drivers etc in the systemvm. This reduces the space consumed from a whooping 270+MB to just ~70MB by the kernel. Signed-off-by: Rohit Yadav --- tools/appliance/systemvmtemplate/http/preseed.cfg | 10 +++++++--- .../systemvmtemplate/scripts/apt_upgrade.sh | 7 +++++++ .../systemvmtemplate/scripts/configure_grub.sh | 2 ++ tools/appliance/systemvmtemplate/template.json | 15 +++++++++++---- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/tools/appliance/systemvmtemplate/http/preseed.cfg b/tools/appliance/systemvmtemplate/http/preseed.cfg index ce51f746c300..6da92dac7261 100644 --- a/tools/appliance/systemvmtemplate/http/preseed.cfg +++ b/tools/appliance/systemvmtemplate/http/preseed.cfg @@ -41,10 +41,14 @@ d-i mirror/http/proxy string ### Apt setup d-i apt-setup/cdrom/set-first false d-i apt-setup/security-updates boolean true -d-i apt-setup/services-select multiselect security, updates +d-i apt-setup/services-select multiselect backports, security, updates d-i apt-setup/security_host string security.debian.org d-i apt-setup/local0/source boolean false d-i apt-setup/multiarch string i386 +d-i apt-setup/backports boolean true +d-i apt-setup/contrib boolean true +d-i apt-setup/multiverse boolean true +d-i apt-setup/universe boolean true ### Clock and time zone setup d-i clock-setup/utc boolean true @@ -62,7 +66,7 @@ d-i partman-auto/expert_recipe string \ use_filesystem{ } filesystem{ ext2 } \ mountpoint{ /boot } \ . \ - 2240 40 2500 ext4 \ + 4500 40 5000 ext4 \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ / } \ @@ -94,7 +98,7 @@ d-i passwd/user-default-groups string audio cdrom video admin ### Package selection tasksel tasksel/first multiselect ssh-server -d-i pkgsel/include string openssh-server ntp acpid sudo bzip2 openssl +d-i pkgsel/include string linux-image-cloud-amd64 openssh-server ntp acpid sudo bzip2 openssl # Allowed values: none, safe-upgrade, full-upgrade d-i pkgsel/upgrade select full-upgrade d-i pkgsel/update-policy select none diff --git a/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh b/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh index ea75c2d8bf2c..28f7a6e9c558 100644 --- a/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh +++ b/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh @@ -53,11 +53,18 @@ function apt_upgrade() { rm -fv /root/*.iso apt-get -q -y update + + # Remove unused non-default kernel + apt-get remove -y --purge linux-image-amd64 linux-image-4.19.0-16-amd64 || true apt-get -q -y upgrade apt-get -q -y dist-upgrade + apt-get -q -y upgrade -t buster-backports + apt-get -q -y dist-upgrade -t buster-backports + apt-get -y autoremove --purge apt-get autoclean apt-get clean + reboot } return 2>/dev/null || apt_upgrade diff --git a/tools/appliance/systemvmtemplate/scripts/configure_grub.sh b/tools/appliance/systemvmtemplate/scripts/configure_grub.sh index 4d250c0417b1..2d7702b69484 100644 --- a/tools/appliance/systemvmtemplate/scripts/configure_grub.sh +++ b/tools/appliance/systemvmtemplate/scripts/configure_grub.sh @@ -20,6 +20,8 @@ set -e set -x function configure_grub() { + # Remove old kernel + apt-get remove -y --purge linux-image-4.19.0-16-cloud-amd64 || true echo "blacklist floppy" > /etc/modprobe.d/blacklist-floppy.conf rmmod floppy || true update-initramfs -u diff --git a/tools/appliance/systemvmtemplate/template.json b/tools/appliance/systemvmtemplate/template.json index 8f199513885c..277a2afb36eb 100644 --- a/tools/appliance/systemvmtemplate/template.json +++ b/tools/appliance/systemvmtemplate/template.json @@ -6,7 +6,14 @@ "type": "shell", "execute_command": "echo 'cloud' | sudo -u root -S bash {{.Path}}", "scripts": [ - "scripts/apt_upgrade.sh", + "scripts/apt_upgrade.sh" + ], + "expect_disconnect": true + }, + { + "type": "shell", + "execute_command": "echo 'cloud' | sudo -u root -S bash {{.Path}}", + "scripts": [ "scripts/configure_grub.sh", "scripts/configure_locale.sh", "scripts/configure_networking.sh", @@ -33,11 +40,11 @@ [ "-smp", "1" ] ], "format": "qcow2", - "disk_size": 2500, + "disk_size": 5000, "disk_interface": "virtio", "net_device": "virtio-net", - "iso_url": "https://cdimage.debian.org/debian-cd/10.8.0/amd64/iso-cd/debian-10.8.0-amd64-netinst.iso", - "iso_checksum": "934336d266535c91fcd12cd122c81f8261721efa117fdcb9a31615caa96c5c5ce3454ed5f28f1b25a7b1b5f44631fdfa78a93adb6445e2e2caaf6455ab344cf8", + "iso_url": "https://cdimage.debian.org/debian-cd/10.9.0/amd64/iso-cd/debian-10.9.0-amd64-netinst.iso", + "iso_checksum": "47d35187b4903e803209959434fb8b65ead3ad2a8f007eef1c3d3284f356ab9955aa7e15e24cb7af6a3859aa66837f5fa2e7441f936496ea447904f7dddfdc20", "iso_checksum_type": "sha512", "output_directory": "../dist", "http_directory": "http", From e1edc85a29a3bd8addd301fe906953c865ee8efb Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Thu, 3 Jun 2021 21:49:16 +0530 Subject: [PATCH 2/3] kernel from backports fails to boot on vmware :( let's try linux-image-4.19.0-16-cloud-amd64 Signed-off-by: Rohit Yadav --- tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh | 2 -- .../appliance/systemvmtemplate/scripts/configure_grub.sh | 1 - tools/appliance/systemvmtemplate/template.json | 9 +-------- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh b/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh index 28f7a6e9c558..74c682735425 100644 --- a/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh +++ b/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh @@ -59,12 +59,10 @@ function apt_upgrade() { apt-get -q -y upgrade apt-get -q -y dist-upgrade apt-get -q -y upgrade -t buster-backports - apt-get -q -y dist-upgrade -t buster-backports apt-get -y autoremove --purge apt-get autoclean apt-get clean - reboot } return 2>/dev/null || apt_upgrade diff --git a/tools/appliance/systemvmtemplate/scripts/configure_grub.sh b/tools/appliance/systemvmtemplate/scripts/configure_grub.sh index 2d7702b69484..583c2efe322f 100644 --- a/tools/appliance/systemvmtemplate/scripts/configure_grub.sh +++ b/tools/appliance/systemvmtemplate/scripts/configure_grub.sh @@ -21,7 +21,6 @@ set -x function configure_grub() { # Remove old kernel - apt-get remove -y --purge linux-image-4.19.0-16-cloud-amd64 || true echo "blacklist floppy" > /etc/modprobe.d/blacklist-floppy.conf rmmod floppy || true update-initramfs -u diff --git a/tools/appliance/systemvmtemplate/template.json b/tools/appliance/systemvmtemplate/template.json index 277a2afb36eb..a598e6dcfa12 100644 --- a/tools/appliance/systemvmtemplate/template.json +++ b/tools/appliance/systemvmtemplate/template.json @@ -6,14 +6,7 @@ "type": "shell", "execute_command": "echo 'cloud' | sudo -u root -S bash {{.Path}}", "scripts": [ - "scripts/apt_upgrade.sh" - ], - "expect_disconnect": true - }, - { - "type": "shell", - "execute_command": "echo 'cloud' | sudo -u root -S bash {{.Path}}", - "scripts": [ + "scripts/apt_upgrade.sh", "scripts/configure_grub.sh", "scripts/configure_locale.sh", "scripts/configure_networking.sh", From 7f2e9f0bc065a1e5abc42f05f74e12cfe6c90a6c Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Thu, 3 Jun 2021 22:55:31 +0530 Subject: [PATCH 3/3] alright let's at least try the latest 5.10 kernel which also ships with Debian 11 Signed-off-by: Rohit Yadav --- tools/appliance/systemvmtemplate/http/preseed.cfg | 6 +++--- tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh | 3 ++- .../appliance/systemvmtemplate/scripts/configure_grub.sh | 1 + .../scripts/install_systemvm_packages.sh | 1 + tools/appliance/systemvmtemplate/template.json | 9 ++++++++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/appliance/systemvmtemplate/http/preseed.cfg b/tools/appliance/systemvmtemplate/http/preseed.cfg index 6da92dac7261..f4c063b39a8e 100644 --- a/tools/appliance/systemvmtemplate/http/preseed.cfg +++ b/tools/appliance/systemvmtemplate/http/preseed.cfg @@ -60,13 +60,13 @@ d-i partman-auto/disk string /dev/vda d-i partman-auto/method string regular d-i partman-auto/expert_recipe string \ boot-root :: \ - 100 60 100 ext2 \ + 400 60 400 ext2 \ $primary{ } $bootable{ } \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext2 } \ mountpoint{ /boot } \ . \ - 4500 40 5000 ext4 \ + 4000 40 5000 ext4 \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ / } \ @@ -98,7 +98,7 @@ d-i passwd/user-default-groups string audio cdrom video admin ### Package selection tasksel tasksel/first multiselect ssh-server -d-i pkgsel/include string linux-image-cloud-amd64 openssh-server ntp acpid sudo bzip2 openssl +d-i pkgsel/include string openssh-server ntp acpid sudo bzip2 openssl # Allowed values: none, safe-upgrade, full-upgrade d-i pkgsel/upgrade select full-upgrade d-i pkgsel/update-policy select none diff --git a/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh b/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh index 74c682735425..8ba2df871e2f 100644 --- a/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh +++ b/tools/appliance/systemvmtemplate/scripts/apt_upgrade.sh @@ -55,14 +55,15 @@ function apt_upgrade() { apt-get -q -y update # Remove unused non-default kernel - apt-get remove -y --purge linux-image-amd64 linux-image-4.19.0-16-amd64 || true apt-get -q -y upgrade apt-get -q -y dist-upgrade apt-get -q -y upgrade -t buster-backports + apt-get -q -y dist-upgrade -t buster-backports apt-get -y autoremove --purge apt-get autoclean apt-get clean + reboot } return 2>/dev/null || apt_upgrade diff --git a/tools/appliance/systemvmtemplate/scripts/configure_grub.sh b/tools/appliance/systemvmtemplate/scripts/configure_grub.sh index 583c2efe322f..a3310fe158de 100644 --- a/tools/appliance/systemvmtemplate/scripts/configure_grub.sh +++ b/tools/appliance/systemvmtemplate/scripts/configure_grub.sh @@ -21,6 +21,7 @@ set -x function configure_grub() { # Remove old kernel + apt-get remove -y --purge linux-image-amd64 linux-image-4.19.0-16-amd64 || true echo "blacklist floppy" > /etc/modprobe.d/blacklist-floppy.conf rmmod floppy || true update-initramfs -u diff --git a/tools/appliance/systemvmtemplate/scripts/install_systemvm_packages.sh b/tools/appliance/systemvmtemplate/scripts/install_systemvm_packages.sh index 2e788f3ced59..3e68154ea78a 100644 --- a/tools/appliance/systemvmtemplate/scripts/install_systemvm_packages.sh +++ b/tools/appliance/systemvmtemplate/scripts/install_systemvm_packages.sh @@ -72,6 +72,7 @@ function install_packages() { strongswan libcharon-extra-plugins libstrongswan-extra-plugins strongswan-charon strongswan-starter \ virt-what open-vm-tools qemu-guest-agent hyperv-daemons + apt-get -y upgrade -t buster-backports apt-get -y autoremove --purge apt-get clean apt-get autoclean diff --git a/tools/appliance/systemvmtemplate/template.json b/tools/appliance/systemvmtemplate/template.json index a598e6dcfa12..277a2afb36eb 100644 --- a/tools/appliance/systemvmtemplate/template.json +++ b/tools/appliance/systemvmtemplate/template.json @@ -6,7 +6,14 @@ "type": "shell", "execute_command": "echo 'cloud' | sudo -u root -S bash {{.Path}}", "scripts": [ - "scripts/apt_upgrade.sh", + "scripts/apt_upgrade.sh" + ], + "expect_disconnect": true + }, + { + "type": "shell", + "execute_command": "echo 'cloud' | sudo -u root -S bash {{.Path}}", + "scripts": [ "scripts/configure_grub.sh", "scripts/configure_locale.sh", "scripts/configure_networking.sh",