Virtual Machines (OCR A-Level Computer Science): Revision Notes
📚 Revision Notes
Virtual Machines
Overview
A virtual machine (VM) is a software-based emulation of a physical computer, allowing a system to operate as though it were an independent machine. VMs can run different operating systems, execute programmes in isolated environments, and even run intermediate code. They are highly versatile, with applications ranging from software testing to running incompatible OSs on a single physical computer. Understanding virtual machines provides insight into how computers can share resources efficiently and how software can create versatile, isolated environments within physical machines.
What Is a Virtual Machine?
- Definition: A virtual machine is software that emulates the functions of a physical computer, allowing it to run an operating system and applications as if it were a separate device.
- Role: VMs are used to create isolated environments, execute programmes independently, and optimise resources by running multiple OSs on a single physical computer.
- Types of Virtual Machines:
- System Virtual Machines: Emulate an entire operating system, allowing users to run one OS inside another (e.g., running Windows on a Mac).
- Process Virtual Machines: Create a virtual environment for running applications, such as intermediate code, without emulating an entire OS (e.g., the Java Virtual Machine).
Uses of Virtual Machines
Running an Operating System Within Another
- Purpose: Allows multiple OSs to run simultaneously on a single physical machine. For example, a VM can host a Linux OS on a Windows machine, enabling cross-platform compatibility.
- How It Works: A hypervisor (or VM manager) is used to create and manage virtual machines on a host system. The hypervisor allocates CPU, memory, and storage resources from the physical machine to each VM, creating a self-contained environment.
- Benefits:
- Resource Optimisation: Multiple VMs can share the resources of a single physical machine, increasing efficiency.
- Isolation: Each VM operates independently, reducing the risk of one VM affecting others or the host.
- Cross-Platform Compatibility: VMs allow users to access applications and features of different OSs without needing separate physical machines.
- Drawbacks:
- Performance Overhead: Running multiple VMs can slow down the host system, as resources are shared.
- Resource Limits: Each VM competes for the host's resources (CPU, memory), limiting the performance available for each VM.
Executing Intermediate Code
- Purpose: VMs can be used to run intermediate code (code that is not directly executed by the OS) in a platform-independent environment. This is common with languages like Java, where intermediate bytecode runs on the Java Virtual Machine (JVM).
- How It Works: Intermediate code is compiled from source code to a universal format that is not hardware-specific (e.g., Java bytecode). The VM interprets or compiles this code on demand, making it executable on any system with the appropriate VM installed.
- Benefits:
- Platform Independence: Intermediate code can be run on any machine with the relevant VM, supporting portability.
- Security and Isolation: VMs provide a controlled environment, reducing the risk of damaging the host or interfering with other programmes.
- Drawbacks:
- Performance: Running intermediate code on a VM can be slower than running compiled native code directly on the hardware.
- Additional Software Dependency: The need for an installed VM can add complexity, as users must install the correct VM for the intermediate code (e.g., the JVM for Java).
Examples of Virtual Machines
Operating System Virtualisation
- A software developer using macOS needs to test a Windows-only application.
- By running a VM with Windows as the guest OS, the developer can test the application without needing a separate physical machine.
Executing Intermediate Code
- A Java application is compiled into bytecode, which is not specific to any OS.
- The bytecode is then executed on the Java Virtual Machine (JVM), making it possible to run the same Java application on any device with a JVM, regardless of the underlying OS.
Benefits of Virtual Machines
| Benefit | Description |
|---|---|
| Cross-Platform Compatibility | VMs allow for running different OSs on a single machine, making it easier to use software from different platforms. |
| Isolation and Security | VMs create isolated environments, minimising the risk of cross-contamination between systems or applications. |
| Resource Optimisation | VMs enable multiple OSs to share hardware resources efficiently, reducing the need for multiple physical systems. |
| Ease of Testing | VMs allow testing of different OSs and configurations without needing separate devices, ideal for development. |
Drawbacks of Virtual Machines
| Drawback | Description |
|---|---|
| Performance Overhead | VMs may slow down the host system due to resource sharing and virtualisation overhead. |
| Complexity and Setup Time | Installing, configuring, and managing VMs can be complex, especially in environments with multiple VMs. |
| Increased Resource Usage | Each VM requires CPU, memory, and storage, which can strain the physical system if not managed effectively. |
| Dependency on VM Software | Running intermediate code requires a specific VM (e.g., JVM), which may need maintenance and compatibility checks. |
Note Summary
infoNote
Common Mistakes
- Confusing VMs with Emulators: VMs simulate a complete OS environment within a host, while emulators replicate specific hardware to run software not intended for the host system.
- Assuming VMs Have No Impact on Performance: VMs share hardware resources with the host, so running multiple VMs or demanding tasks within a VM can impact the overall system performance.
- Forgetting to Consider Compatibility: Some applications or peripherals may not work within a VM due to hardware or software limitations, which can limit usability.
infoNote
Key Takeaways
- Definition of Virtual Machine: A software-based emulation of a physical computer that enables isolated OSs or applications to run within a host system.
- Uses:
- Running Multiple OSs: VMs allow different OSs to operate on a single physical machine, enabling cross-platform compatibility and resource sharing.
- Executing Intermediate Code: VMs, such as the JVM, enable platform-independent execution of intermediate code, enhancing portability.
- Benefits: VMs provide isolation, security, and cross-platform compatibility while maximising resource use.
- Drawbacks: VMs can reduce performance due to resource sharing and may require specific configurations, adding complexity.