Simple script to create a QEMU
Debian or Ubuntu
Linux .qcow2
disk image using debootstrap
and nbd
.
sudo apt-get install debootstrap qemu-utils util-linux debian-archive-keyring
export FLAVOUR={debian|ubuntu} # default: debian
export ARCH={amd64|...} # default: amd64
export MIRROR=... # default: http://deb.debian.org/debian
export IMGSIZE=... # default: 8G
qemu-debian-create-image debian-test.qcow2 debian-test.hostname stretch
Any additional arguments will be passed through to debootstrap
.
See blog post by Kamil Trzcinski
for more detail. Note that this version of the script will also create
the initial disk image for you (of IMGSIZE
size) so it is nearly fully
automated.
apt-cacher-ng
can be used to reduce the download requirements by
specifying a MIRROR
value like:
http://localhost:3142/us.archive.ubuntu.com/ubuntu/
and with that style of MIRROR
value should allow running offline
providing all packages are
cached.
To do additional setup for a
Vagrant Base Box,
to use with
vagrant-libvirt
you can run the setup-for-vagrant-base-box
script at the end of the
setup with:
export ... # VM flavour, etc, as above
export DISKNAME=vda # vagrant-libvirt assumes /dev/vda
export ETH_DEVICE=ens5 # vagrant-libvirt uses virtio, which ends up slot 5
export EXTRA_SETUP=setup-for-vagrant-base-box
qemu-debian-create-image debian-test.qcow2 debian-test.hostname stretch
and the script referred to by EXTRA_SETUP
will be run at the end, before
unmounting the disk image.
-
Manual procedure designed and documented by Diogo Gomes in a blog post
-
Automated version created by Kamil Trzcinski and released in a blog post under the GPL (GPL version unstated -- assumed to be GPL 2 or later).
-
Several later modifications posted in GitHub gists by:
also assumed to be released under GPL 2 or later.
-
Turned into a git repo by Lucas Nussbaum -- @lnussbaum, with additional changes (also assumed to be released under GPL 2 or later).
-
Other modified versions of original gist (not included in
git
repo, but may have useful ideas):