Skip to content

Commit

Permalink
Disable automatic updates on Ubuntu and install qemu guest agent
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorific committed Sep 24, 2023
1 parent dfbabb8 commit 4603563
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
9 changes: 9 additions & 0 deletions ubuntu/aarch64/ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,13 @@ source "qemu" "ubuntu" {

build {
sources = ["source.qemu.ubuntu"]

provisioner "shell" {
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -S -E sh -eux '{{ .Path }}'"
expect_disconnect = true
scripts = [
"../scripts/disable-updates.sh",
"../scripts/qemu.sh",
]
}
}
30 changes: 30 additions & 0 deletions ubuntu/scripts/disable-updates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh -eux

export DEBIAN_FRONTEND=noninteractive

echo "==> Disable release-upgrades"
sed -i.bak 's/^Prompt=.*$/Prompt=never/' /etc/update-manager/release-upgrades;

echo "==> Disable systemd apt timers/services"
systemctl stop apt-daily.timer;
systemctl stop apt-daily-upgrade.timer;
systemctl disable apt-daily.timer;
systemctl disable apt-daily-upgrade.timer;
systemctl mask apt-daily.service;
systemctl mask apt-daily-upgrade.service;
systemctl daemon-reload;

# Disable periodic activities of apt to be safe
cat <<EOF >/etc/apt/apt.conf.d/10periodic;
APT::Periodic::Enable "0";
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "0";
EOF

echo "==> Remove the unattended-upgrades and ubuntu-release-upgrader-core packages"
apt-get -y purge unattended-upgrades ubuntu-release-upgrader-core;
rm -rf /var/log/unattended-upgrades;

apt-get update;
6 changes: 6 additions & 0 deletions ubuntu/scripts/qemu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh -eux
export DEBIAN_FRONTEND=noninteractive

echo "==> Install qemu guest agent"
apt-get install -y qemu-guest-agent
apt-get -y autoremove
12 changes: 9 additions & 3 deletions ubuntu/x86_64/ubuntu.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ source "qemu" "ubuntu" {
efi_boot = var.efi_boot
efi_firmware_code = var.efi_firmware_code
efi_firmware_vars = var.efi_firmware_vars
# efi_boot = true
# efi_firmware_code = "/usr/share/OVMF/OVMF_CODE.fd"
# efi_firmware_vars = "/usr/share/OVMF/OVMF_VARS.fd"
}

build {
sources = ["source.qemu.ubuntu"]

provisioner "shell" {
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -S -E sh -eux '{{ .Path }}'"
expect_disconnect = true
scripts = [
"../scripts/disable-updates.sh",
"../scripts/qemu.sh",
]
}
}

0 comments on commit 4603563

Please sign in to comment.