使用Packer为KVM QEMU自动化构建CentOS 8 虚拟机映像

2023-11-02 10:30

本文主要是介绍使用Packer为KVM QEMU自动化构建CentOS 8 虚拟机映像,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

由于CentOS 8上没有找到/usr/bin/qemu-system-x86_64

可以使用Debian 11或OpenSUSE 15.3

如下是使用Debian 11上运行qemu

{"variables":{"cpu": "2","ram": "2048","name": "centos","disk_size": "40000","version": "8-stream","iso_checksum_type": "sha256","iso_checksum": "5d61940668bc5e40d1c974e42d39f048","iso_url": "/root/CentOS-Stream-8-x86_64-20211206-dvd1.iso","headless": "false","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/bin/qemu-system-x86_64","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": ["<up><wait><tab><wait> net.ifnames=0 biosdevname=0 text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{user `config_file`}}<enter><wait>"],"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": ["dnf -y update"]}]
}

ks.cfg

#version=RHEL8
# Use graphical install
graphicalrepo --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=lvmreboot --eject# System timezone
timezone Asia/Shanghai --isUtcnetwork --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

输出:

这篇关于使用Packer为KVM QEMU自动化构建CentOS 8 虚拟机映像的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/329991

相关文章

使用Dify访问mysql数据库详细代码示例

《使用Dify访问mysql数据库详细代码示例》:本文主要介绍使用Dify访问mysql数据库的相关资料,并详细讲解了如何在本地搭建数据库访问服务,使用ngrok暴露到公网,并创建知识库、数据库访... 1、在本地搭建数据库访问的服务,并使用ngrok暴露到公网。#sql_tools.pyfrom

使用mvn deploy命令上传jar包的实现

《使用mvndeploy命令上传jar包的实现》本文介绍了使用mvndeploy:deploy-file命令将本地仓库中的JAR包重新发布到Maven私服,文中通过示例代码介绍的非常详细,对大家的学... 目录一、背景二、环境三、配置nexus上传账号四、执行deploy命令上传包1. 首先需要把本地仓中要

Spring Cloud之注册中心Nacos的使用详解

《SpringCloud之注册中心Nacos的使用详解》本文介绍SpringCloudAlibaba中的Nacos组件,对比了Nacos与Eureka的区别,展示了如何在项目中引入SpringClo... 目录Naacos服务注册/服务发现引⼊Spring Cloud Alibaba依赖引入Naco编程s依

Java springBoot初步使用websocket的代码示例

《JavaspringBoot初步使用websocket的代码示例》:本文主要介绍JavaspringBoot初步使用websocket的相关资料,WebSocket是一种实现实时双向通信的协... 目录一、什么是websocket二、依赖坐标地址1.springBoot父级依赖2.springBoot依赖

Java使用Mail构建邮件功能的完整指南

《Java使用Mail构建邮件功能的完整指南》JavaMailAPI是一个功能强大的工具,它可以帮助开发者轻松实现邮件的发送与接收功能,本文将介绍如何使用JavaMail发送和接收邮件,希望对大家有所... 目录1、简述2、主要特点3、发送样例3.1 发送纯文本邮件3.2 发送 html 邮件3.3 发送带

Linux虚拟机不显示IP地址的解决方法(亲测有效)

《Linux虚拟机不显示IP地址的解决方法(亲测有效)》本文主要介绍了通过VMware新装的Linux系统没有IP地址的解决方法,主要步骤包括:关闭虚拟机、打开VM虚拟网络编辑器、还原VMnet8或修... 目录前言步骤0.问题情况1.关闭虚拟机2.China编程打开VM虚拟网络编辑器3.1 方法一:点击还原VM

使用DeepSeek搭建个人知识库(在笔记本电脑上)

《使用DeepSeek搭建个人知识库(在笔记本电脑上)》本文介绍了如何在笔记本电脑上使用DeepSeek和开源工具搭建个人知识库,通过安装DeepSeek和RAGFlow,并使用CherryStudi... 目录部署环境软件清单安装DeepSeek安装Cherry Studio安装RAGFlow设置知识库总

Python FastAPI入门安装使用

《PythonFastAPI入门安装使用》FastAPI是一个现代、快速的PythonWeb框架,用于构建API,它基于Python3.6+的类型提示特性,使得代码更加简洁且易于绶护,这篇文章主要介... 目录第一节:FastAPI入门一、FastAPI框架介绍什么是ASGI服务(WSGI)二、FastAP

Spring-AOP-ProceedingJoinPoint的使用详解

《Spring-AOP-ProceedingJoinPoint的使用详解》:本文主要介绍Spring-AOP-ProceedingJoinPoint的使用方式,具有很好的参考价值,希望对大家有所帮... 目录ProceedingJoinPoijsnt简介获取环绕通知方法的相关信息1.proceed()2.g

Maven pom.xml文件中build,plugin标签的使用小结

《Mavenpom.xml文件中build,plugin标签的使用小结》本文主要介绍了Mavenpom.xml文件中build,plugin标签的使用小结,文中通过示例代码介绍的非常详细,对大家的学... 目录<build> 标签Plugins插件<build> 标签<build> 标签是 pom.XML