KVMをVagrantを使って、仮想マシンをブートする。
virshコマンドを使って、仮想マシンを作成、操作する方法もあるが、ここでは、vagrantを使って、仮想マシンを操作する。
Install KVM, QEMU, libvirt, Vagrant
as root
# kvm
dnf -y install qemu-kvm libvirt virt-install libvirt-devel
systemctl enable --now libvirtd
# vagrant
yum install -y yum-utils
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
yum -y install vagrant
user=user
usermod -aG libvirt ${user}
su - ${user}
Install plugin for libvirt
vagrant plugin install vagrant-libvirt
Boot Virtual Machine
mkdir vmmachine && cat <<'VEOF' > vmmachine/Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure('2') do |config|
config.vm.box = 'almalinux/9'
config.vm.provider 'libvirt' do |vb|
vb.memory = 2048
vb.cpus = 2
end
end
VEOF
cd vmmachine && vagrant up
Clean Virtual Machine
vagrant destroy -f
cd -
rm -rf vmmachine