Hi Debian has a couple of tools like fai-diskimage and vmdebootstrap, to build VM images, but they require being root, as these loopmounts partitions on which deboostrap is executed. Maybe installing grub2 needs access to block devices too. I was thinking of using libguestfs to sandbox those processes, by passing a build VM as a disk image and my build directory as a 9pfs mount to the appliance, and calling the build command via $g->shell(). Any pitfalls I should be aware while doing this ? Emmanuel
Richard W.M. Jones
2017-Sep-29 09:48 UTC
Re: [Libguestfs] Using libguestfs to sandbox VM builds
On Thu, Sep 28, 2017 at 06:02:04PM +0200, Emmanuel Kasper wrote:> Hi > Debian has a couple of tools like fai-diskimage and vmdebootstrap, to > build VM images, but they require being root, as these loopmounts > partitions on which deboostrap is executed. Maybe installing grub2 needs > access to block devices too. > > I was thinking of using libguestfs to sandbox those processes, by > passing a build VM as a disk image and my build directory as a 9pfs > mount to the appliance, and calling the build command via $g->shell(). > > Any pitfalls I should be aware while doing this ?In the general case that you want to build bootable disk images, installing them using d-i, you can do that fully non-root using virt-install: https://github.com/libguestfs/libguestfs/blob/stable-1.34/builder/website/debian.sh#L66 You could also use virt-builder (either using our Debian 9 template as a starting point, or your own created in the previous step). Something like: $ virt-builder debian-9 \ --install some,required,packages \ --copy-in test-dir:/var/tmp \ --firstboot-command /var/tmp/test-dir/run-the-tests.sh $ qemu-system-x86_64 \ -nodefaults \ -nographic \ -machine accel=kvm:tcg \ -cpu host \ -m 2048 \ -drive file=debian-9.img,format=raw,if=virtio \ -serial stdio Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html