Thinking about how best to solve this, maybe you move update-alternatives --install/--remove calls into a start/stop actions service triggered by detection of the appropriate environment, instead of the package postinst/prerm? I think you should be able to do it with a systemd unit that has WantedBy=graphical.target, Before=graphical.target, and ConditionVirtualization=oracle.
That (as long as those alternative links are left on --auto) should yield that VM image can just "do the right thing" based on what hardware it finds itself on, though it would still be a little messy in handling an unclean shutdown (you could start up with stale links still present). Probably not a big deal, since most reasonable use cases are authoring an image customers might launch different hosts, not actually migrating a dirty disk image around.
Thinking about how best to solve this, maybe you move update-alternatives --install/--remove calls into a start/stop actions service triggered by detection of the appropriate environment, instead of the package postinst/prerm? I think you should be able to do it with a systemd unit that has WantedBy= graphical. target, Before= graphical. target, and ConditionVirtua lization= oracle.
That (as long as those alternative links are left on --auto) should yield that VM image can just "do the right thing" based on what hardware it finds itself on, though it would still be a little messy in handling an unclean shutdown (you could start up with stale links still present). Probably not a big deal, since most reasonable use cases are authoring an image customers might launch different hosts, not actually migrating a dirty disk image around.