In this article, we’ll go through the difference between running Linux on a virtual machine and bare metal. We’ll discuss the pros and cons of both approaches.
Finally, we’ll touch on the subject of containerization as an alternative to virtualization.
2. Linux on a Virtual Machine
A virtual machine is system software that imitates the hardware and software of an actual computer system, making it possible to run specific software that would rather not run on our system directly. For instance, a virtual machine will allow us to use a Linux distro without having to install it on the native hardware.
2.1. The Good
A virtual machine is resilient. It allows us to run operating systems that are designed for older hardware. Not only that, but we can also run older operating systems on newer hardware. It can be useful in software testing where we don’t have access to the required hardware. This decreases our expense and effort considerably.
Apart from that, a virtual machine enables us to run multiple Linux distros simultaneously, thereby decreasing the installation and maintenance overhead. So, if we value efficiency and reduced downtime, a virtual environment can prove to be a very reliable choice.
2.2. The Bad
Some virtual machines might lack a few features here and there. For instance, VirtualBox does not support USB 3.0 out of the box. Therefore, we might need to install additional extensions for certain features. Apart from that, we can also encounter issues concerning screen sizes, color depth, incorrect date/time, and hardware acceleration.
For older AMD and Intel CPUs, running a virtual machine might be an issue because a virtual machine depends on a technology called hardware virtualization. Of course, some virtual machines will still run with software virtualization, but the user experience will suffer. Nonetheless, almost all modern CPUs have hardware virtualization support such as Intel-VT and AMD-V.
One more thing to note is that setting up a wireless network on the guest operating system might not be possible since most wireless devices don’t support bridging. However, there are extensions and workarounds to get the wireless interface working.
2.3. The Ugly
Running a Linux operating system in a virtual machine can be painfully slow due to the extra layer of indirection. Although a solid-state drive could certainly help, it will still not be as smooth as running it on bare metal. So, a virtual machine is not an ideal platform for running video games and intensive disk I/O operations.
An operating system running in a virtual machine depends on the host operating system. For that reason, if the host operating system runs into issues, then it will affect the guest operating system as well. Most of the time, issues that affect the guest operating system are related to hardware. For instance, the machine can run out of memory and cause undefined behavior.
3. Linux on Native Hardware
3.1. Hardware Support
Linux on bare metal has the advantage of supporting more hardware. It supports most modern hardware out of the box without having to install third-party drivers. Not only that, but we can downgrade the kernel and firmware to support legacy systems as well. Therefore, we can easily use certain PCI devices that the virtual machine cannot virtualize.
Moreover, virtual machines such as VMWare and Virtualbox limit the creation of virtual volumes to a maximum capacity of 2 TB as opposed to native hardware, where there are no limits.
3.2. Linux Servers
If we were to create a Linux server, we’d install it on bare metal as it allows more freedom, security, and stability. Linux as a server on a virtual machine is totally feasible, but there will be a huge performance hit when it comes to handling requests that are I/O intensive.
3.3. Software Development
Using Linux as our primary development platform can be very rewarding due to the flexible environment and the availability of thousands of open-source software packages. We can configure our environment to our heart’s content through scripting and open-source add-ons.
On the other hand, if we were to develop system software for Linux-based systems, we’d need to test it on Linux running on real hardware. For instance, developing a video game and testing it out on a Linux running in a virtual machine will not behave the same as on Linux running natively on bare metal.
Sometimes, we might need to run multiple servers on a single machine where we need to provide a neat environment for each server. The environment includes basic utilities, dependencies, libraries, executables, and environment variables. So, running multiple servers might have conflicts in the environment, such as one server depending on a newer library than the installed one. For that reason, maintenance becomes costly and time-consuming.
As we saw earlier, a Linux server in a virtual machine is not an optimal solution, let alone multiple Linux servers in multiple virtual machines. To overcome this issue, we can carry out OS-level virtualization through containers.
A container is a user space where the server or the application and its environment reside alongside the required dependencies. The process of packaging the application is known as containerization. In short, containers provide multiple isolated user spaces, while a virtual machine provides a complete operating system. Some popular platforms that provide containerization include Docker, Azure Container Registry, and Podman.
We can run multiple containers on a single Linux machine without having to install multiple virtual machines on the server. Therefore, for service-oriented software, such as microservices, using containers is an effective solution.
5. When to Use What?
As we saw, each approach has different use cases. Let’s briefly go through the most common use cases where each approach makes the most sense.
5.1. Linux on Native Hardware
- Primary desktop operating system
- Server deployment
- Software development and testing
- Gaming and media encoding
- Embedded systems
- Mission-critical systems
5.2. Linux in Virtual Machine
- For testing out a Linux distro
- Using a few software applications specific to a certain Linux-based distro such as Android
- Using older operating systems
- DevOps support for continuous integration and deployment
In this article, we discussed the pros and cons of Linux on virtual machines and bare metal. We saw the different use cases where we can make the best use of both approaches. Afterward, we saw where we could use containers when the virtual machine is not an optimal choice.
Finally, we categorized a few Linux use cases where each approach makes a sensible solution.