Skip to main content

Linux Daily Driver Setup Part 3: VM Control Panel

Now that I have my VMs running, what if I want to switch between them? What if I want to put the VM or the host to sleep, or shut them down?

In this post, I’ll discuss a few options.

Just a quick overview of my setup:

  • Only one VM is running at a time.
  • All VMs have GPU passthrough, and the GPU is connected to a display.
  • I have a secondary display, which I prefer not to use unless absolutely necessary.

See also:

Option 1: Deep Integration with Guest OS

Ideally, I could just click on a “Power off and Switch to VM X” menu from within the guest OS.

This isn’t difficult to support on the host side: the guest OS could pass the VM name to the host (e.g., via a serial port), and the host would automatically start the next VM when the current one exits.

However, I didn’t find an easy way to implement this menu, especially considering I plan to support multiple operating systems. I also couldn’t find a way to prevent the guest from shutting down without providing the next VM’s name.

It sounds like it would require a lot of custom scripting, so I decided to pass on this idea.

Option 2: GPU Rebinding + TTY Menu

I figured the logic had to be implemented on the host side. The idea here is that the host reclaims the GPU when a VM exits.

This requires two steps:

  1. Rebind the GPU from vfio-pci to a “real” driver after a VM exits.
  2. Rebind the GPU from the “real” driver back to vfio-pci before a VM starts.

Step 1 is generally easy because vfio-pci is pretty lightweight, but Step 2 is not, especially for nouveau. I also needed to make sure to disconnect all possible GPU usages (e.g., fbcon), otherwise the driver would likely hang.

In the end, I couldn’t make it stable enough, and I definitely didn’t want to risk hanging the host. Time for a new option.

Option 3: Menu in VM

Since I prefer to stick with the vfio-pci driver, a natural idea was to launch a dedicated VM just for the menu.

The kernel and rootfs could be heavily stripped down to do nothing but show a menu and pass the user’s choice back to the host. It’s a bit of work, but doable.

In practice, however, a minimal VM took about 6 seconds to boot. I managed to pinpoint the bottleneck: GPU initialization. The VM boots much faster without it.

Ultimately, I couldn’t find a good solution. My only finding was that OVMF/UEFI is required to initialize the GPU; without it, the GPU won’t work and the kernel might just hang (the RIP register doesn’t change). Using a dumped or downloaded ROM file didn’t help in my case.

I didn’t bother implementing the menu because the boot delay was just too slow for practical use.

Option 4: Web Server

Another idea was to implement a web server with a simple UI, allowing me to control the host using my phone.

I don’t think it would be difficult to build something that just works, but making it secure enough would be a challenge. Plus, I don’t like that it requires a second device.

Option 5: TTY Menu in Secondary Monitor

Running out of ideas for reusing the primary monitor, I decided to compromise and use the secondary display.

It was straightforward to implement:

  • The menu is built using whiptail.
  • Mask the default getty@tty2 service and run my menu service on TTY2.
  • Use chvt to switch terminals, and setfont to set a huge font size.
  • Write to /sys/module/kernel/parameters/consoleblank to make the screen turn off automatically.
  • The screen turns on automatically when a VM stops, probably due to keyboard/mouse events after evdev passthrough switching.
  • I also added a few options to the menu like “sleep” and “power off”, so I can control the host without having to log in.

In practice, this works really well. It just requires that secondary display.

Thoughts

While Option 5 ended up being the best compromise, I really wish Option 2 or 3 had worked better. That way, the entire setup would work on a single display. Maybe there is a better solution for GPU initialization out there. I’ll probably revisit this later.

Comments

Popular posts from this blog

Exploring Immutable Distros and Declarative Management

My current server setup, based on Debian Stable and Docker, has served me reliably for years. It's stable, familiar, and gets the job done. However, an intriguing article I revisited recently about Fedora CoreOS, rpm-ostree, and OSTree native containers sparked my curiosity and sent me down a rabbit hole exploring alternative approaches to system management. Could there be a better way? Core Goals & Requirements Before diving into new technologies, I wanted to define what "better" means for my use case: The base operating system must update automatically and reliably. Hosted services (applications) should be updatable either automatically or manually, depending on the service. Configuration and data files need to be easy to modify, and crucially, automatically tracked and backed up. Current Setup: Debian Stable + Docker My current infrastructure consists of several servers, all running Debian Stable. System Updates are andled automatically via unattended-upgrades. Se...

A Rocky Migration: Moving from docker-compose to Podman and gVisor

I've been running a few containers for several years. They were all running under rootless Docker with a single user. Initially, I planned to  migrate the containers to VMs , but I couldn't get a stable workflow after about two months of effort. Later,  gVisor caught my attention , and I decided to migrate to Podman with gVisor instead. The new plan is to run each container with  --userns=auto  and use Quadlet for systemd integration. This approach provides better isolation and makes writing firewall rules easier. I'm now close to migrating all my containers. Here are a couple of rough edges I'd like to share. Network Layout I compared  various networking options  and spent a few hours trying the one-interface-per-group approach before giving up. I settled on a single macvlan network and decided to use static IP addresses for my containers. To prevent a randomly assigned IP address from conflicting with a predefined one, I allocated a large IP range for my ...

Determine Perspective Lines With Off-page Vanishing Point

In perspective drawing, a vanishing point represents a group of parallel lines, in other words, a direction. For any point on the paper, if we want a line towards the same direction (in the 3d space), we simply draw a line through it and the vanishing point. But sometimes the vanishing point is too far away, such that it is outside the paper/canvas. In this example, we have a point P and two perspective lines L1 and L2. The vanishing point VP is naturally the intersection of L1 and L2. The task is to draw a line through P and VP, without having VP on the paper. I am aware of a few traditional solutions: 1. Use extra pieces of paper such that we can extend L1 and L2 until we see VP. 2. Draw everything in a smaller scale, such that we can see both P and VP on the paper. Draw the line and scale everything back. 3. Draw a perspective grid using the Brewer Method. #1 and #2 might be quite practical. #3 may not guarantee a solution, unless we can measure distances/p...