kvm | ||
mmdebstrap | ||
README.md |
Provisioning scripts
Scripts used for provisioning
mmdebstrap
mmdebstrap-deb12
Script to create systemd-container using mmdebstrap
Recommended to use the current mmdebstrap
systemd-container handles assigning IP address to container and name resolution for contianers via libnss-mymachines
Usage
Be sure to read the script and provide appropriate information including Apt proxy, user name and password, and user and root SSH public keys. If not using an Apt proxy delete the corresponding lines.
# create container named 'deb12-1'
./mmdebstrap-deb12 deb12-1
# start the container
sudo machinectl start deb12-1
# access the container
ssh deb12-1
KVM
etc-profile.d-virsh.sh
Useful Bash aliases (actually they are functions) for managing KVM containers.
For these aliases to be system-wide for Bash users, put them in:
/etc/profile.d/virsh.sh
For a user only, they can be copied into ~/.bashrc
vlist List machines and their status
vstart <machine> Start <machine>
vsave <machine> Save (suspend) <machine>
vtop <machine> Stop (gracefully shutdown) <machine>
vkill <machine> Kill (force shutdown) <machine>
vconsole <machine> Open console on <machine>
vrm <machine> Completely remove (destroy) <machine>
kvm-setup
Bash script to assist with setting up a Linux virtual machine under KVM/QEMU from an ISO image file.
Usage
Edit the variables machineName
, isoImage
, machineMemory
, diskSize
, and cpuNumber
. machineMemory
is the number of Gigabytes. Recommended values are:
machineMemory=2
diskSize=40
cpuNumber=2
kvm-setup-from-img
Bash script to set up a Linux virtual machine under KVM/QEMU from an existing qcow2 image file.
vclone
Script to clone a virtual machine. The idea is to create a base (or template) image that you want to use and then you can create as many copies of it that you want.
vclone
will remove any temporary files, re-initialize the machine as new, and generate a new MAC address and SSH host keys. It will not remove any ~/.ssh/authorized_keys files that exist in user directories so you can have your SSH keys seeded into the machines.
vclone
relies on the name of the base (template) machine being used in /etc/hosts, /etc/hostname, and /etc/motd. It replaces the base machine name with the new machine name.
Finally, vclone
will print the IPv6 link-local address of the newly-cloned machine. This address can be used in inventory files and ssh/config stanzas like so:
Host master-node
Hostname fe80::3172:00ff:fe86:4103
BindInterface br1
where BindInterface
is the interface on the host that is on the same segment as the virtual machine. Because we're using a link-local address the interface name must be provided to SSH.
get-kvm-link-local
This is a useful script to extract the IPv6 link-local address from a KVM machine using the machine's MAC address.
Put it in /usr/local/bin
or $HOME/bin
Installing KVM/QEMU
For info on setting up KVM/QEMU and the necessary tools on the host machine refer to the Debian Wiki KVM page.
In addition to what is recommended there, it is recommended to also install ovmf
which allows UEFI booting
Here is what I usually use:
apt install --no-install-recommends qemu-system libvirt-clients libvirt-daemon-system ovmf
apt install --no-install-recommends virtinst libguestfs-tools
Don't forget:
usermod -aG libvirt <user>
and re-login or run newgrp libvirt
as the user
osinfo-db
This will make sure that the osinfo database contains the lastest release information for distributions, such as debian12
(or any later versions), which can then be set for the --os-variant virt-install
switch.
This is done with:
git clone https://gitlab.com/libosinfo/osinfo-db.git
apt install gettext osinfo-db-tools libosinfo-bin
cd osinfo-db
make
# this runs osinfo-db-import to import the latest data:
sudo make install
It may also be necessary to run this to fully install the updated db system-wide, replace with the actual version that was built:
sudo osinfo-db-import --root / --system osinfo-db-<version>.tar.xz
# test it:
osinfo-query os