How to recover a suspended fdroidserver VM that was halted

As a contributor I need to enter the VM rather often, since most recipes that I need to build have failed using the usual simple steps or the CI can’t handle some cases.

Hence I’ve edited fdroidserver/fdroidserver/ and replaced destroy with suspend around here so at the end of the build the VM can still be used. I can enter it to tweak/test the steps of the recipe or analyze the dependency tree or search/extract for an APK that was not found automatically, etc.

The trouble is that even if the VM was suspended there’s a chance (afaics bigger if the VM runs for longer or is left in suspended state longer) that the VM will refuse to restart. Same behaviour as if I’ve halted it manually.

Trying to start it:

$ cd ~/fdroiddata/builder
$ vagrant halt ; vagrant up ; vagrant ssh
==> default: Halting domain...
Bringing machine 'default' up with 'libvirt' provider...
==> default: Starting domain.
==> default: Waiting for domain to get an IP address...
==> default: Waiting for SSH to become available...
==> default: Creating shared folders metadata...
==> default: Halting domain...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
sed -i '/#VAGRANT-BEGIN/,/#VAGRANT-END/d' /etc/fstab
Stdout from the command:
Stderr from the command:
==> default: Domain is not suspended.
==> default: Domain is not running. Please run `vagrant up` or `vagrant resume` first.

Which command failed? Hmm, let’s debug this vagrant up --debug

DEBUG ssh: stderr: bash: sudo: command not found

…ah, as expected, we nuke sudo after the first steps.

At @jspricke advice, “you could mount the image and install sudo again”

So let’s do this them, looks easy enough:

sudo modprobe nbd max_part=8
sudo qemu-nbd --connect=/dev/nbd0 /var/lib/libvirt/images/builder_default.img (adapt to yours as needed)
sudo mount /dev/nbd0p1 /mnt/
sudo su   (so we don't mess perms later just in case)
mc   (so we don't deal with unzipping and messed perms) mc from .deb copy CONTENTS/* to /mnt/
echo 'vagrant ALL = NOPASSWD: ALL' > /mnt/etc/sudoers.d/vagrant 
chmod 440 /mnt/etc/sudoers.d/vagrant 
sudo umount /mnt/
sudo qemu-nbd --disconnect /dev/nbd0
sudo rmmod nbd

Now redo vagrant up ; vagrant ssh and you end up logged as needed.

1 Like