/qemu-debian-create-image

Simple script to create a QEMU Debian image using debootstrap and nbd

Primary LanguageShellGNU General Public License v2.0GPL-2.0

qemu-debian-create-image

Simple script to create a QEMU Debian or Ubuntu Linux .qcow2 disk image using debootstrap and nbd.

Usage

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.

Vagrant base box

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.

History