[[!tag debian]]
Some months ago I wished for a tool to create virtual disk
images, something similar to debootstrap
except
it would create a disk image instead of a directory. It would
be used like this:
sudo ./vmdebootstrap --image test.img --size 1G \
--log test.log --mirror http://mirror.lan/debian/
debootstrap
is wonderful for creating a basic Debian system
for use with chroot
. In the modern world, something similar
but for virtual machines (such as KVM) would be nice to have,
I thought. Particularly if it is something that is not tied to
a particular virtualization technology, and does not require
running in an actual virtual machine (for speed and simplicity).
I could imagine using a tool like this for automatically building appliance-like system images, for example for FreedomBox. Being able to do that in a fully automatic manner would make development simpler and more easy for others to reproduce, and would allow for things like automatic integration testing: build image, boot it in a virtual machine, run automatic tests, report results.
There are a bunch of tools that almost do this, but not quite.
For example, live-build
builds a disk image, but it's one that
is aimed for live CDs and such. This brings in some limitations.
By default, the image is not persistent. You can make a persistent
image, but that requires you to provide a second partition (or disk)
that holds the modified parts, using copy-on-write. It also means
that if the bootloader or initramfs needs to be updated, then the
read-only image needs to be updated. That's fine for live CDs,
but not so good if you want a real installed system that you can
upgrade to all future releases of Debian. (Ben Armstrong
kindly helped me use live-build
the right way. Thanks!)
There's also grml-debootstrap
which seems to work on a real system,
but not installing onto a virtual disk image (and the difference
is crucial to me).
Based on feedback I received back then, and some experimentation I've done the past couple of days, I wrote a very rudimentary version of the tool I want. The code is on gitorius. (You need my cliapp library to run it.)
Be warned: it really is a very rudimentary version. For example, it provides not flexibility in choice of partitioning, filesystem type, what packages get installed, etc. It does not configure networking, and the root password is disabled. Some of that flexibility would be quite easy to add.
It also uses extlinux
as the bootloader, since I utterly failed
to get grub2
to install onto the virtual disk. (I did, however,
manage to overwrite my develpment machine's bootloader.)
The command above works, and results in a RAW format disk image that boots under KVM. It might boot off a hard disk or USB flashdrive too, but I haven't tried that.
I now have several questions:
- Does something like this already exist?
- Does anyone else find this useful?
- Is another approach better? Perhaps running a fully preseeded debian-installer in a virtual machine might be better.
- If no other tool exists for the same job, what should I do next with vmdebootstrap?