Installing Linux

Why This Matters

You cannot learn Linux from a book alone. You need a running system where you can break things, fix them, break them again, and gradually build confidence. The first real step on that path is installation.

The good news: installing Linux has never been easier. You do not need to wipe your existing operating system. You do not need dedicated hardware. You have at least five different ways to get a working Linux environment, ranging from "takes five minutes, no risk" to "full bare-metal installation." This chapter covers them all.

By the end of this chapter, you will have a working Linux system ready for every exercise in this book.


Try This Right Now

If you are on Windows 10/11, you can have a working Linux system in under five minutes:

# Open PowerShell as Administrator and run:
wsl --install

That single command installs WSL2 with Ubuntu. After a reboot, you will have a full Linux environment. If you already did this, try:

wsl --status

If you are on macOS or already run Linux, skip ahead to the VM section or the bare-metal section.


Installation Options Overview

Here are your options, from simplest to most involved:

┌─────────────────────────────────────────────────────────┐
│              Installation Options                        │
│                                                          │
│  Option              Risk Level    Time     Best For     │
│  ─────────────────────────────────────────────────────   │
│  WSL2 (Windows)      None          5 min    Learning,    │
│                                              dev work    │
│                                                          │
│  Cloud Instance       None          5 min    Server      │
│  (AWS/GCP/etc.)                              skills      │
│                                                          │
│  Virtual Machine      None          30 min   Full        │
│  (VirtualBox/QEMU)                           experience  │
│                                                          │
│  Live USB             None          10 min   Testing     │
│  (no install)                                hardware    │
│                                                          │
│  Dual Boot            Medium        45 min   Daily use   │
│                                              + Windows   │
│                                                          │
│  Bare Metal           High          30 min   Full        │
│  (replace OS)                                commitment  │
│                                                          │
└─────────────────────────────────────────────────────────┘

For this book, any of these options works. A VM or WSL2 is recommended because you can take snapshots, experiment freely, and destroy and rebuild your environment without consequence.


Option 1: WSL2 on Windows

Windows Subsystem for Linux 2 (WSL2) runs a real Linux kernel inside a lightweight virtual machine managed by Windows. It is not emulation -- it is genuine Linux.

Prerequisites

  • Windows 10 version 2004 or later (Build 19041+) or Windows 11
  • Hardware virtualization enabled in BIOS (usually enabled by default)
  • At least 4 GB RAM (8 GB recommended)

Step-by-Step Installation

Step 1: Enable WSL

Open PowerShell as Administrator:

wsl --install

This command:

  • Enables the WSL feature
  • Enables the Virtual Machine Platform
  • Downloads and installs the Linux kernel
  • Sets WSL2 as the default version
  • Installs Ubuntu as the default distribution

Step 2: Reboot

# After the command completes:
Restart-Computer

Step 3: First Launch

After reboot, Ubuntu will launch automatically (or find it in the Start menu). You will be prompted to create a username and password:

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: yourname
New password:
Retype new password:
passwd: password updated successfully
Installation successful!

Warning: This username and password are for Linux only. They are separate from your Windows login. Choose a short username with no spaces. You will type this password often -- make it something you can remember.

Step 4: Verify

$ uname -a
Linux DESKTOP-ABC123 5.15.153.1-microsoft-standard-WSL2 #1 SMP x86_64 GNU/Linux

$ cat /etc/os-release | head -3
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"

$ echo "Hello from Linux!"
Hello from Linux!

You now have a working Linux system.

Installing Additional Distributions in WSL2

# List available distributions
wsl --list --online

# Install a specific one
wsl --install -d Debian
wsl --install -d Fedora

# List your installed distributions
wsl --list --verbose

WSL2 Tips

  • Access Windows files from Linux: They are at /mnt/c/, /mnt/d/, etc.
  • Access Linux files from Windows: In Explorer, type \\wsl$ in the address bar
  • Run Linux commands from PowerShell: wsl ls -la /home
  • Run Windows commands from Linux: /mnt/c/Windows/System32/notepad.exe
  • Keep your Linux files in the Linux filesystem (under /home/yourname), not on /mnt/c/. The Linux filesystem is much faster for Linux operations.

WSL2 Limitations

WSL2 is excellent for learning and development, but has some limitations:

  • No systemd by default (though it can be enabled in recent versions)
  • No direct hardware access (USB passthrough requires extra tools)
  • Networking is bridged through Windows
  • Not suitable for testing boot processes, kernel modules, or hardware interaction

For these topics, use a virtual machine instead.

Distro Note: WSL2 defaults to Ubuntu, but you can install Debian, Fedora, openSUSE, Kali, Alpine, and others. Check wsl --list --online for the current list.


Option 2: Virtual Machine with VirtualBox

A virtual machine (VM) gives you a complete, isolated Linux system with full control. You can take snapshots, experiment with boot configurations, and even simulate hardware failures.

Prerequisites

  • Any operating system (Windows, macOS, or Linux) as the host
  • At least 8 GB RAM (to give 2-4 GB to the VM)
  • At least 25 GB free disk space
  • VirtualBox downloaded from virtualbox.org

Note: VirtualBox is open source (GPLv2). Other options include GNOME Boxes (Linux), QEMU/KVM (Linux, covered below), and VMware Workstation Player (free for personal use but not open source).

Step 1: Download the Linux ISO

Go to your chosen distribution's website and download the installation ISO:

For this walkthrough, we use Ubuntu Server 22.04 LTS.

Step 2: Create the Virtual Machine

  1. Open VirtualBox and click New

  2. Configure:

    • Name: ubuntu-lab
    • Type: Linux
    • Version: Ubuntu (64-bit)
    • Memory: 2048 MB (2 GB) minimum, 4096 MB recommended
    • Hard disk: Create a virtual hard disk now
    • Disk size: 25 GB (dynamically allocated)
    • Disk type: VDI (VirtualBox Disk Image)
  3. Before starting, go to Settings:

    • System > Processor: 2 CPUs
    • Network > Adapter 1: NAT (for internet) or Bridged Adapter (for network visibility)
    • Storage: Under "Controller: IDE," click the empty disk icon, then select "Choose a disk file" and point to your downloaded ISO

Step 3: Install Ubuntu Server

Start the VM. You will boot from the ISO into the Ubuntu installer.

  1. Language: English
  2. Keyboard layout: Your keyboard layout
  3. Installation type: Ubuntu Server
  4. Network: The installer auto-detects. Accept defaults
  5. Storage/Partitioning: Use the entire disk (guided). The installer will suggest:
  /dev/sda  25 GB
  ├── /dev/sda1   1 GB   /boot/efi  (EFI System Partition)
  ├── /dev/sda2   1.7 GB /boot      (boot partition)
  └── /dev/sda3   22 GB  / (root)   (main partition, ext4)

Accept the defaults for now. We will cover partitioning in depth in Chapter 7.

  1. Profile setup:

    • Your name: Your Name
    • Server name: ubuntu-lab
    • Username: yourname
    • Password: choose something memorable
  2. SSH Setup: Check "Install OpenSSH server" -- you will need this

  3. Featured snaps: Skip all of these for now

  4. Wait for installation to complete, then select Reboot Now

Step 4: First Boot

After reboot, you will see a login prompt:

ubuntu-lab login: yourname
Password:
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-91-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Jan 15 10:30:00 UTC 2024

  System load:  0.08              Processes:             112
  Usage of /:   18.2% of 21.5GB  Users logged in:       0
  Memory usage: 12%               IPv4 address for eth0: 10.0.2.15
  Swap usage:   0%

yourname@ubuntu-lab:~$

You are in.

Step 5: Take a Snapshot

Before doing anything else, take a snapshot in VirtualBox. This gives you a known-good state you can revert to at any time:

  1. In VirtualBox Manager, select your VM
  2. Click Snapshots (top right)
  3. Click Take (camera icon)
  4. Name it "fresh-install"

Warning: Always take a snapshot before experimenting with anything potentially destructive. This is your safety net. You can restore to any snapshot in seconds.


Option 3: QEMU/KVM (Linux Host)

If your host system already runs Linux, QEMU/KVM is the preferred virtualization solution. It is fully open source and offers near-native performance.

Install QEMU/KVM

# Debian/Ubuntu
$ sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients \
    bridge-utils virt-manager

# Fedora
$ sudo dnf install @virtualization

# Arch
$ sudo pacman -S qemu-full libvirt virt-manager dnsmasq

Verify KVM Support

$ lscpu | grep Virtualization
Virtualization:                  VT-x

$ ls /dev/kvm
/dev/kvm

If /dev/kvm exists, you have hardware virtualization support.

Create a VM with virt-manager (GUI)

  1. Launch virt-manager
  2. Click Create a new virtual machine
  3. Select Local install media (ISO)
  4. Browse to your downloaded ISO
  5. Allocate 2 GB RAM, 2 CPUs
  6. Create a 25 GB disk
  7. Name your VM and click Finish

Create a VM from the Command Line

# Create a disk image
$ qemu-img create -f qcow2 ubuntu-lab.qcow2 25G

# Boot from ISO to install
$ qemu-system-x86_64 \
    -enable-kvm \
    -m 2048 \
    -smp 2 \
    -hda ubuntu-lab.qcow2 \
    -cdrom ubuntu-22.04-live-server-amd64.iso \
    -boot d \
    -net nic -net user,hostfwd=tcp::2222-:22

# After installation, boot without ISO
$ qemu-system-x86_64 \
    -enable-kvm \
    -m 2048 \
    -smp 2 \
    -hda ubuntu-lab.qcow2 \
    -net nic -net user,hostfwd=tcp::2222-:22

The hostfwd option forwards port 2222 on your host to port 22 on the VM, so you can SSH in:

$ ssh -p 2222 yourname@localhost

Option 4: Cloud Instance

If you have an account with any cloud provider, you can launch a Linux instance in minutes.

AWS (Free Tier)

# Using the AWS CLI
$ aws ec2 run-instances \
    --image-id ami-0c7217cdde317cfec \
    --instance-type t2.micro \
    --key-name your-keypair \
    --security-group-ids sg-xxxxx

# SSH in
$ ssh -i your-key.pem ubuntu@<public-ip>

DigitalOcean, Linode, Vultr

These providers offer $5-10/month VMs with one-click Linux provisioning. Many offer free credits for new accounts. The setup is typically:

  1. Create an account
  2. Create a "Droplet" / "Linode" / "Instance"
  3. Choose Ubuntu 22.04 LTS
  4. Choose the smallest size
  5. Add your SSH key
  6. SSH in

This approach is excellent for practicing remote server administration, which is how you will manage Linux servers in the real world.


Option 5: Live USB (Try Without Installing)

A Live USB lets you boot a full Linux system from a USB drive without touching your hard disk. This is great for testing hardware compatibility before committing to an installation.

Create a Live USB

What you need:

  • A USB drive (4 GB minimum, 8 GB recommended)
  • A Linux ISO (Ubuntu Desktop is best for this)
  • A tool to write the ISO to USB

Warning: Writing an ISO to a USB drive will ERASE ALL DATA on that drive. Back up any files on the USB before proceeding.

On Linux:

# Identify your USB drive (CAREFULLY -- do not pick the wrong device!)
$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 256.0G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi
└─sda2   8:2    0 255.5G  0 part /
sdb      8:16   1   7.5G  0 disk          <-- This is the USB drive

# Write the ISO (replace /dev/sdb with YOUR USB device)
$ sudo dd if=ubuntu-22.04-desktop-amd64.iso of=/dev/sdb bs=4M status=progress
$ sync

Warning: The dd command is sometimes called "disk destroyer" for good reason. If you specify the wrong of= target, you will overwrite your hard disk. Triple-check the device name with lsblk before running dd.

On Windows:

Use Rufus (rufus.ie) -- a free, open-source tool:

  1. Download and run Rufus
  2. Select your USB drive
  3. Select the ISO file
  4. Click Start

On macOS:

Use balenaEtcher (balena.io/etcher) -- also free and open source.

Boot from USB

  1. Insert the USB drive
  2. Reboot your computer
  3. Enter the boot menu (usually F12, F2, Esc, or Del during startup -- varies by manufacturer)
  4. Select the USB drive
  5. Choose "Try Ubuntu" (or equivalent) to boot without installing

Option 6: Bare Metal Installation

Installing Linux as the sole operating system on a computer gives you the best performance and full hardware access. This is ideal if you have a spare laptop or desktop.

Warning: Installing Linux on bare metal will ERASE your existing operating system and all data on the target disk (unless you set up dual boot). Back up everything first.

The process is the same as a VM install, but booting from a USB drive on real hardware:

  1. Create a Live USB (see above)
  2. Boot from USB
  3. Choose "Install Ubuntu" instead of "Try Ubuntu"
  4. Follow the installer (same steps as the VM walkthrough above)
  5. When asked about disk partitioning, "Erase disk and install" is the simplest option

Understanding Partitioning Basics

During installation, you encounter disk partitioning. Here is what you need to know now (Chapter 7 goes deep).

What Is a Partition?

A partition divides a physical disk into logical sections. Each partition can have its own filesystem and purpose.

Common Partition Layouts

Simple (recommended for learning):

┌──────────────────────────────────────────────┐
│  /dev/sda                                     │
│                                               │
│  ┌────────┬──────────────────────────────┐    │
│  │ sda1   │ sda2                         │    │
│  │ /boot  │ / (root)                     │    │
│  │ ~1 GB  │ remaining space              │    │
│  │ (EFI)  │ (ext4 filesystem)            │    │
│  └────────┴──────────────────────────────┘    │
└──────────────────────────────────────────────┘

Production server (typical):

┌──────────────────────────────────────────────┐
│  /dev/sda                                     │
│                                               │
│  ┌──────┬──────┬────────┬────────┬────────┐  │
│  │ sda1 │ sda2 │ sda3   │ sda4   │ sda5   │  │
│  │/boot │ /    │ /home  │ /var   │ swap   │  │
│  │512MB │ 20GB │ 50GB   │ 20GB   │ 4GB    │  │
│  │(EFI) │      │        │(logs)  │        │  │
│  └──────┴──────┴────────┴────────┴────────┘  │
└──────────────────────────────────────────────┘

Why separate partitions?

  • /boot or /boot/efi -- keeps boot files on a simple filesystem the bootloader can read
  • / (root) -- the core operating system
  • /home -- user files (separate so you can reinstall the OS without losing your data)
  • /var -- logs and variable data (separate so a full disk from runaway logs does not crash the OS)
  • swap -- virtual memory space (used when RAM is full)

For a learning VM, the simple layout is perfect. Accept the installer's defaults.

Filesystem Types

The installer will ask about filesystem types. The short answer: use ext4. It is the default, well-tested, and reliable.

FilesystemUse Case
ext4Default for most Linux installs. Reliable, mature
XFSDefault on RHEL/Rocky. Good for large files
BtrfsAdvanced features (snapshots, compression). Default on Fedora, openSUSE
ZFSAdvanced features, from the Solaris world. Popular on NAS systems

Think About It: Why might you put /var/log on a separate partition from /? What happens if log files fill up all available disk space on the root partition?


Post-Install First Steps

You have a running Linux system. Now what? Run through these steps to make sure everything is working and up to date.

Step 1: Update Your System

The very first thing to do on any new Linux install is update all packages:

# Debian/Ubuntu
$ sudo apt update && sudo apt upgrade -y

# Fedora/RHEL/Rocky
$ sudo dnf upgrade -y

# Arch
$ sudo pacman -Syu

Distro Note: apt update refreshes the package list (what is available). apt upgrade installs newer versions. These are two separate steps on Debian/Ubuntu. On Fedora, dnf upgrade does both. On Arch, pacman -Syu does both.

Step 2: Check Networking

# Do you have an IP address?
$ ip addr show
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP>
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0

# Can you reach the internet?
$ ping -c 3 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=12.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=11.8 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=117 time=12.1 ms

# Can DNS resolution work?
$ ping -c 3 google.com
PING google.com (142.250.80.46) 56(84) bytes of data.
64 bytes from lax17s64-in-f14.1e100.net: icmp_seq=1 ttl=117 time=12.5 ms

If ping 8.8.8.8 works but ping google.com does not, you have a DNS problem. Check /etc/resolv.conf.

Step 3: Install Essential Tools

# Debian/Ubuntu
$ sudo apt install -y curl wget vim git htop tree net-tools

# Fedora/RHEL/Rocky
$ sudo dnf install -y curl wget vim git htop tree net-tools

# Arch
$ sudo pacman -S curl wget vim git htop tree net-tools

These are tools you will use throughout this book.

Step 4: Check Disk Space

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        22G  4.2G   17G  21% /
/dev/sda1       512M  5.3M  507M   2% /boot/efi
tmpfs           994M     0  994M   0% /dev/shm

Make sure you have plenty of space available on /.

Step 5: Verify Your User Can Use sudo

$ sudo whoami
root

If this returns root, your user has sudo privileges. If it returns an error, you need to add your user to the sudo group:

# This requires logging in as root first
# Debian/Ubuntu
$ su -
# usermod -aG sudo yourname

# Fedora/RHEL/Rocky
$ su -
# usermod -aG wheel yourname

Distro Note: The sudo group is called sudo on Debian/Ubuntu and wheel on Fedora/RHEL. Same concept, different name.

Step 6: Set Your Timezone

# Check current timezone
$ timedatectl
               Local time: Mon 2024-01-15 10:45:00 UTC
           Universal time: Mon 2024-01-15 10:45:00 UTC
                 RTC time: Mon 2024-01-15 10:45:00
                Time zone: Etc/UTC (UTC, +0000)

# List available timezones
$ timedatectl list-timezones | grep America
America/Chicago
America/Denver
America/Los_Angeles
America/New_York
...

# Set your timezone
$ sudo timedatectl set-timezone America/New_York

# Verify
$ date
Mon Jan 15 05:45:00 EST 2024

Verifying Your Installation: A Checklist

Run through this checklist to confirm your system is ready for the rest of this book:

# 1. Kernel is running
$ uname -r
6.1.0-18-amd64

# 2. You know your distribution
$ cat /etc/os-release | grep PRETTY_NAME
PRETTY_NAME="Ubuntu 22.04.3 LTS"

# 3. Networking works
$ curl -s ifconfig.me
203.0.113.42

# 4. Package manager works
$ apt list --installed 2>/dev/null | wc -l    # Debian/Ubuntu
587

# 5. sudo works
$ sudo echo "I have sudo access"
I have sudo access

# 6. Disk space is sufficient
$ df -h / | awk 'NR==2 {print "Available:", $4}'
Available: 17G

# 7. Memory is sufficient
$ free -h | awk '/Mem:/ {print "Available:", $7}'
Available: 1.5Gi

# 8. Essential tools are installed
$ which bash curl vim git ssh
/usr/bin/bash
/usr/bin/curl
/usr/bin/vim
/usr/bin/git
/usr/bin/ssh

If all of these pass, you are ready.


Debug This

You installed Ubuntu in a VM. You can log in at the console, but when you try to SSH from your host machine, it does not connect:

$ ssh yourname@10.0.2.15
ssh: connect to host 10.0.2.15 port 22: Connection refused

What could be wrong? Work through these possibilities:

Click to see the diagnosis

Check 1: Is SSH installed and running on the VM?

# On the VM console
$ systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
     Active: active (running)

If SSH is not installed: sudo apt install openssh-server If SSH is not running: sudo systemctl start ssh

Check 2: Is the VM network configured for access from the host?

VirtualBox NAT mode (the default) gives the VM a private IP (10.0.2.x) that the host cannot reach directly. You have two options:

Option A: Port forwarding (with NAT) In VirtualBox: Settings > Network > Advanced > Port Forwarding Add a rule: Host Port 2222 -> Guest Port 22 Then connect with: ssh -p 2222 yourname@localhost

Option B: Bridged networking In VirtualBox: Settings > Network > Attached to: Bridged Adapter The VM will get an IP on your local network, and you can SSH to it directly.

Check 3: Is a firewall blocking port 22?

$ sudo ufw status
Status: active
...

If the firewall is active and SSH is not allowed:

$ sudo ufw allow ssh

The most common cause for new users is the NAT networking issue. VirtualBox NAT gives the VM internet access but does not allow incoming connections from the host without port forwarding.


What Just Happened?

┌─────────────────────────────────────────────────────┐
│                                                      │
│  In this chapter, you:                               │
│                                                      │
│  - Learned 6 ways to run Linux: WSL2, VirtualBox,    │
│    QEMU/KVM, cloud instance, live USB, bare metal.   │
│                                                      │
│  - Set up WSL2 on Windows with a single command      │
│    (wsl --install).                                   │
│                                                      │
│  - Created a VirtualBox VM with Ubuntu Server,       │
│    walked through the installer step by step.         │
│                                                      │
│  - Learned partitioning basics: /, /boot, /home,     │
│    /var, swap -- and why separate partitions matter.  │
│                                                      │
│  - Completed post-install setup: updated packages,   │
│    verified networking, installed essential tools,    │
│    set timezone, confirmed sudo access.              │
│                                                      │
│  - Ran a verification checklist to confirm your      │
│    system is ready for the rest of this book.         │
│                                                      │
│  Commands you met: wsl, apt update, apt upgrade,     │
│  ip addr, ping, curl, df, free, timedatectl,         │
│  systemctl, ufw, dd, lsblk, sudo                    │
│                                                      │
└─────────────────────────────────────────────────────┘

Try This

Exercises

  1. Installation exercise: Install Linux using at least one method from this chapter. If you are on Windows, start with WSL2. If you want the full experience, create a VirtualBox VM.

  2. Snapshot exercise (VM users): Take a snapshot of your fresh install. Then intentionally break something (delete /etc/hostname, for example). Restore the snapshot and verify everything is back to normal.

  3. Post-install exercise: Run through every step in the "Post-Install First Steps" section. Record the output of each command. Compare with a classmate or colleague -- are your outputs different? Why?

  4. Partitioning exercise: Run lsblk and df -h on your system. Draw a diagram of your disk layout similar to the ASCII diagrams in this chapter. What partitions exist? What filesystem does each use?

  5. Multi-distro exercise: If you have VirtualBox or Docker, install a second distribution (e.g., if you installed Ubuntu, try Fedora). Run through the same post-install steps. Note every command that differs.

Bonus Challenge

Install Arch Linux in a virtual machine following the official Arch Installation Guide on the Arch Wiki. This is a rite of passage for Linux enthusiasts. The Arch installer gives you nothing -- no GUI, no automation. You will manually partition disks, install the base system, configure the bootloader, and set up networking. It is difficult, educational, and deeply satisfying when it works.


What's Next

You have a running Linux system. You are staring at a blinking cursor. What now? Chapter 4 introduces the shell -- the interface between you and the full power of Linux. This is where the real journey begins.