由于CentOS 8上没有找到/usr/bin/qemu-system-x86_64
需要设置
"qemu_binary": "/usr/libexec/qemu-kvm",
另qemu-kvm编译时没有启用gtk
需要设置
"headless": "true",
{
"variables":
{
"cpu": "2",
"ram": "2048",
"name": "centos",
"disk_size": "40000",
"version": "8-stream",
"iso_checksum": "none",
"iso_url": "/root/CentOS-Stream-8-x86_64-20211206-dvd1.iso",
"headless": "true",
"config_file": "ks.cfg",
"ssh_username": "packer",
"ssh_password": "packer",
"destination_server": "download.goffinet.org"
},
"builders": [
{
"name": "{{user `name`}}{{user `version`}}",
"type": "qemu",
"format": "qcow2",
"accelerator": "kvm",
"qemu_binary": "/usr/libexec/qemu-kvm",
"net_device": "virtio-net",
"disk_interface": "virtio",
"disk_cache": "none",
"qemuargs": [[ "-m", "{{user `ram`}}M" ],[ "-smp", "{{user `cpu`}}" ]],
"ssh_wait_timeout": "3000h",
"http_directory": "http",
"ssh_username": "{{user `ssh_username`}}",
"ssh_password": "{{user `ssh_password`}}",
"iso_url": "{{user `iso_url`}}",
"iso_checksum": "{{user `iso_checksum`}}",
"boot_wait": "40s",
"boot_command": [
" net.ifnames=0 biosdevname=0 text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `config_file`}}"
],
"disk_size": "{{user `disk_size`}}",
"disk_discard": "unmap",
"disk_compression": true,
"headless": "{{user `headless`}}",
"shutdown_command": "shutdown -h now",
"output_directory": "artifacts/qemu/{{user `name`}}{{user `version`}}"
}
],
"provisioners": [
{
"type": "shell",
"execute_command": "echo 'packer'|{{.Vars}} sudo -S -E bash '{{.Path}}'",
"inline": [
"df -hT"
]
}
]
}
ks.cfg
#version=RHEL8
# Use graphical install
graphical
repo --name="AppStream" --baseurl=file:///run/install/sources/mount-0000-cdrom/AppStream
%packages
@^minimal-environment
kexec-tools
%end
# Keyboard layouts
keyboard --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
network --hostname=localhost.localdomain
# Use CDROM installation media
cdrom
# Run the Setup Agent on first boot
firstboot --enable
# System bootloader configuration
bootloader --location=mbr --append="crashkernel=no"
# Clear the Master Boot Record
zerombr
# Remove partitions
clearpart --all --initlabel
# Automatically create partitions using LVM
autopart --type=lvm
reboot --eject
# System timezone
timezone Asia/Shanghai --isUtc
network --device ens160 --onboot yes --bootproto dhcp --activate --noipv6 --hostname=CentOS8Packer
# Root password
rootpw --iscrypted $6$qC9lB22EyX3vb0wO$z/XXG4NZvVMz1wEFNfwYig9t0sYhzFMIfXkNfNAoBqxjfCY1USH2POrBnowaIC5w5QG0oYFnW3Ml6Ker/718y1
user --groups=wheel --name=packer --password=$6$AFD79/F4mP11CTLX$YgD6rTSaDj/kI0OIe22JhrlhYkBxMuut3phOGjQVx6IAtYrwGiVMAkEIY7HNWIiwi3r1JxZRlYJZ8vqJUtkZN0 --iscrypted --gecos="packer"
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
# dnf install tigervnc
使用tigervnc连接