Kahibaro
Discord Login Register

1.3.4 Installing in a virtual machine

Why Install Linux in a Virtual Machine

Installing Linux in a virtual machine lets you experiment safely inside a window on your existing system. The virtual machine behaves like a separate computer, but it is implemented in software. You can try different distributions, break things while learning, and delete everything with a few clicks, all without changing your main operating system.

Virtual machines are especially useful for beginners who are not yet ready to repartition disks, erase an existing system, or set up dual booting. They are also convenient for trying out multiple Linux environments side by side.

A virtual machine uses your existing hardware resources. If your computer is low on RAM or CPU power, running a virtual machine will feel slow. Do not assign all your RAM or CPU cores to the virtual machine, or your host system will become unstable.

Choosing Virtualization Software

To install Linux in a virtual machine, you need a hypervisor, which is the program that creates and runs virtual machines. On a typical desktop or laptop, you will most often use:

On Windows or macOS, beginners commonly start with VirtualBox or VMware Player / VMware Fusion. On Linux, you can also use VirtualBox, but many distributions provide tools built on KVM such as virt-manager.

When choosing, consider license, ease of installation, and whether there are convenient graphical tools. For basic learning, VirtualBox is usually sufficient and simple to begin with.

Preparing to Create the Virtual Machine

Before creating the virtual machine, you should have:

A Linux installation ISO file, which is the disk image of the installer. You get this by downloading an ISO from your chosen distribution.

A check of your hardware virtualization support. Most modern CPUs support virtualization. In many computers you must enable this feature in BIOS or UEFI settings. Look for settings named Intel VT-x, Intel Virtualization Technology, AMD-V, or similar. If virtualization is disabled, your hypervisor may run very slowly or refuse to start 64-bit guests.

On your host operating system, install your chosen hypervisor using its normal installer. Once installed, you usually get a graphical interface for creating and managing virtual machines.

Creating a New Virtual Machine

The exact appearance of the dialog varies among hypervisors, but the steps are conceptually similar. You define a new virtual machine by specifying a few fundamental properties.

You first choose the name and type. You can name the machine something descriptive, such as Ubuntu-Desktop or Debian-Test. You then select the operating system family as Linux and then pick the approximate version. This helps the hypervisor choose defaults, but it does not change the Linux installer itself.

You then allocate memory. This is a key decision. If your host has, for example, 8 GB of RAM, a common configuration is to give the virtual machine between 2 GB and 4 GB. Too little and Linux will feel sluggish. Too much and your host system may struggle.

A useful basic rule of thumb is:
$$\text{VM RAM} \le \frac{1}{2} \times \text{Host RAM}$$

but you should adjust according to what you will do and how much the host needs.

Next you choose CPUs. Many hypervisors let you assign virtual CPUs that map to host CPU cores or threads. For a typical dual core or quad core laptop, giving the virtual machine 1 or 2 virtual CPUs is usually enough. Avoid assigning all cores to the virtual machine.

Do not assign more CPU cores or more RAM to the virtual machine than your host can spare. Leaving some resources for the host is essential for a responsive system.

Creating a Virtual Disk

Every virtual machine needs its own virtual disk file. This file lives on your host filesystem, but Linux inside the virtual machine sees it as its own hard drive.

When you create the virtual machine, the hypervisor will ask whether you want to create a new virtual disk or use an existing one. For a first install, create a new virtual disk.

You then choose a size. For a simple desktop test system, a virtual disk of 20 GB to 40 GB is usually enough. If you plan to install many programs or keep large files, choose more.

Most hypervisors offer two kinds of virtual disks. One is dynamically allocated, where the file on your host grows as the guest uses more space. The other is preallocated, where the full size file is created immediately. Dynamically allocated disks save host disk space at first, but they can become fragmented over time. For beginners, dynamic allocation is usually fine.

You then select the virtual disk format, such as VDI, VMDK, or QCOW2, depending on the hypervisor. For basic local use, the default choice is acceptable. The format only matters if you plan to move the disk file between different virtualization systems.

Connecting the Installation ISO

Before you can install Linux inside the virtual machine, you must simulate inserting the installation media. Instead of a physical DVD or USB, you attach the ISO file to the virtual machine’s virtual optical drive.

In your hypervisor, you typically open the settings of the virtual machine, go to the storage or CD/DVD section, and select the ISO file as the virtual disk. From the point of view of the virtual machine, this is exactly like having a DVD with the installer inserted.

If you forget to attach the ISO as a virtual CD/DVD, the new virtual machine will often show a “No bootable medium” or similar error when you start it.

Once attached, configure the boot order so that the virtual optical drive comes before the virtual hard disk. This ensures the virtual machine boots from the installer ISO the first time.

Running the Installer inside the VM

With the ISO attached and the virtual machine defined, you start the virtual machine from your hypervisor’s interface. A new window opens, representing the screen of the virtual machine.

Inside this window, you follow the Linux distribution’s normal installer that you would also use on real hardware. The installer does not know that it is running in a virtual machine. It sees a virtual disk, virtual network card, and virtual display as if they were physical devices.

During the installation, when you reach the partitioning step, the installer will only see the virtual disk that you created, not your host disk. This makes installation much safer than installing directly on your hardware. You can follow the partitioning guidance that applies to normal installations, but you are working inside an isolated virtual disk file.

After the installer finishes copying files and configuring the system, it will usually ask you to reboot the virtual machine. At this point, it is important to remove or detach the ISO from the virtual drive, otherwise the virtual machine may boot the installer again instead of your new system.

Post Installation Adjustments in the VM

Once Linux boots from the virtual disk, you can log in and use it as a normal Linux system. However, there are a few virtual machine specific adjustments worth making.

Most hypervisors provide special guest tools. For example, VirtualBox has Guest Additions, VMware has VMware Tools, and KVM based systems can use packages like qemu-guest-agent. These tools improve integration between the host and guest. They usually provide:

Better graphics support and automatic screen resizing when you change the VM window size.

Improved mouse integration so you can move the cursor in and out of the VM window smoothly.

Clipboard sharing between host and guest.

Optional shared folders between host and guest for easy file transfer.

To install these tools, you typically mount a virtual CD from the hypervisor menu inside the running guest and follow the instructions. Some modern distributions already include integration packages or make them available through their package manager.

You can also configure networking. By default, many hypervisors use NAT networking, where the virtual machine shares the host’s connection. For beginner use, NAT is usually enough. Other modes, such as bridged networking or host only, affect how visible the virtual machine is on your local network and can be explored later.

Managing Resources and Snapshots

Over time, you may want to adjust how many resources the virtual machine uses. Most hypervisors let you change RAM, CPU count, and some other parameters while the VM is powered off. If your host system feels slow, you might reduce the RAM or CPUs allocated to the VM. If your guest feels slow and your host is comfortable, you might increase them.

Another important feature of virtual machines is snapshots. A snapshot captures the state of the virtual machine at a point in time, including disk state and sometimes memory. This is very helpful when you are learning. You can create a snapshot before making major changes or experiments, then revert to that snapshot if something goes wrong.

Relying only on snapshots is not a complete backup strategy, but snapshots are very useful for quickly undoing experimental changes inside a virtual machine.

Snapshots are specific to the hypervisor and usually cannot be moved easily between different virtualization systems. Use them mainly to manage risk inside a learning environment.

Benefits and Limitations of Learning in a VM

A virtual machine is excellent for trying commands, installing software, exploring different desktops, and learning system administration concepts. You can create multiple virtual machines with different distributions, experiment with networking between them, and practice installations without touching your real disks.

However, some things behave differently compared to real hardware. For example, direct hardware access, such as graphics drivers for high performance gaming, or power management on laptops, may not be fully representative. Performance in a VM is usually lower, especially for graphics intensive tasks.

Despite these limitations, for most beginners the virtual machine environment provides a safe, flexible, and forgiving way to become comfortable with Linux installation and basic use before moving on to real hardware or more complex setups.

Views: 7

Comments

Please login to add a comment.

Don't have an account? Register now!