使用Packer为 VMware Workstation Pro和 Oracle VM VirtualBox 自动化构建Debian 11 虚拟机映像

preseed.cfg

# To see all available options execute this command once the install is done:
# sudo less /var/log/installer/cdebconf/questions.dat
# If you need information about an option use the command below (example for keymap):
# grep -A 4 "keyboard-configuration/xkb-keymap" /var/log/installer/cdebconf/templates.dat

# Use network mirror for package installation
# d-i apt-setup/use_mirror boolean true

# Automatic installation
d-i auto-install/enable boolean true

# "linux-server" is substituted by "linux-image-amd64"
# Possible options : "linux-image-amd64"(default) or "linux-image-rt-amd64"
d-i base-installer/kernel/override-image string linux-server

# Configure hardware clock
d-i clock-setup/utc boolean true
d-i clock-setup/utc-auto boolean true

# d-i console-setup/ask_detect boolean false

# d-i debconf/frontend select noninteractive

# Set OS locale
d-i debian-installer/language string en
d-i debian-installer/country string US
d-i debian-installer/locale string en_US.UTF-8

# d-i debian-installer/framebuffer boolean false

# Reboot once the install is done
d-i finish-install/reboot_in_progress note

# Bootloader options
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string /dev/sda

# Set the keyboard layout
d-i keyboard-configuration/xkb-keymap select us

# Mirror from which packages will be downloaded
d-i mirror/country string manual
d-i mirror/http/directory string /debian
d-i mirror/http/hostname string httpredir.debian.org

# Configure http proxy if needed "http://[[user][:pass]@]host[:port]/"
d-i mirror/http/proxy string

# Disk configuration
d-i partman-efi/non_efi_system boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/device_remove_lvm 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/confirm_write_new_label boolean true

# User configuration
d-i passwd/root-login boolean true
d-i passwd/root-password-again password packer
d-i passwd/root-password password packer
d-i passwd/user-fullname string packer
d-i passwd/user-uid string 1000
d-i passwd/user-password password packer
d-i passwd/user-password-again password packer
d-i passwd/username string packer

# Extra packages to be installed
d-i pkgsel/include string sudo

d-i pkgsel/install-language-support boolean false
d-i pkgsel/update-policy select none

# Whether to upgrade packages after debootstrap
d-i pkgsel/upgrade select full-upgrade

# Set timezone
d-i time/zone string Europe/Paris

# Allow weak user password
d-i user-setup/allow-password-weak boolean true

# Home folder encryption
d-i user-setup/encrypt-home boolean false

# Do not scan additional CDs
apt-cdrom-setup apt-setup/cdrom/set-first boolean false

# Use network mirror
apt-mirror-setup apt-setup/use_mirror boolean true

# Disable polularity contest
popularity-contest popularity-contest/participate boolean false

# Select base install
tasksel tasksel/first multiselect standard, ssh-server

# Setup passwordless sudo for packer user
d-i preseed/late_command string \
  echo "packer ALL=(ALL:ALL) NOPASSWD:ALL" > /target/etc/sudoers.d/packer && chmod 0440 /target/etc/sudoers.d/packer

debian11.json

{
  "variables": {
      "vm_name": "debian-11.0.0-amd64",
      "numvcpus": "1",
      "memsize": "1024",
      "disk_size": "40960",
      "iso_url": "file://F:\\debian-11.1.0-amd64-DVD-1.iso",
      "iso_checksum": "27ba728881caeb73b49121697bf3af00",
      "ssh_username" : "packer",
      "ssh_password" : "packer",
      "boot_wait": "5s"
    },
    "builders": [
      {
        "type": "vmware-iso",
        "boot_command": ["<esc>auto preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<enter>"],
        "boot_wait": "{{ user `boot_wait` }}",
        "disk_size": "{{ user `disk_size` }}",
        "disk_type_id": "0",
        "guest_os_type": "debian10-64",
        "headless": false,
        "http_directory": "http",
        "iso_checksum": "{{ user `iso_checksum` }}",
        "iso_url": "{{ user `iso_url` }}",
        "shutdown_command": "echo 'packer'|sudo -S shutdown -P now",
        "ssh_password": "{{ user `ssh_password` }}",
        "ssh_port": 22,
        "ssh_username": "{{ user `ssh_username` }}",
        "ssh_timeout": "30h",
        "vm_name": "{{ user `vm_name` }}",
        "vmx_data": {
          "memsize": "{{ user `memsize` }}",
          "numvcpus": "{{ user `numvcpus` }}",
          "virtualHW.version": "14"
        }
      },
      {
        "type": "virtualbox-iso",
        "boot_command": ["<esc>auto preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<enter>"],
        "boot_wait": "{{ user `boot_wait` }}",
        "disk_size": "{{ user `disk_size` }}",
        "headless": false,
        "guest_os_type": "Debian_64",
        "http_directory": "http",
        "iso_checksum": "{{ user `iso_checksum` }}",
        "iso_url": "{{ user `iso_url` }}",
        "shutdown_command": "echo 'packer'|sudo -S shutdown -P now",
        "ssh_password": "{{ user `ssh_password` }}",
        "ssh_port": 22,
        "ssh_username": "{{ user `ssh_username` }}",
        "ssh_timeout": "30h",
        "vm_name": "{{ user `vm_name` }}",
        "vboxmanage": [
          ["modifyvm", "{{.Name}}", "--memory", "{{ user `memsize` }}"],
          ["modifyvm", "{{.Name}}", "--cpus", "{{ user `numvcpus` }}"]
        ]
      }
  ],
  "provisioners": [
    {
      "type": "shell",
      "execute_command": "echo 'packer'|{{.Vars}} sudo -S -E bash '{{.Path}}'",
      "inline": [
        "df -hT"
      ]
    }
  ]
}
F:\packer-Debian11>packer build -only=vmware-iso debian11.json
Warning: Warning when preparing build: "vmware-iso"

Your vmx data contains the following variable(s), which Packer normally sets
when it generates its own default vmx template. This may cause your build to
fail or behave unpredictably: numvcpus, memsize, virtualHW.version


vmware-iso: output will be in this color.

==> vmware-iso: Retrieving ISO
==> vmware-iso: Trying file://F:\debian-11.1.0-amd64-DVD-1.iso
==> vmware-iso: Trying file://F:/debian-11.1.0-amd64-DVD-1.iso?checksum=md5%3A27ba728881caeb73b49121697bf3af00
==> vmware-iso: file://F:/debian-11.1.0-amd64-DVD-1.iso?checksum=md5%3A27ba728881caeb73b49121697bf3af00 => F:/debian-11.1.0-amd64-DVD-1.iso
==> vmware-iso: Configuring output and export directories...
==> vmware-iso: Creating required virtual machine disks
==> vmware-iso: Building and writing VMX file
==> vmware-iso: Starting HTTP server on port 8899
==> vmware-iso: Starting virtual machine...
==> vmware-iso: Connecting to VNC...
==> vmware-iso: Waiting 5s for boot...
==> vmware-iso: Typing the boot command over VNC...
==> vmware-iso: Waiting for SSH to become available...
==> vmware-iso: Connected to SSH!
==> vmware-iso: Provisioning with shell script: C:\Users\ADMINI~1\AppData\Local\Temp\packer-shell2318967041
    vmware-iso: Filesystem                  Type      Size  Used Avail Use% Mounted on
    vmware-iso: udev                        devtmpfs  471M     0  471M   0% /dev
    vmware-iso: tmpfs                       tmpfs      98M  1.9M   96M   2% /run
    vmware-iso: /dev/mapper/debian--vg-root ext4       38G  1.3G   35G   4% /
    vmware-iso: tmpfs                       tmpfs     489M     0  489M   0% /dev/shm
    vmware-iso: tmpfs                       tmpfs     5.0M     0  5.0M   0% /run/lock
    vmware-iso: /dev/sda1                   ext2      470M   85M  361M  19% /boot
    vmware-iso: tmpfs                       tmpfs      98M     0   98M   0% /run/user/1000
==> vmware-iso: Gracefully halting virtual machine...
    vmware-iso: Waiting for VMware to clean up after itself...
==> vmware-iso: Deleting unnecessary VMware files...
    vmware-iso: Deleting: output-vmware-iso\vm.scoreboard
    vmware-iso: Deleting: output-vmware-iso\vmware.log
==> vmware-iso: Compacting all attached virtual disks...
    vmware-iso: Compacting virtual disk 1
==> vmware-iso: Cleaning VMX prior to finishing up...
    vmware-iso: Disabling VNC server...
==> vmware-iso: Skipping export of virtual machine...
Build 'vmware-iso' finished after 9 minutes 202 milliseconds.

==> Wait completed after 9 minutes 202 milliseconds

==> Builds finished. The artifacts of successful builds are:
--> vmware-iso: VM files in directory: output-vmware-iso

F:\packer-Debian11>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值