\newpage
Virtual machines (VMs) are software emulations of physical computers. They allow you to run multiple operating systems on a single hardware device, providing a flexible and isolated environment for development, testing, and deployment. This chapter explains virtualization, the benefits and drawbacks of VMs, and provides a step-by-step tutorial on setting up a virtual machine using VirtualBox with the latest Ubuntu LTS version (24.04).
A virtual machine is a complete software-based computer that runs on top of a physical host machine. Unlike containers, VMs do not share the host kernel; each VM includes its own operating system kernel.
- Isolation: Each VM operates independently, ensuring stable environments for different applications.
- Flexibility: Run multiple operating systems simultaneously.
- Snapshot Functionality: Save states and revert if needed.
- Security: Isolated environments reduce the risk of system-wide vulnerabilities.
- Resource Intensive: VMs require significant CPU, RAM, and storage.
- Slower Performance: Overheads from virtualized hardware.
- Complexity: Managing multiple VMs can be cumbersome.
VirtualBox is a popular open-source virtualization software that allows you to create and manage VMs.
- Visit the VirtualBox website.
- Download the installer for your operating system (Windows, macOS, or Linux).
- Run the downloaded installer.
- Follow the on-screen instructions, accepting the default settings.
- Launch VirtualBox after installation.
- Visit the Ubuntu downloads page.
- Download the latest Ubuntu 24.04 LTS ISO file.
- Open VirtualBox and click New.
- Enter a name for your VM (e.g., "Ubuntu 24.04").
- Select Linux as the type and Ubuntu (64-bit) as the version.
- Click Next.
- Memory (RAM): Allocate at least 4 GB (4096 MB) for smooth performance.
- Hard Disk:
- Select Create a virtual hard disk now.
- Choose VDI (VirtualBox Disk Image).
- Select Dynamically allocated for storage.
- Allocate at least 25 GB of disk space.
- Select your VM and click Settings.
- Go to the Storage tab.
- Under Controller: IDE, click the empty disk icon.
- Click the disk icon on the right and select Choose a disk file.
- Navigate to and select the downloaded Ubuntu ISO file.
- Click OK.
- Select your VM and click Start.
- Follow the on-screen instructions to install Ubuntu:
- Select your language and click Install Ubuntu.
- Choose Normal installation.
- Follow the prompts to partition the virtual disk and set up your user account.
- Reboot the VM after installation completes.
- Log into your Ubuntu VM.
- Open a terminal and run the following commands:
- Update the package manager:
sudo apt update && sudo apt upgrade -y
- Verify kernel information:
uname -r
- Update the package manager:
- Stop the VM and take a snapshot in VirtualBox.
- Make changes within the VM and revert to the snapshot.
- Ideal for testing new operating systems.
- Create isolated environments for specific projects.
- Develop and test applications in different OS setups.
In this chapter, you learned:
- What virtual machines are and their advantages and disadvantages.
- How to install VirtualBox and create a virtual machine with Ubuntu 24.04.
VMs provide a versatile and secure environment for experimentation and development. In the next chapter, we’ll explore Docker and containerization, which offer lightweight alternatives to virtualization.