Module 0 · Lesson 2 of 42

Installing Ubuntu three ways

Install Ubuntu 24.04 on WSL2 or in a virtual machine, or set up a safe dual boot, then update the system with apt.

  • Beginner to advanced
  • 9 min read
  • 9 min lab
What you will need

A PC or laptop with at least 8 GB of RAM and about 40 GB of free disk; Windows 10 (2004 or later) or Windows 11, an Intel or Apple Silicon Mac, or an existing Linux machine. Nothing else is required.

Your place in the module
By the end you can 4 objectives
  • Install Ubuntu 24.04 LTS in WSL2 or a virtual machine and update it with apt.
  • Manage packages with apt and sudo, and add your user to the administrator group.
  • Install Ubuntu alongside Windows safely by matching the boot mode and backing up before repartitioning.
  • Choose NAT or bridged networking and enable hardware virtualization for a virtual machine.
Video coming soonInstalling Ubuntu three ways
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Why you need a real Linux machine
  • Systems and embedded C needs Linux: the GNU toolchain, the POSIX API and the target boards all assume it.
  • Linux is the GNU tools plus the Linux kernel, packaged into distributions such as Ubuntu.
  • On Windows use WSL2, on a Mac use a virtual machine, and on Linux use the machine you have.
01

Installing Ubuntu 24.04 on WSL2

4 min read

You have chosen an environment; now you install it. This lesson answers how to install Ubuntu 24.04 on WSL2, in a virtual machine, or as a safe dual boot.

WSL2 is the recommended path on Windows, so this is the longest how-to section. Ubuntu 24.04 LTS, released in April 2024, is the long-term-support release this program standardises on, with five years of updates.

1check you can install it

You need Windows 10 version 2004 (build 19041) or later, or Windows 11, and hardware virtualization enabled in the firmware (the internals section explains why). Open PowerShell or a Windows Terminal as an administrator and run:

powershell
wsl --status

If this prints a version, WSL is already present. If not, proceed.

2install WSL and Ubuntu

powershell
wsl --install

On a current Windows 11 this single command enables the needed Windows features, installs WSL2, and installs the default Ubuntu distribution, then asks you to reboot. After the reboot, a console opens and asks you to create a UNIX username and password. This first user is your everyday account and is automatically added to the sudo group, the administrators.

On some older Windows 10 builds wsl --install only installs WSL without a distribution. In that case pick Ubuntu explicitly:

powershell
wsl --install -d Ubuntu-24.04

To make sure new distributions default to WSL2 rather than the legacy WSL1:

powershell
wsl --set-default-version 2

3update the system

Open the Ubuntu terminal and run the package manager. First refresh the list of available packages, then upgrade what is installed:

bash
sudo apt update
sudo apt upgrade

sudo runs a command as the superuser, because installing software changes the system. You will be asked for your password. This is your first real use of the .

Step by stepHow wsl --install brings up Ubuntu
  1. Enable the platform: Windows turns on the Virtual Machine Platform and WSL features that let a lightweight VM run.

  2. Install the WSL2 kernel: a Microsoft-built Linux kernel is downloaded and registered as the default.

  3. Register a distribution: the Ubuntu root filesystem is installed and associated with a distro name.

  4. First boot: the distribution starts, initialises, and asks you to create a username and password.

  5. You update it: sudo apt update refreshes package lists, then sudo apt upgrade brings installed packages current.

Two practical facts about WSL save a lot of pain. Windows drives are reachable from inside Linux at /mnt/c, and the Linux filesystem is reachable from Windows Explorer at \\wsl$ (or \\wsl.localhost). But crossing that boundary is slow. Building a C project whose source lives in /mnt/c/... can be many times slower than building the same project inside the Linux filesystem, because every file access has to cross between the two worlds through a network-style protocol. Keep your source code in your Linux home directory, not on the Windows side.

WSL1 and WSL2 are different things, and old machines sometimes still have WSL1. WSL1 translated Linux system calls into Windows calls with no real kernel, which broke software that needed low-level features. WSL2 runs a genuine Linux kernel in a VM. Check which version a distribution uses with wsl -l -v; convert with wsl --set-version Ubuntu 2.

WSL1 versus WSL2WSL1WSL2Linux kernelnone,translatessystem callsreal kernelin a VMHow calls worktranslated toNT callsexecuted bythe kernelWindows filesdirect viadrvfsvia 9PprotocolCompatibilitypartialfullStatus todaylegacydefault
A comparison of WSL1, which translates Linux system calls without a kernel, against WSL2, which runs a real Linux kernel inside a lightweight VM.
02

Installing Ubuntu in a virtual machine

3 min read

A VM is the right choice on a Mac, and a good choice on Windows or Linux when you want a full, snapshot-able, disposable machine. The free options are VirtualBox (Windows, Linux, Intel Macs), UTM (macOS, especially Apple Silicon), and VMware Workstation or Fusion.

1enable hardware virtualization

A VM runs at near-native speed only if the CPU's virtualization extensions are on. On Intel CPUs this is VT-x, on AMD it is AMD-V (also called SVM). If it is disabled, most hypervisors refuse to run 64-bit guests or fall back to painfully slow software emulation. Reboot into your BIOS/UEFI firmware, find the setting (often under "CPU configuration" or "Security", sometimes labelled "Intel Virtualization Technology" or "SVM Mode"), enable it, and save. The internals section explains what this switch actually does.

2download the Ubuntu 24.04 ISO

Get the desktop installer image from ubuntu.com. The ISO is the installation medium, the modern equivalent of a DVD.

3create the machine and attach the ISO

In your hypervisor, create a new virtual machine, set it to type Linux / Ubuntu (64-bit), and give it a reasonable slice of your hardware. For the labs in this program, 4 GB of RAM and a 30 GB virtual disk are a comfortable minimum; give it 2 or more CPU cores. Attach the downloaded ISO as the virtual optical drive and start the machine. The Ubuntu installer runs inside the VM, asks for your name, username and password, and installs to the virtual disk.

4install the guest additions and shared folders

After installation, install the hypervisor's guest tools. In VirtualBox this is the Guest Additions, which give you a shared clipboard, better graphics and shared folders; VMware has VMware Tools, UTM has its own guest support. Shared folders let you pass a host directory through to the guest, but, as with WSL2, files that live on the host side and are accessed through a shared folder are slower than files on the guest's own disk. Do your builds inside the guest.

5choose a networking mode

This is the one genuinely tricky setting. The two modes you will meet are NAT, network address translation, where the VM shares the host's IP address for outbound traffic and is hidden behind it, and bridged, where the VM appears as its own device on the physical LAN with its own IP address. NAT is the default and is right for almost everything: the VM reaches the internet through the host, and you reach the VM by forwarding specific ports. Bridged puts the VM on your real network as a peer, which you need later when the VM must be reachable from other devices, for example when serving files to a lab board. Start with NAT; switch to bridged only when a lab needs it.

NAT versus bridged networkingNATBridgedIP addressshares thehost'sits own onthe LANInbound from LANneeds portforwardingdirectlyreachableInternet accessyes, throughhostyes, directlyUse fordefault, mostlabsserving labboards
A comparison of NAT networking, where the VM shares the host IP and is hidden, against bridged networking, where the VM has its own address on the LAN.
Snapshot before you experiment

A VM's single biggest advantage is the snapshot. Take one right after a clean install, and you can roll back to it in seconds after breaking the system with an experiment. Get into the habit of snapshotting before risky changes.

03

Dual boot and a native install, done safely

4 min read

Dual boot is the most native and fastest option, but it is the only one in this lesson that can destroy data, so this section explains the mechanics before the steps. If your machine already runs Linux natively, skip the partitioning and just read the verification sections that follow.

When a computer powers on, firmware starts the boot process. Older machines used a BIOS with the old MBR (master boot record), the legacy partition scheme limited to four primary partitions and 2 TB disks. Modern machines use UEFI firmware with the GPT (GUID partition table), the modern scheme used with UEFI that supports large disks, many partitions and a dedicated boot partition. UEFI boots operating systems from a small FAT32 partition called the EFI System Partition, or ESP. This matters because Ubuntu and Windows must agree on the scheme: if Windows was installed in UEFI mode, Ubuntu must be installed in UEFI mode too.

The program that lets you choose between the two systems is a . Ubuntu uses GRUB 2. The Ubuntu installer detects the existing Windows installation automatically (through a helper called os-prober) and adds a GRUB menu entry for it, and it respects Secure Boot by installing a signed shim, so you can usually leave Secure Boot enabled. After installation, GRUB is the menu you see at startup; the boot order and whether Windows or Ubuntu is the default can be changed in GRUB or in the firmware settings.

The boot path is: power on, firmware starts, GRUB loads from the EFI System Partition, and your choice at the menu starts either Ubuntu or Windows.

  • states: [{"id": "off", "label": "Powered off"}, {"id": "firmware", "label": "Firmware (UEFI or BIOS)"}, {"id": "bootloader", "label": "Bootloader (GRUB menu)"}, {"id": "ubuntu", "label": "Ubuntu running"}, {"id": "windows", "label": "Windows running"}]
  • transitions: [{"from": "off", "to": "firmware", "event": "power on"}, {"from": "firmware", "to": "bootloader", "event": "load GRUB from the ESP"}, {"from": "bootloader", "to": "ubuntu", "event": "choose Ubuntu"}, {"from": "bootloader", "to": "windows", "event": "choose Windows"}, {"from": "ubuntu", "to": "off", "event": "shut down"}, {"from": "windows", "to": "off", "event": "shut down"}]

The risky part is making room. You shrink the Windows partition to free space, then create the Linux partitions in that space. Shrinking is safe in principle, but a power cut or a filesystem error mid-resize can corrupt data, which is why a full backup first is non-negotiable. The Ubuntu installer offers an "install alongside Windows" option that does the shrinking and partitioning for you; that is the safest route. If you prefer, shrink from inside Windows using Disk Management first, then reboot, then let the installer use the free space.

A GPT disk with two systemshighEFI System PartitionFAT32, boot loadersWindows (C:)NTFSfree spacecreated by shrinkingLinux rootext4lowLinux swaphighEFI System PartitionFAT32, boot loadersWindows (C:)NTFSfree spacecreated by shrinkingLinux rootext4lowLinux swap
A GPT disk layout with the EFI System Partition at the top, the Windows partition, the freed space, and the Linux root and swap partitions created in that space.
Repartitioning can destroy data

Back up everything you cannot afford to lose before shrinking a partition or installing a second operating system. A backup is not optional here. Never interrupt a resize operation, and make sure the machine is on mains power for the whole install.

A native install on a Linux-only machine needs none of this: the installer owns the whole disk, and there is no boot menu conflict to manage. If you are already on Linux, you are ahead of the game.

Going deeperWhy the boot mode must match

Windows and Ubuntu both offer a UEFI path and a legacy BIOS path, and the two must agree. The tell is the partition table: a Windows installed on a GPT disk boots in UEFI mode, while one on an MBR disk boots in legacy mode. If you install Ubuntu in UEFI mode next to a legacy-mode Windows, GRUB may not be able to chain-load Windows, and you will have to switch boot modes in the firmware each time. The practical rule is to install Ubuntu in the same mode as Windows. You can check which mode a running system booted in: on Ubuntu the directory /sys/firmware/efi exists only when the machine booted via UEFI, and Windows reports it under System Information as BIOS or UEFI. When they match, one GRUB menu lists both systems cleanly.

Key takeaways

  • Keep your source code inside the Linux filesystem, not /mnt/c, or every build crawls.
  • A VM gives a full machine and snapshots, but it needs hardware virtualization (VT-x or AMD-V) enabled in firmware.
  • Dual boot is the fastest native option but the riskiest, so back up before you repartition.
Reflect
  1. Explain to a colleague, in two sentences: install Ubuntu 24.04 LTS in WSL2 or a virtual machine and update it with apt.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close