Prerequisites
Before we write any code, let’s set up the environment. We do this once, and it covers everything we need for the rest of the book.
Operating System and CPU Architecture
Every command and instruction in this book targets x86 Ubuntu. Don’t worry if your machine runs Windows, macOS, or has a non-x86 CPU: the Docker instructions below are the simplest way to get there, and the one I recommend. If you prefer a virtual machine, VirtualBox1 is a solid free option on an x86 machine.
x86 Ubuntu in Docker
Install Docker by following the official guide2. Once Docker is running, start a container with the command below. Replace <host_path> with the directory on your machine where you want the book’s code to live. Inside the container, it shows up as /workspace, and everything we write there is stored in <host_path> on your machine, so it stays safe even if the container is deleted:
docker run \
-it \
--name fat12 \
--privileged \
--platform linux/amd64 \
-v <host_path>:/workspace \
-w /workspace \
ubuntu \
bash
The container keeps everything we install, so this setup only happens once. Exiting the shell just stops the container. To pick up where we left off in a later session, restart it with the command below instead of running docker run again:
docker start -ai fat12
The container shell runs as root, and the Ubuntu image doesn’t even include sudo. Many commands in this book start with sudo because native Ubuntu and VM readers need it, so we install it once here. That way, every command works exactly as shown, with no need to strip sudo each time:
apt update
apt install sudo
From there, run the commands in the following sections to set up the tools one by one.
Command-Line Tools
We build all the code we write with the GCC toolchain. We also need dosfstools, which provides the mkfs.fat command we use to create FAT disk images until we can create our own, and xxd, which we use throughout the book to hexdump disk structures.
Install all three in one shot:
sudo apt update
sudo apt install build-essential dosfstools xxd
Kernel Tools (Chapter 12 and Appendixes)
Chapter 12 boots our code inside a 32-bit i386 kernel, which needs two extras: 32-bit headers to compile it and QEMU to run it. Feel free to skip this section for now and come back once you reach Chapter 12.
First, the 32-bit headers we need to compile the kernel:
sudo apt update
sudo apt install libc6-dev-i386
Running it needs the x86 system emulator from QEMU. If you are using a VM or Docker, install QEMU directly on your machine, not inside the VM or container. Follow the official install guide for your platform3.
Getting the Code (Optional)
There is nothing to clone before we start: every chapter shows every line of code we type. Still, the finished code4 makes a great safety net. When a build fails or a hexdump doesn’t match the book, you can compare your code against a known-good version. To get it, clone the repository:
git clone https://github.com/BjoernGoetz/FAT12-Book-Code
Each chapter has its own directory (chapter-01 through chapter-12) holding the code exactly as it stands at the end of that chapter, so you can check your work or jump in at any point. Appendixes A and B add code too, so they get their own directories as well (appendix-a, appendix-b).