2

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!

2
  • 1
    How did you try to approach this? Have you looked at the capability of remote xserver sessions?
    – Seth
    Commented Feb 2, 2017 at 13:18
  • 1
    Thanks 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. Commented Feb 2, 2017 at 22:44

2 Answers 2

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.

1
  • 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. Commented Feb 4, 2017 at 17:07
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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .