Skip to content

Instantly share code, notes, and snippets.

@rikonor
Created February 14, 2021 05:25
Show Gist options
  • Save rikonor/e8c0be38cbe34a73b7e00881281a639d to your computer and use it in GitHub Desktop.
Save rikonor/e8c0be38cbe34a73b7e00881281a639d to your computer and use it in GitHub Desktop.
Packer QEMU Pre-Seeded Debian Image
variable "iso_url" {
type = string
default = "https://cdimage.debian.org/cdimage/release/10.8.0/amd64/iso-cd/debian-10.8.0-amd64-netinst.iso"
}
variable "iso_checksum" {
type = string
default = "file:https://cdimage.debian.org/cdimage/release/10.8.0/amd64/iso-cd/MD5SUMS"
}
# "timestamp" template function replacement
locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
source "qemu" "debian" {
vm_name = "debian.qcow2"
format = "qcow2"
accelerator = "hvf"
boot_wait = "1s"
headless = true
memory = 1024
disk_size = "8192M"
iso_url = "${var.iso_url}"
iso_checksum = "${var.iso_checksum}"
ssh_password = "1234"
ssh_username = "1234"
ssh_timeout = "1h"
http_directory = "http"
boot_command = [
"<down><tab>",
" auto-install/enable=true",
" debconf/priority=critical",
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>",
" -- <wait>",
"<enter><wait>"
]
disk_compression = true
disk_discard = "unmap"
}
build {
sources = ["source.qemu.debian"]
}
# Preseeding only locale sets language, country and locale.
d-i debian-installer/locale string en_US
# Keyboard selection.
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/xkb-keymap select us
choose-mirror-bin mirror/http/proxy string
### Clock and time zone setup
d-i clock-setup/utc boolean true
d-i time/zone string UTC
# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note
# Pre-select the device to install grub
d-i grub-installer/bootdev string /dev/vda
# This is fairly safe to set, it makes grub install automatically to the MBR
# if no other operating system is detected on the machine.
d-i grub-installer/only_debian boolean true
# This one makes grub-installer install to the MBR if it also finds some other
# OS, which is less safe as it might not be able to boot that other OS.
d-i grub-installer/with_other_os boolean true
### Mirror settings
# If you select ftp, the mirror/country string does not need to be set.
d-i mirror/country string manual
d-i mirror/http/directory string /debian
d-i mirror/http/hostname string deb.debian.org
d-i mirror/http/proxy string
### Partitioning
d-i partman-auto/method string lvm
# This makes partman automatically partition without confirmation.
d-i partman-md/confirm boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
### Root setup
d-i passwd/root-password password 1234
d-i passwd/root-password-again password 1234
### Account setup
d-i passwd/user-fullname string vagrant
d-i passwd/user-uid string 1000
d-i passwd/user-password password vagrant
d-i passwd/user-password-again password vagrant
d-i passwd/username string vagrant
# The installer will warn about weak passwords. If you are sure you know
# what you're doing and want to override it, uncomment this.
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
### Package selection
tasksel tasksel/first multiselect ssh-server
d-i pkgsel/include string build-essential
d-i pkgsel/install-language-support boolean false
# disable automatic package updates
d-i pkgsel/update-policy select none
d-i pkgsel/upgrade select full-upgrade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment