This is a note on running Linux in a VirtualBox.
In 2012 I wrote a note on running Linux in a VirtualBox. There have been a lot of changes since then.
- We have a new president. Donald Trump replaced Barack Obama as the president of the USA;
- I bought a house in a nice neighborhood. When I tried to recommend the one-bed-room apartment where I wrote my first note on Linux to one of my young colleagues, I was shocked that the rent price went to $1030 from $680 in five years, which is effectively more expensive than my mortgage payment now.
But a lot of things remain the same.
- The Newton’s laws remain the same. Even the people who are so interested in re-factoring other people’s already functional programs do not have the incentive to make any changes on Newton’s sentences;
- I am still using one of the computers that I owned by the year 2012. It is a SONY VAIO with an Intel Pentium B940 2.00GHz x 2 CPU and 4GB of memory. I replaced the hard drive with a 100GB SSD which cost me about $30. I also replaced the Windows operating system with Linux. For normal activities, I have confidence that it can outperform a lot of much more expensive new computers that use Windows operating systems.
I am not a rich guy, but I have five computers. Four of them are bought refurbished through Amazon. All of them are running in Linux with three of them are dual-boot systems between Linux and Windows. My wife and I use Linux exclusively in home. Although Linux is my preference, I use Windows at work to bring money back to buy refurbished computers and to buy carrots to feed my stomach. I am not an expert on Linux, but I think that I have practically learned enough to take another note on running Linux in a VirtualBox in 2017.
Why Run Linux in A VirtualBox?
The performance of a Linux system running in a VirtualBox has no match to a natively installed system, but you may still want to run Linux in a VirtualBox in many cases.
- The VirtualBox is a perfect environment for beginners. If you make a mistake, you can delete the VM (virtual machine) and its associated files. You can restart the whole process without any impact on your host computer;
- It is not always trivial to set a dual-boot system. The GRUB is how Linux achieves coexistence with other operating systems. But Microsoft made the effort in some Windows versions with some computer manufacturers to make the GRUB difficult. In some cases, you will have to make a choice between Windows and Linux, but not both;
- The VirtualBox is a perfect test environment. You can test the communications between the VM and the host computer without the effort to setup a network. If you have a powerful computer, you can setup multiple VMs to test the communications among them.
What Do You Need?
To run Linux in a VirtualBox, the computer does not have to be powerful. In 2012, I experimented VirtualBox with a 32-bit Pentium(R) Dual-Core T4200 @ 2.00GHz laptop with 3GB of memory.
- You need a VirtualBox installer that you can download from the VirtualBox website;
- You need to choose a Linux distribution. The popular ones are Ubuntu and Mint. I have played with both. I think that Mint is more visually pleasant, because I use Linux as a desktop operating system. In this note, I will use Mint. But you are free to try Ubuntu, it is a great system and it works perfectly.
I will recommend you to try the most updated stable versions for both VirtualBox and Mint. If your host computer is 64-bit, I will recommend you to use a 64-bit version Linux. I prefer the “cinnamon” flavor Mint, so I chose the “linuxmint-18.2-cinnamon-64bit.iso”. The VirtualBox runs on multiple operating systems. Because you are reading this note, I would assume that your host computer runs on Windows. VirtualBox is very easy to install. You can double click the installer file and follow the instructions to install it.
Although VirtualBox is a powerful VM hosting environment, You can access the most commonly used functionalities through just the three buttons.
- The “New” button allows you to create a VM;
- The “Settings” button allows you to manage the settings of the VM;
- If you want to start the VM, you can click the “Start” button.
Create A VM And Install Linux
Create an Empty VM
Click the “New” button and choose “Expert Mode”, we can start to create a VM.
By default, VirtualBox will allocate 1GB of memory to the VM. If you want better performance, you can add more memory to it.
When you create the VHD (Virtual Hard Drive), I would recommend to choose “Fix size” and set the size to at least 20GB.
After the VM is created, we can make changes to its default settings by clicking on the “Settings” button. In order to have better graphical experience later, I would recommend you to check the “Enable 3D Acceleration”.
Run Linux in Evaluation Mode from ISO
Linux supports a evaluation mode, which allows us to boot the VM directly from the “ISO” file. In order that the VM knows about the “ISO”, we can create a virtual optical drive and associate the “ISO” file to it.
In order that the VM boots from the ISO file, we need to change the boot order of the VM and move “Optical” to the top of the list.
Now you can boot the VM in evaluation mode by clicking the “Start” button. You may see some messages due to misunderstanding between Mint and VirtualBox, but you should see that Linux boots successfully directly from the ISO file.
Install Linux in the VHD
Running Linux directly from the ISO file can give you some feeling about the Linux, but it has very limited capabilities. You need to install Linux to the virtual hard drive to have its full capability.
- You need to make sure the computer is plugged to a power supply;
- You need to make sure your VM has internet access through the host computer. You have access to Firefox in the evaluation mode. You can open the brower and try to access some of the well known websites like “www.google.com” to check if your VM has internet access.
You can then double click the “Install Linux Mint” virtual optical dive to intall Linux to your VHD. The installation process is pretty simple and I would recommend you just take the default options suggested by the installer.
You will need to provide a user name and a password during the installation. You need this UN/PWD pair to login to the Linux. By default, this user is a system administrator of the Linux system. After the installation, you can re-start the VM to let Linxu to boot from your VHD. Depending on the version of the VirtualBox, you may need to change the boot order of the VM to put your VHD to the top of the list. Otherwise, it may keep booting from your ISO file in the evaluation mode.
Install VirtualBox Guest Additions
In order that you can switch smoothly between your guest VM and your host computer, you need to install VirtualBox Guest Additions to the VM. After you start Linux and log into it, click the “Device” menu of the VirtualBox and choose “Insert Guest Additions CD image”.
After you choose the “Insert Guest Additions ….” option, you will be asked if want to run it.
Click the Run button and follow the instructions to install it. During the installation process, you will be asked for a password. It is part of the typical Linux program installation process, you can give the password and proceed with the installation.
Now you have a fully functional Linux VM running in your VirtualBox. Just a quick tip, you can switch your VM to full screen mode back and forth by typing Right CTL + F.
Remove the VM from the VirtualBox
Regardless if you make a mistake or you simply do not want the VM anymore, You can right click the VM in the VirtualBox Manager to remove the VM from the VirtualBox.
When you remove the VM, you have two options. You can choose to remove it from VirtualBox but keep all the files so you can add it back if you need it. You can also choose to remove it and also delete the VM and all the associated files.
From the VirtualBox menu -> File -> Preferences, you can find the location of all the VM files and you can make change to it if you want to.
The Clipboard and Drag & Drop and Shared Folders
It is a big convenience that we can share the clipboard and use drag & drop between the guest and the host computers. But these capabilities are disabled by default. You can enable them through Settings -> General -> and make changes to the dropdown boxes.
You can transfer small files by dragging & dropping. But I noticed that it does not work well for larger files. For larger files, you need to enable a shared folder.
You can go through Settings -> Shared Folders -> and add a shared folder. You can browse to any folder in your host computer and add it as a shared folder. By default you do not automatically have access to the shared folder in the Linux guest. You need to issue the following command to add yourself to the “vboxsf” group to gain access to the shared folder.
sudo usermod -aG vboxsf $(whoami)
The “sudo” command requires you to give your password. After the success run of the command and restart you VM, you should be able transfer files between the guest and the host computers through the shared folder.
Native Linux Installation
It is a nice and pleasant experience to run Linux in a VirtualBox. But sooner or later, you will want to install Linux natively to see how fast Linux is compared with its Windows counterpart. The first step to install Linux is to create a bootable USB drive based on the Linux ISO file that you downloaded earlier.
Create a Bootable USB Drive in Linux
If you already have a Linux machine, you can click on “Menu” -> and search for “USB Image”. You will find that the USB Image Writer is installed in your Linux machine by default.
You can browse to the ISO file and select the USB drive that you want to use and click “Write” button to create the bootable drive.
Create a Bootable USB Drive in Windows
The USB Image Writer is not available in Windows. Typically people download the “UNetbootin” to create the bootable USB drive in Windows. I actually created my first Linux bootable USB by “UNetbootin“. But I noticed that the “UNetbootin” currently does not support the most updated Mint version, so I tried to use the Linux running in the VirtualBox to create the bootable drive in a Windows computer.
In order to use the USB Image Writer in a VirtualBox to create the bootable USB, you need to make the VM to gain access to the USB drive on the host computer. You can plug the USB drive to the host computer and make sure the VM is shutdown. From “Settings” -> USB -> click the “+” button to add the USB to the VM.
After clicking the “+” button, you will be presented the options and you should see the USB drive that you want to use.
After selecting the USB drive and start your VM, the USB drive should be visible in the VM. You can then use the USB Image Writer in your Linux to create the bootable drive.
Stand–alone Linux Installation
It is an easy and pleasant to install Linux natively on your computer. You can plug the USB bootable drive to your computer and restart the computer.
BBBB – A – F12 to change the boot order.
Myths About Linux
There have been many myths about Linux. This link summarized five of them and I am in total agreement with him.
Points of Interest
- This is a note on running Linux in a VirtualBox;
- I hope you like my postings and I hope this note can help you one way or the other.
First Revision – 7/14/2017.