Chapter 02Lesson 02~50 minutes

Installing Linux in a Virtual Machine

A virtual machine gives this course a complete Linux system with its own kernel, boot sequence, disks, services, and network interfaces—while snapshots keep experiments recoverable. The goal is not merely to finish an installer; it is to create a documented laboratory.

BeginnerVirtualizationHands-on lab

Learning objectives

By the end of this lesson

  • Explain the isolation and fidelity advantages of a full virtual machine.
  • Verify installation media before booting it.
  • Choose CPU, memory, disk, firmware, and network settings appropriate for the host.
  • Install a minimal Linux server safely and create a non-root administrative user.
  • Validate the resulting guest and capture a clean baseline for later snapshots.

1. Why a virtual machine is the primary lab

A VM virtualizes enough hardware to boot a complete guest operating system. Unlike a container shell, it has its own kernel, PID 1, virtual disks, network devices, bootloader, and service lifecycle. That fidelity is required for later lessons on systemd, storage, boot recovery, firewalls, and kernel interfaces.

Isolation

Experiments stay inside the guest

Filesystem and service changes do not normally modify the host operating system.

Fidelity

Complete system behavior

The guest boots, mounts filesystems, manages services, and exposes realistic network interfaces.

Recovery

Snapshots and clones

A known-good checkpoint makes risky exercises repeatable without reinstalling from zero.

2. Understand the virtualization layers

A hosted Linux laboratory
flowchart TB
  H["Physical host hardware"] --> HV["Hypervisor or virtualization platform"]
  HV --> VM["Virtual CPU, memory, disk, firmware, and network"]
  VM --> K["Guest Linux kernel"]
  K --> US["Guest user space and services"]
  US --> LAB["DevOps Academy labs"]
  SNAP["Snapshot or clone"] -. captures .-> VM

VirtualBox, VMware Workstation/Fusion, Hyper-V, KVM/QEMU, and other platforms expose different interfaces, but the design choices are similar. Use a platform supported by your host and avoid running multiple competing hypervisors unless you understand their compatibility constraints.

3. Host preflight and resource sizing

ResourceStarting pointReasoning
vCPU2 virtual CPUsEnough for package operations and services without consuming the whole host
Memory2–4 GiBSuitable for a server lab; increase for containers or Kubernetes later
Disk30–50 GiB dynamically allocatedLeaves room for packages, logs, container images, and snapshots
FirmwareUEFI when supportedRepresents modern systems; keep the setting consistent after installation
NetworkNAT initiallyProvides outbound access while limiting direct exposure from the LAN
Leave capacity for the host

Do not assign every CPU core or most of the host’s memory to the guest. Resource starvation makes both systems unstable and teaches the wrong performance lesson.

4. Download and verify installation media

Use the distribution’s official download page and retrieve its published checksum. Verifying the ISO detects corruption and helps confirm that the file matches the release publisher’s manifest.

# Run on a Linux or WSL host after downloading the ISO and checksum file.
cd "$HOME/Downloads"

# Replace these example names with the actual downloaded files.
iso="linux-server.iso"
checksums="SHA256SUMS"

sha256sum "$iso"
grep "$(basename "$iso")" "$checksums"

# When the checksum file uses sha256sum-compatible lines:
sha256sum --check --ignore-missing "$checksums"

A checksum alone does not establish publisher identity if an attacker can replace both the ISO and checksum file. For higher assurance, follow the distribution’s documented signature-verification procedure using its official signing key.

5. Select the network mode deliberately

Default

NAT

The guest reaches external networks through the host. Inbound access usually requires explicit port forwarding.

Local access

Host-only

The host and guest communicate on an isolated virtual network, often without internet access unless a second adapter is added.

LAN presence

Bridged

The guest appears as another machine on the physical network. This is useful but increases exposure and depends on network policy.

Multi-node labs

Internal network

Guests communicate with each other on a private virtual segment, useful for clusters and routing exercises.

For the first installation, use NAT. Later, add a host-only adapter when you need stable host-to-guest SSH without exposing the VM to the entire LAN.

6. Installation plan

01Create the VM

Name it clearly, select the correct architecture, allocate resources, and attach the verified ISO.

02Boot the installer

Choose the intended language, keyboard, time zone, and network behavior.

03Partition the virtual disk

For the first lab, guided partitioning is acceptable because the disk is disposable. Confirm the target disk before writing.

04Create an administrative user

Use a normal account with sudo access rather than enabling routine direct root login.

05Select a minimal server profile

Install SSH server support when offered; avoid unnecessary desktop packages unless they serve a specific learning need.

06Reboot and detach the ISO

Ensure the guest boots from its virtual disk rather than restarting the installer.

7. First boot: update, identify, and validate

Run the appropriate update commands for the chosen family. Read the package transaction before confirming it.

# Identify the distribution first.
cat /etc/os-release

# Debian/Ubuntu family
if command -v apt-get >/dev/null 2>&1; then
  sudo apt-get update
  sudo apt-get upgrade
fi

# Fedora/Rocky/AlmaLinux family
if command -v dnf >/dev/null 2>&1; then
  sudo dnf upgrade --refresh
fi

# Validate the complete guest.
printf '\n=== boot and init ===\n'
who -b
ps -p 1 -o pid,comm,args
systemctl is-system-running || true

printf '\n=== identity and network ===\n'
hostnamectl 2>/dev/null || hostname
ip -brief address
ip route

printf '\n=== storage ===\n'
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
findmnt -D

timedatectl status 2>/dev/null || date

If the upgrade installs a new kernel, reboot before creating the baseline snapshot, then confirm the running kernel with uname -r.

8. Optional host-to-guest SSH access

SSH makes copy-and-paste, file transfer, and automation easier. Confirm the server is installed and running inside the guest, then connect through a host-only address or a NAT port-forward configured in the hypervisor.

# Inside the guest
systemctl status ssh 2>/dev/null || systemctl status sshd
ss -lnt | grep ':22 '

# From another machine after confirming the guest address and firewall policy
ssh your_user@guest_address

# Record the host key fingerprint after first connection
ssh-keygen -F guest_address
Never expose password SSH casually

Bridged networking can place the guest on the physical LAN. Use strong authentication, apply updates, understand the firewall, and later move to key-based access.

9. Hands-on lab: create a machine baseline report

Capture the exact VM state that will define the clean checkpoint for Chapter 2.

lab="$HOME/devops-academy/linux/chapter02/lesson02"
mkdir -p "$lab"
cd "$lab"

{
  printf '=== distribution ===\n'
  cat /etc/os-release

  printf '\n=== kernel and architecture ===\n'
  uname -a

  printf '\n=== virtualization ===\n'
  systemd-detect-virt 2>/dev/null || true

  printf '\n=== boot and services ===\n'
  who -b
  ps -p 1 -o pid,comm,args
  systemctl --failed --no-pager 2>/dev/null || true

  printf '\n=== network ===\n'
  ip -brief address
  ip route

  printf '\n=== storage ===\n'
  lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
  df -hT

  printf '\n=== updates ===\n'
  if command -v apt >/dev/null 2>&1; then
    apt list --upgradable 2>/dev/null || true
  elif command -v dnf >/dev/null 2>&1; then
    dnf check-update 2>/dev/null || true
  fi
} > vm-baseline-report.txt

less vm-baseline-report.txt

Verification checklist

10. Common installation mistakes

Skipping ISO verification

Corrupted media can produce subtle installation failures. Verify before troubleshooting the guest.

Using bridged networking by default

It exposes the guest more broadly than necessary and can violate local network policy.

Allocating excessive host resources

A VM that starves the host creates unstable behavior and unreliable performance observations.

Taking the baseline snapshot too early

First apply updates, reboot when necessary, confirm networking and time, and collect the baseline report.

11. Knowledge check

Question 1. Why does a VM teach more of this course than a container shell?

Question 2. Why is NAT the recommended first network mode?

Question 3. When should the first clean snapshot be created?

12. Summary

A useful VM lab is verified, deliberately sized, minimally exposed, fully updated, and documented. NAT is the safest initial network mode; a normal sudo-capable user is preferable to routine root login; and the first snapshot should represent a tested baseline rather than an unfinished installation.

Next lesson

Using WSL for Linux Practice on Windows

You will compare WSL with a conventional VM, install and inspect WSL 2, choose correct file locations, and define which course labs belong in WSL versus a full guest.

13. Further reading

  • Your selected distribution’s official installation guide and release notes.
  • The hypervisor vendor’s documentation for virtual networking, snapshots, and guest integration.
  • Linux manual pages for lsblk, findmnt, ip, ssh, and systemd-detect-virt.
  • Distribution security documentation for update channels and installation-media verification.
  • OpenSSH documentation — host keys, client trust, and secure remote administration.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0 Send only Ethereum/ERC-20 compatible assets to this address.