How to boot a virtual machine as the primary desktop from text mode or DM under linux?

1

1

I need to switch between linux distributions every couple weeks. Virtual machines are great for this, but it'd be more convenient to run the virtual machine as my main desktop for a that period of time, rather than starting it from within a running window manager.

I would like to boot into text mode and just run a script that would start the VM-of-the-week in graphics mode. Alternatively, it could be started from the login manager (e.g. lightdm) How can this be done with kvm or VirtualBox? Thanks!

Ellis Whitehead

Posted 2017-02-02T12:33:54.687

Reputation: 111

1How did you try to approach this? Have you looked at the capability of remote xserver sessions? – Seth – 2017-02-02T13:18:12.593

1Thanks for the input @Seth. I've googled occasionally over the last month for "boot vm as desktop" and whatnot; explored using kvm with hardware passthrough, but I didn't figure out how use it on my single-graphics-card system; read about setting up thin clients, but there seem to be too many drawback. I'll look into remote xserver sessions now. – Ellis Whitehead – 2017-02-02T22:44:14.483

Answers

0

Seth's comment about the remote xserver sessions led me in the right direction. VirtualBox can be directly started on its own X session. In the example below, we start an Ubuntu 15.04 image.

From the command line

Create a file named startx_ubuntu1504 (or whatever you want to call it) in your home directory with these contents:

virtualbox --startvm Ubuntu_15.04 --fullscreen

You can then run startx $HOME/startx_ubuntu1504 -- :1 to start the VM.

From the login manager

Create a file named /usr/share/xsessions/vm_ubuntu1504.session with these contents:

[Desktop Entry]
Type=Application
Exec=virtualbox --startvm Ubuntu_15.04 --fullscreen
Name=VM Ubuntu 15.04
Comment=Run VirtualBox image in its own X session

You should then be able to select the X session from your login manager. For example, I'm currently running Xubuntu 2016.10 with the lightdm login manager, and my current login theme has a session dropdown near the upper right corner. This lets me select between any number of virtual machines or my non-virtual desktop. Very cool!

Ellis Whitehead

Posted 2017-02-02T12:33:54.687

Reputation: 111

1

You can start the Virtual Machine headless, in Virtual Box with:

VBoxManage startvm "VM name" --type headless

Once it has started, you connect your xsession into the already open Linux Virtual Box.

Disclaimer: I didn't try it because don't have a box to do it, but the theory says it should be possible.

fernando.reyes

Posted 2017-02-02T12:33:54.687

Reputation: 862

Thanks fernando.reyes; yes, I think that should work. I found something similar that works for directly starting with startx or a login manager, which I posted in my answer. – Ellis Whitehead – 2017-02-04T17:07:00.020