initial commit
This commit is contained in:
commit
de0e6a360c
1 changed files with 111 additions and 0 deletions
111
README.md
Executable file
111
README.md
Executable file
|
@ -0,0 +1,111 @@
|
|||
# KVM Scripts
|
||||
|
||||
A collection of scripts useful for creating KVM/QEMU virtual machines
|
||||
|
||||
|
||||
## mmdebstrap
|
||||
|
||||
### mmdebstrap-deb12
|
||||
|
||||
Script to create systemd-container using mmdebstrap
|
||||
|
||||
Recommended to use the [current mmdebstrap](https://github.com/deepin-community/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.
|
||||
```bash
|
||||
# create container named 'deb12-1'
|
||||
./mmdebstrap-deb12 deb12-1
|
||||
# start the container
|
||||
sudo machinectl start deb12-1
|
||||
# access the container
|
||||
ssh deb12-1
|
||||
```
|
||||
|
||||
## KVM
|
||||
|
||||
### 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:
|
||||
```bash
|
||||
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:
|
||||
```sshconfig
|
||||
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](https://wiki.debian.org/KVM).
|
||||
|
||||
In addition to what is recommended there, it is recommended to also install `ovmf` which allows UEFI booting
|
||||
|
||||
Here is what I usually use:
|
||||
```bash
|
||||
apt install --no-install-recommends qemu-system libvirt-clients libvirt-daemon-system ovmf
|
||||
apt install --no-install-recommends virtinst libguestfs-tools
|
||||
```
|
||||
Don't forget:
|
||||
```bash
|
||||
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:
|
||||
```bash
|
||||
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 <version> with the actual version that was built:
|
||||
```bash
|
||||
sudo osinfo-db-import --root / --system osinfo-db-<version>.tar.xz
|
||||
|
||||
# test it:
|
||||
osinfo-query os
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue