Run Linux on Windows 10 with VirtualBox
Why Linux? Why VirtualBox?
As I grew more comfortable with the command line and tools such as Vim, Linux felt like a natural progression to using these more without the speed bumps that I would often encounter when developing on Windows.
Although Windows now offers the Windows Subsystem for Linux (WSL), at the time of writing this was relatively new.
I decided on running a Linux distribution within a VirtualBox environment as a means of evaluating features, ease of use and whether I would actually use it before I committed to dual-booting.
This post serves as a reference and guide for how I achieved this. For reference, my environment consisted of:
- Windows 10, as the host operating system (OS);
- Linux Mint Cinnamon, as the guest OS; and
- Oracle VirtualBox 6.0 as the virtual machine manager.
Setting up a Linux virtual machine
Enable hardware virtualisation
If you want to run a 64-bit guest OS on your host OS (even if the host OS is 32-bit) you will need to ensure that your motherboard has hardware virtualisation enabled.
This is necessary to allow for a 64-bit instance of Linux to be installed through VirtualBox, as described in the VirtualBox documentation.
For Intel motherboards, this option is referred to as Intel Virtualisation Technology (Intel VT-x). For AMD motherboards, this is known as AMD Secure Virtual Machine (AMD SVM).
If your motherboard does not support hardware virtualisation, you will only be able to install the 32-bit instance of your chosen guest OS.
Install VirtualBox and download a Linux distribution
Download and install VirtualBox, and then download the distribution of your choice. I downloaded the latest Linux Mint ISO. The 64-bit version should be fine.
Create a new virtual machine
To create a virtual machine in VirtualBox, perform the following steps:
- Select Machine > New... in the VirtualBox menu and use the following settings:
- Name: (the distribution name);
- Type: Linux; and
- Version: Other Linux (64-bit).
- Set the allocated memory to 2048MB, i.e. 2GB;
- Select the Create a virtual hard disk now option and:
- Select VDI (VirtualBox Disk Image) and proceed;
- Select Fixed Size and proceed; and
- Specify the location of the hard disk file and set the file size to 20GB. Check the distribution for minimum size requirements.
Install Linux to the virtual machine
With a virtual machine set up, Linux can be installed on it. Select the virtual machine and open the settings via Machine > Settings in the VirtualBox menu.
In the dialog that displays, select Storage. There should be two storage devices available by default, listed under a Controller: IDE item:
- the virtual disk image (with a
*.vdi
extension); and - an optical drive, which should currently be labelled Empty.
Select the optical drive and, under the attributes, load the Linux ISO downloaded in the earlier step.
Now start the virtual machine and wait for Linux to load.
The desktop will be displayed and, in the case of Linux Mint, there should be an Install Linux Mint icon. Run it and select the following options as they appear, modifying to suit your needs. Below are the choices I selected for the Linux Mint installation:
- Select English as the language;
- Select English (US) as the keyboard layout;
- Leave the Install third-party software… unchecked;
- Select Erase disk and install Linux Mint as the installation method;
- Set the timezone location; and
- Set the computer details, including username and password.
Wait for Linux to install and then shut down the virtual machine via the operating system.
Resolve Linux Mint's "Running in software rendering mode" notification
A message may display every time Linux Mint is loaded that says the following:
To correct this, open the virtual machine's settings and, under Display, check the Enable 3D Acceleration option.
Install VirtualBox guest additions
VirtualBox provides useful host to guest OS integrations such as a bidirectional clipboard, shared folders and dynamic window resizing.
With the virtual machine running, select Devices > Insert Guest Additions CD image… from the menu of the virtual machine's window.
Click Run on the box that pops up or double click the CD icon that appears on the desktop. Enter a password if required. A terminal should display, which will log the installation progress.
Once installed, shut down the virtual machine. VirtualBox will keep this drive inserted so if you wish to remove it you can do so by opening the settings of the virtual machine, going to Storage, selecting the VBoxGuestAdditions.iso item and selecting Remove Disk from Virtual Drive on the dropdown that displays when clicking the blue CD icon.
A useful feature to enable is the bidirectional clipboard. This is found in the virtual machine's settings, under General in the Advanced tab. Set Shared Clipboard to Bidrectional. Now both the host OS (e.g. Windows 10) and guest OS (e.g. Linux Mint) will read and write to the same clipboard.
Add folder sharing between the host and guest OS
Having a point where both the host and guest OS files systems are connected makes moving documents between the two easier.
With the virtual machine running, open the settings for the virtual machine in VirtualBox and, under Shared Folders, click the Add shared folder icon. Use the following settings in the dialog box that appears:
- Folder Path: use the folder path for the folder to share between the host and guest;
- Folder Name: choose a name for the folder, which will be displayed in Linux Mint and be referenced in a startup command;
- Leave Read-only unchecked;
- Leave Auto-mount unchecked; and
- Leave Mount point empty.
After confirming the settings, the shared folder can be mounted with the following commands:
$ mkdir /home/<username>/<folder-name>
$ sudo mount -t vboxsf -o rw,uid=<username>,gid=<username> /home/<username>/<folder-name>/
These commands:
- make the directory on the guest before mounting; then
- mount the directory to create a link between the host and guest OS.
To automatically mount the shared folder on start up, edit /etc/group
and add
your username to the end of the vboxsf
line:
vboxsf:x:999:<username>
Then add the following line to /etc/fstab
:
<folder-name> /home/<username>/<folder-name> vboxsf rw,uid=<username>,gid=<username> 0 0
Enable port forwarding to access localhost
from guest to host
It can be useful to share access to localhost
from the guest to the host if
the guest is being used for web development.
With the virtual machine powered down, open its settings and go to Network. On the Adapter 2 tab, check Enable Network Adapter and set Attached to: as Host-only Adapter.
Save the changes and start the virtual machine. All that is left is to set up a port forwarding rule. To do this, the IP address of the Host-only adapter is needed.
In Linux, open a terminal and run ifconfig
. There should be three results from
ifconfig
. The Host-only adapter IP address will typically look like
192.*.*.*
.
Copy this IP address and, back in the virtual machine's network settings, select the Adapter 1 tab (which should be set as Attached to: NAT) and expand the Advanced options toggle to reveal the Port forwarding button.
Open the port forwarding dialog and add a new rule with the following details:
- Name: Guest-to-host localhost
- Protocol: TCP
- Host IP:
127.0.0.1
- Host Port:
1313
- Guest IP:
192.*.*.*
- Guest Port:
1313
This rule will tell the virtual machine that any server running on Linux Mint
bound to the IP and port of 192.*.*.*:1313
will be port forwarded and
accessible on Windows at localhost:1313
.
Confirming that port forwarding works
The best way to confirm that the port forwarding works is to use the npm package
http-server
, which will require Node.js (this is beyond the scope of this
tutorial):
$ npx http-server -a 192.*.*.*
…where 192.*.*.*
is the host-only adapter address retrieved from
ifconfig
.
The -a
flag is specifying the address to bind the HTTP server to; any HTTP
servers running on the guest OS will need to be bound to the 192.*.*.*
address
for the localhost
port forwarding to work.
With http-server
running, open localhost:8080
in the host OS. The content
will be port forwarded from the guest to host and served accordingly.
Works cited
"How to Install Linux Mint in VirtualBox (Step by Step with Images)." Stugon, Stugon, 16 June 2017, https://www.stugon.com/linux-mint-virtualbox/. Accessed 6 June 2019.
Venkatesh, Nitin. "Accessing your Virtualbox Guest from your Host OS." 2buntu, 8 November 2014, https://2buntu.com/articles/1513/accessing-your-virtualbox-guest-from-your-host-os/. Accessed 6 June 2019.
duDE. "Why does virtualbox only have 32-bit option, no 64-bit option on Windows 7?" Super User, Stack Exchange, https://superuser.com/questions/866962/why-does-virtualbox-only-have-32-bit-option-no-64-bit-option-on-windows-7/866963#866963. Accessed 6 June 2019.