Module 0 · Lesson 3 of 42

How your Linux machine runs, and checking it

Explain how WSL2, hypervisors, and containers run a Linux system, then verify, configure, snapshot, and start using the shell on your install.

  • Beginner to advanced
  • 11 min read
  • 35 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
  • Verify the install with uname, /etc/os-release, nproc, free -h, df -h and lscpu, and confirm a 64-bit kernel.
  • Configure the hostname, timezone and locale, and generate an Ed25519 SSH key.
  • Diagnose the common failures: virtualization disabled in firmware, WSL1 instead of WSL2, disk pressure and clock drift.
  • Explain how a hypervisor and a container each run Linux, and where WSL2 and Docker fit among them.
Video coming soonHow your Linux machine runs, and checking it
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Installing Ubuntu three ways
  • 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.
01

How WSL2 and hypervisors actually work

4 min read

You have installed Ubuntu; now confirm it really works and understand what runs underneath. This lesson answers how WSL2, hypervisors and containers run your system, and how to verify it and start the shell.

Understanding what is really running under you pays off every time something is slow or refuses to start, so this section opens the hood.

A is the program that makes virtual machines possible. It comes in two kinds. A type-1 hypervisor runs directly on the hardware, like Microsoft's Hyper-V or the Linux KVM. A type-2 hypervisor runs as an application inside a host operating system, like VirtualBox or VMware Workstation. The hardware extensions you enabled, VT-x or AMD-V, are what let a hypervisor run guest code safely and at speed: without them, the hypervisor has to emulate instructions in software, which is dramatically slower and is why 64-bit guests are refused when virtualization is off.

WSL2 is, concretely, a type-1 setup: it runs a Microsoft-built Linux kernel inside a small Hyper-V virtual machine called the utility VM. This is the key difference from WSL1, which had no kernel at all. The Linux distribution's files live on an ext4 filesystem stored in a virtual disk file, the ext4.vhdx. For distributions installed from the Microsoft Store it lives under %LOCALAPPDATA%\Packages\<distro>\LocalState\; distributions installed by newer versions of wsl --install keep it under %LOCALAPPDATA%\wsl\{GUID}\. wsl -l -v lists them, and Windows Explorer shows the files under \\wsl.localhost\. When you ask Windows to talk to Linux, it does so through a 9P protocol connection into the VM, and when Linux touches /mnt/c it goes back out the same way. That round trip is exactly why cross-filesystem access is slow and why native Linux files are fast.

You control this machine through two files. /etc/wsl.conf inside the distribution configures that one distribution (for example whether it auto-mounts Windows drives). %UserProfile%\.wslconfig configures WSL globally, and this is where you set memory and CPU limits and reclaim behaviour:

ini
[wsl2]
memory=8GB
processors=4
swap=4GB
autoMemoryReclaim=gradual

On older WSL releases autoMemoryReclaim lived under an [experimental] section; run wsl --version and check the Microsoft WSL configuration page for the release you have.

Because the whole distribution is one disk file, you can back it up and move it with two commands. Export snapshots the current state to a tarball, and import recreates a distribution from one:

powershell
wsl --export Ubuntu C:\backups\ubuntu-2026-11.tar
wsl --import Ubuntu-New C:\wsl\Ubuntu-New C:\backups\ubuntu-2026-11.tar

This is the WSL equivalent of a VM snapshot, and it is your cheap insurance before a risky experiment.

Inside WSL2Windowshost operating systemHyper-Vtype-1 hypervisorUtility VMLinux kernelext4 vhdxthe distro disk file9P bridges Windows and the VMWindowshost operating systemHyper-Vtype-1 hypervisorUtility VMLinux kernelext4 vhdxthe distro disk file9P bridges Windows and the VM
The WSL2 architecture: Windows on the host, the Hyper-V hypervisor below it, and the utility VM running the Linux kernel with the ext4 vhdx disk, connected by the 9P protocol.
Going deeper9P, drvfs and why /mnt/c is slow

Both WSL versions mount Windows drives with a component called drvfs, but it works very differently. In WSL1 there was no Linux kernel, so drvfs translated each file operation directly into a Windows call. In WSL2 the Linux kernel is inside a separate VM, so a direct call is impossible: drvfs mounts /mnt/c over 9P, the Plan 9 file protocol, carried across a Hyper-V socket to a file server on the Windows host, which then does the real disk I/O. It is fast enough for occasional copies, but every single stat, open and read during a compile pays the round-trip cost, and a build with thousands of small source files becomes many times slower. That is the whole reason for the rule: keep projects inside the Linux filesystem. You can see this in Linux with mount | grep /mnt/c, which shows the Windows drive mounted as type 9p, while / is type ext4.

02

Containers and reproducible toolchains

3 min read

Containers are the third big idea from the history section, and they matter for this program because later modules use them for reproducible build environments. They are lighter than a VM because they share the host kernel.

A Docker is a template, and a is a running instance of that template. An image is like a class, a container like an object. Images are built in layers and stored read-only; when you start a container, Docker adds a thin writable layer on top, so the image itself never changes.

To run Ubuntu tooling in a container you pull an official image and run a shell in it:

bash
docker pull ubuntu:24.04
docker run -it ubuntu:24.04 bash

The -it attaches your terminal so you can type. The crucial flag for development is -v, which bind-mounts a directory on your host into the container, so files you edit outside are visible inside:

bash
docker run -it -v "$HOME/project":/work ubuntu:24.04 bash

Now /work inside the container is ~/project on the host, and changes made on either side are visible on the other. This is how you keep your source on your own disk while building it in a clean, reproducible environment.

The trade-off that matters: a container shares the host kernel, so it cannot run a different kernel, and it is not a full machine. But because the entire environment is declared in the image, a toolchain built in a container behaves the same on every machine and every colleague's machine, which is why build servers and CI systems are built on containers. For this program, the container is a complement to WSL2 or a VM, not a replacement for your main development environment.

Docker image versus containerImageContainerWhat it isread-onlytemplaterunninginstancePersistenceimmutable,layeredhas awritablelayerLifecyclebuilt andstoredstarted andstoppedSharingshared as abaseisolated perinstance
A comparison of a Docker image, a read-only layered template, against a container, a running instance with an added writable layer.
03

Verify, configure and snapshot your system

5 min read

Whatever route you took, the first thing to do is prove the environment is what you think it is. Run these and read the output:

bash
uname -a
cat /etc/os-release
nproc
free -h
df -h
lscpu

uname -a prints the kernel name and release plus the machine architecture. The architecture is the line that matters: x86_64 means a 64-bit Intel/AMD system, aarch64 means 64-bit ARM. cat /etc/os-release identifies the distribution and version, confirming Ubuntu 24.04. nproc counts CPU cores, free -h shows memory in human units, df -h shows disk usage, and lscpu details the CPU including the model and the virtualization flags. If uname -m reports x86_64 or aarch64, you have a 64-bit kernel, which this program requires.

Step by stepFirst login and system update
  1. Confirm the kernel and resources: run uname -a, free -h and df -h and check the 64-bit architecture.

  2. Refresh and upgrade packages: sudo apt update then sudo apt upgrade bring the system current.

  3. Install the development tools: sudo apt install build-essential git gcc gdb adds the compiler, debugger and build helpers.

  4. Set your identity: give the machine a hostname, timezone and locale with hostnamectl, timedatectl and localectl.

  5. Generate an SSH key: ssh-keygen -t ed25519 creates a key pair for Git and future lab-board access.

  6. Take a snapshot: snapshot the VM or run wsl --export so the state is recoverable.

Install the toolchain now so it is ready for the next lesson:

bash
sudo apt install build-essential git gcc gdb

build-essential is a metapackage that pulls in gcc, g++, make and the C library headers; gdb is installed as its own package. Confirm the tools exist and can compile a real program:

bash
gcc --version
gdb --version
printf '#include <stdio.h>\nint main(void){puts("hello");return 0;}\n' > hello.c
gcc -o hello hello.c
./hello

The final line should print hello. This is the moment the environment stops being a box and becomes a working development machine: a compiler that turns C into a running program, on the same platform your future code will target.

Identity and housekeeping follow. sudo hostnamectl set-hostname devbox names the machine, sudo timedatectl set-timezone Africa/Cairo sets the timezone (adjust to your own), and sudo localectl set-locale LANG=en_US.UTF-8 sets the locale. On Ubuntu your first user is already in the sudo group; on other distributions the administrator group is called wheel, and you add a user with usermod -aG wheel user. Then generate an SSH key for the Git work and board access coming later:

bash
ssh-keygen -t ed25519 -C "your.email@example.com"

This creates a private key and a public key (.pub) in ~/.ssh. Never share the private key; the public key is what you give to Git hosts and later to lab boards.

Finish with a snapshot. On a VM, snapshot the machine in your hypervisor. On WSL2, export the distribution as shown in the internals section. A snapshot taken now means the next lesson's experiments can never permanently break your environment.

First login and system setupuname -averifykernelapt updaterefreshpackagesapt installtoolchainhostnamectlidentityssh-keygened25519 keysnapshotrecoverablestateuname -averifykernelapt updaterefreshpackagesapt installtoolchainhostnamectlidentityssh-keygened25519 keysnapshotrecoverablestate
The first-login sequence, from verifying the kernel and resources, through apt update and installing the toolchain, to setting the hostname, timezone, locale and SSH key.
Read the kernel, distribution and resources
/dev/sdd       1007G  5.1G  951G   1% /
none            3.9G   36K  3.9G   1% /mnt/wslg
none            3.9G     0  3.9G   0% /usr/lib/wsl/lib
rootfs          3.9G  3.4M  3.9G   1% /init
none            3.9G  556K  3.9G   1% /run
none            3.9G     0  3.9G   0% /run/lock
none            3.9G     0  3.9G   0% /run/shm
none            3.9G   68K  3.9G   1% /mnt/wslg/versions.txt
none            3.9G   68K  3.9G   1% /mnt/wslg/doc
C:\             477G  361G  116G  76% /mnt/c
D:\             476G  265G  212G  56% /mnt/d
tmpfs           3.9G     0  3.9G   0% /run/qemu
tmpfs           783M   20K  783M   1% /run/user/1000
learner@embeddex:~/lab$ # the CPU model behind nproc and uname
learner@embeddex:~/lab$ lscpu | head -8
Architecture:                            x86_64
CPU op-mode(s):                          32-bit, 64-bit
Address sizes:                           46 bits physical, 48 bits virtual
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               GenuineIntel
Model name:                              12th Gen Intel(R) Core(TM) i5-12600HX
Compile and run your first C program
learner@embeddex:~/lab$ # the GNU compiler is installed
learner@embeddex:~/lab$ gcc --version | head -1
gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
learner@embeddex:~/lab$ # write a tiny C program
learner@embeddex:~/lab$ printf '#include <stdio.h>\nint main(void){puts("hello");return 0;}\n' >
 hello.c
learner@embeddex:~/lab$ # the complete source
learner@embeddex:~/lab$ cat hello.c
#include <stdio.h>
int main(void){puts("hello");return 0;}
learner@embeddex:~/lab$ # compile it
learner@embeddex:~/lab$ gcc -o hello hello.c
learner@embeddex:~/lab$ # run it: this box is now a working dev machine
learner@embeddex:~/lab$ ./hello
hello
learner@embeddex:~/lab$ # a 64-bit ELF for the same platform as the kernel
learner@embeddex:~/lab$ file hello
hello: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter
/lib64/ld-linux-x86-64.so.2, BuildID[sha1]=d3496a29592052e6027c4dd9204a4874becd30ae, for GNU/Lin
ux 3.2.0, not stripped
04

A minimal shell, and the failures you will meet

5 min read

You only need a handful of commands to be productive on day one, and then a map of the failures you are most likely to hit. This section gives you both.

The on Ubuntu is bash. It prints a prompt, you type a command, and it runs it. The core set: cd changes directory, ls lists files, pwd prints where you are, mkdir makes a directory, rm removes files, cp copies, mv moves or renames, and cat prints a file. When you forget how a command works, man command opens its manual page, and man itself is the most important command to remember.

When you type a command, the shell looks for a program of that name in the directories listed in a variable called PATH:

bash
echo $PATH
which gcc

If a program is not found, bash reports command not found. That almost always means the program is not installed, or its directory is not on your PATH. The file ~/.bashrc runs each time you open a shell and is where you add your own settings, such as extending PATH or adding aliases.

How bash resolves a commandtype acommandalias?expandbuiltin?PATH lookupExit from step 4: not foundcommand not foundfork + exectype acommandalias?expandbuiltin?PATH lookupExit from step 4: not foundcommand not foundfork + exec
How bash resolves a typed command: check for an alias, then a builtin, then search each PATH directory, then run it or report command not found.
Going deeper.bashrc, .profile and when each runs

Bash reads different files depending on how it starts. An interactive non-login shell, which is what you get when you open a terminal window, reads ~/.bashrc. A login shell, which is what you get when you log in over SSH or at a text console, reads ~/.profile (and ~/.bash_profile if it exists). A terminal window on the Ubuntu desktop (GNOME Terminal) starts a non-login shell, so it reads ~/.bashrc; WSL and SSH sessions start a login shell, and Ubuntu's default ~/.profile then sources ~/.bashrc. That is why beginners are told to put settings in ~/.bashrc: it runs in both cases. The practical rule: put interactive conveniences like aliases and prompt settings in ~/.bashrc, and put things that should happen once per login, like adding directories to PATH, in ~/.profile. In WSL2, the Windows PATH is appended to the Linux PATH by default, which is why you can sometimes run Windows executables from inside Linux.

The failures to expect, with the symptom, cause and fix:

  • A VM reports no 64-bit guest, or WSL2 will not start. Virtualization is disabled in the firmware. Reboot into BIOS/UEFI and enable VT-x (Intel) or AMD-V/SVM (AMD). Confirm with lscpu, which lists vmx or svm in the flags.
  • wsl -l -v shows version 1, and something odd is broken. The distribution is still WSL1. Convert it with wsl --set-version <distro> 2.
  • The disk is full. Guest disks and WSL2 vhdx files grow and do not shrink automatically. Check df -h, remove what you do not need, and for WSL2 reclaim space by exporting and re-importing the distribution, or let the disk shrink automatically with wsl --manage <distro> --set-sparse true on recent WSL versions.
  • The clock is wrong inside a VM or WSL2. Virtual machines do not always keep time perfectly, and a suspended WSL2 can drift. Fix a VM by enabling time sync in the guest tools, and fix WSL2 with sudo hwclock -s or by shutting down with wsl --shutdown and restarting.
  • apt update fails with network errors behind a corporate proxy. The package manager cannot reach the repository. Set the proxy variables http_proxy and https_proxy, and for apt add a line such as Acquire::http::Proxy "http://proxy:3128"; to a file in /etc/apt/apt.conf.d/.
The shell: move around and manage files
learner@embeddex:~/lab$ # the shell starts in your home directory
learner@embeddex:~/lab$ pwd
/home/learner/lab
learner@embeddex:~/lab$ # make a directory
learner@embeddex:~/lab$ mkdir demo
learner@embeddex:~/lab$ # move into it
learner@embeddex:~/lab$ cd demo
learner@embeddex:~/lab/demo$ # the working directory changed
learner@embeddex:~/lab/demo$ pwd
/home/learner/lab/demo
learner@embeddex:~/lab/demo$ # write two lines to a file
learner@embeddex:~/lab/demo$ printf 'first line\nsecond line\n' > notes.txt
learner@embeddex:~/lab/demo$ # list the directory with details
learner@embeddex:~/lab/demo$ ls -l
total 4
-rw-r--r-- 1 learner learner 23 Nov 15 05:35 notes.txt
learner@embeddex:~/lab/demo$ # read the file back
learner@embeddex:~/lab/demo$ cat notes.txt
first line
second line
learner@embeddex:~/lab/demo$ # back to the home directory
learner@embeddex:~/lab/demo$ cd ..
How bash finds a command, and why a bare script fails
kyb3d8bbwe/ffmpeg-9.0-full_build/bin:/mnt/c/Users/Eslam El Hefny/AppData/Local/Programs/Cua/cua-
driver/bin:/mnt/c/Users/Eslam El Hefny/AppData/Local/Programs/cursor/resources/app/bin:/mnt/c/Us
ers/Eslam El Hefny/AppData/Local/Microsoft/WinGet/Packages/PHP.PHP.8.3_Microsoft.Winget.Source_8
wekyb3d8bbwe:/mnt/c/Program Files/nodejs:/mnt/c/Program Files/Git/mingw64/bin:/mnt/c/Program Fil
es/GitHub CLI:/mnt/c/Program Files/Git/usr/bin/vendor_perl:/mnt/c/Program Files/Git/usr/bin/core
_perl
learner@embeddex:~/lab$ # where a command actually lives
learner@embeddex:~/lab$ which bash
/usr/bin/bash
learner@embeddex:~/lab$ # a script we wrote; note the permissions
learner@embeddex:~/lab$ ls -l myscript
-rw-r--r-- 1 learner learner 39 Nov 15 05:35 myscript
learner@embeddex:~/lab$ # the bare name is not on PATH: command not found
learner@embeddex:~/lab$ myscript
bash: myscript: command not found
learner@embeddex:~/lab$ # an explicit path finds it, but no execute bit: permission denied
learner@embeddex:~/lab$ ./myscript
bash: ./myscript: Permission denied
learner@embeddex:~/lab$ # add the execute permission
learner@embeddex:~/lab$ chmod +x myscript
learner@embeddex:~/lab$ # now it runs
learner@embeddex:~/lab$ ./myscript
hello from the script
05

Try it

1 min read

Open the lab for this session and install your chosen environment from scratch, then run the verification commands and record what uname -a, free -h and df -h print. Install the toolchain with sudo apt install build-essential git gcc gdb and record the versions gcc --version and gdb --version report, then generate an Ed25519 key with ssh-keygen -t ed25519 and print the public key. Each step proves one idea from this lesson, and the practice pack's questions cover the same ground, from the difference between WSL1 and WSL2 to the NAT-versus-bridged decision. Take a snapshot or export before you move on to your developer toolkit and lab board.

Key takeaways

  • WSL2 is a real Linux kernel in a lightweight Hyper-V VM; WSL1 was a syscall translator with no kernel.
  • Containers reuse the host kernel to give reproducible toolchains without a full VM.
  • uname -a, free -h and df -h confirm the kernel, memory and disk in one breath.
  • A snapshot or a wsl --export before any risky change is what makes a broken environment recoverable.
Reflect
  1. Explain to a colleague, in two sentences: verify the install with uname, /etc/os-release, nproc, free -h, df -h and lscpu, and confirm a 64-bit kernel.
  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