Skip to content
  • PC & Mobile
    • Windows
    • Mac
    • Linux
    • Mobile
    • Android
    • iOS
    • Chrome OS
  • Hardware
    • PC Hardware
    • Product Review
    • Smart Home
  • Lifestyle
    • Internet
    • Gaming
    • Productivity
    • How Things Work
    • Glossary
    • News
  • Cheatsheets
  • Deals

Dark mode:

Home > Linux

How to Log Directly Into a VirtualBox Session in Ubuntu

Aaron Peters
Mar 26, 2013

The flexibility of Linux is one of its many benefits. And in particular, one aspect of that flexibility is allowing the user to completely customize his or her computing environment. For example, suppose you’re a stalwart Linux fan (of course you are), but you’re sharing a machine with someone who prefers another OS. You could dual-boot, but then what happens to all the important background processes you have running? Let’s set up your system so that, when this particular user logs in, they’ll go directly to a Virtual Machine running their favorite operating system.

Prerequisites

We’ll be using VirtualBox for this article, but you should be able to adjust the concept if you’re using another VM application (it will just need to have the ability to start a VM from the command-line). The initial steps you’ll need to take are:

  1. Install VirtualBox.
  2. Create a Virtual Machine with your favorite OS installed (MTE has covered installing both Windows and Mac OS X previously).
  3. Start-up your new Virtual Machine and configure to taste.

The Linux Log-in Process

It’s useful to understand a little about how the log-in process works in Linux GUI’s. When the system starts, a display manager will run automatically… this is why nowadays you’re greeted with a nice graphical log-in, rather than a plain old command prompt on start-up. Once you log in, the display manager will start one application or script, which will in turn start a number of other programs, scripts, and processes. For example, in a KDE environment, the display manager doesn’t care about all the background processes – it only needs to run the script “startkde“. The start-up script will remain running as long as you’re using the desktop. Once you exit your desktop (by using an option like “Log Out” or “Restart”), the desktop’s processes will all shut themselves down, and when they’re all done, the start-up script knows it can exit as well. The display manager is waiting in the background, and when the start-up script exits, the display manager takes control and displays your log-in screen again.

Setting Up Your Custom Start-up Script

So, in order to allow a user to log directly into a VM, all we need to do is create a start-up script that will run this VM for them automatically. The first step is to create this script, which is straightforward in Linux. Create a new text file (let’s call it winxp-session), and paste in the following:

#! /bin/bash
 
VirtualBox --startvm [name of the VM you created

winxp-session-script

You can try running the Virtual Box command from the terminal to make sure it works correctly… if not, you probably have the name of the VM misspelled (keep in mind if your VM’s name has spaces, you’ll need to enclose it in single quotes). Next, run the following command in order to make the script executable:

chmod 755 winxp-session

Then you’ll need to copy this file to someplace it can be executed. The “/usr/bin” directory is an option here, as is “/usr/local/bin”. You’ll need to be root to do so for both these locations. To place it in “/usr/bin”, use the following command:

sudo cp winxp-session /usr/bin

The final step is to create a shortcut in the location where the display manager looks for available start-up scripts. In Ubuntu, this is in the “/usr/share/xsessions/” directory. With a text editor, create a new file (as, for example, “/usr/share/xsessions/winxp-session.desktop”):

[Desktop Entry]
Name=Windows XP
Exec=/usr/bin/winxp-session

winxp-session-desktop

Now, if you’re in the desktop, log out. Your new VM-based desktop will be ready for you when the display manager comes up again. Note, however, that this session will only be available for the user who created the VM (since it will only be in that user’s “~/VirtualBox VMs/” directory).

login-shot

Let us know if this is helpful to you, or if you have any question.

Is this article useful?
Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

  • Facebook
  • Tweet

Popular Posts

How to Install macOS in VirtualBox

How to Convert Legacy BIOS to UEFI in Windows

How to Bypass Paywalls of Leading News Websites

Best Android Launchers for Senior and Visually Impaired Users

How to Build and Install a Custom Kernel on Ubuntu

8 of the Best Smartphones for Seniors

9 of the Best Alternatives to Apple's Magic Keyboard

Settings App Not Working in Windows? Here Are the Fixes

PGP Encryption: How It Works and How You Can Get Started

15 Safe Websites for Downloading Windows Software

Affiliate Disclosure: Make Tech Easier may earn commission on products purchased through our links, which supports the work we do for our readers.

Read Next

How to Manage Git in Emacs with Magit
How to Install macOS in VirtualBox
How to Build and Install a Custom Kernel on Ubuntu
The Beginner’s Guide to Git
How to Use Sed in Linux for Basic Shell Tasks
5 Tools to Easily Create a Custom Linux Distro
What Is the Matrix Protocol and How to Install It
Why and How to Edit Your Sudoers File in Linux

© 2022 Uqnic Network Pte Ltd.
All rights reserved.

  • About
  • Contact
  • Advertise
  • Write For Us
  • Terms of Use
  • Privacy Policy
  • RSS Feed Terms
Do not share my Personal Information.