scratch is a tool for creating and cleaning up throw-away or "scratch" VMs in a
It aims to require very little of you, while also providing a familiar environment, by using "cloud" VM images from various distros. Currently Debian is supported.
To create a new scratch VM:
$ scratch new IMAGE
IMAGE is the name of a supported image from
scratch tries to guess as many of its configuration options as possible, for instance it will create a user in the VM matching your
$USER if not using
sudo), it will copy the
/etc/resolv.conf and SSH public keys from your host machine in to the VM and it will handle automatically assigning static IPs from a pool, without requiring DHCP.
Additional customisation of the created VM is possible, see the output of
scratch --help and
scratch new --help.
For instance to create a
bullseye VM with the hostname
test and a 10 gigabyte disk:
$ scratch new -L10G -n test bullseye
By default newly created VMs will be added to your host's
/etc/hosts file to make resolving their names easier.
For Debian install required packages:
$ apt install bridge-utils openssh-client genisoimage qemu-utils python3-click python3-guestfs python3-libvirt python3-requests
scratch expects a relatively standard Debian environment:
$HOSTNAME-vg, e.g. if your PC is called
laptopit'll expect a volume group called
laptop-vg. Logical volumes will be created like
hostnameis the name you give a VM.
br-scratchis used, and an IPv4 subnet is selected automatically pased on your PC's hostname, from the
libvirtmanaged bridge and pass
scratchat VM creation time.
For example assuming your automatic subnet is
100.101.36.0/24 (find this from the output of
scratch new --help), this Debian
/etc/network/interfaces fragment will configure the default expected bridge:
auto br-scratch iface br-scratch inet static address 100.101.36.1/24 bridge-ports none bridge-stp off bridge-waitport 0 bridge-fd 0
Currently no configuration mechanism exists to change the default behaviours, but an
alias or wrapper script could be used to supply frequently configured options.
rm command will remove any logical volume that matches the expected name, regardless of whether the VM actually exists. Logical volumes created by
scatch have a specific tag identifying them, and this should be checked at deletion time but currently isn't.
The way the templates are bundled and rendered in the script is a bit gnarly. There are a lot of edge cases to take care of, so some further refining of the
new command will likely take place over time.
Nightly cloud images are used and these are not currently signed. It may be beneficial to migrate to using the less frequently updated images which are signed.