Skip to content
Projects

About

OS tutorial from Nanobyte YouTube channel.

Learning & Education

How these counts are measured

Measured star growth

in 24h
+2
in 7 days
+2
in 15 days
+2
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

nanobyte_os

This repository contains the code from the "Building an OS" series on the "Nanobyte" YouTube channel.

Prerequisites

The project requires a Unix-like environment. If you are using Windows, there are various ways of setting one up (WSL, a Linux virtual machine, Cygwin, MSYS2). I recommend using WSL, which is the easiest to setup.

For Part 11, you need the following tools:

  • scons
  • nasm
  • mtools
  • dependencies to build a GCC cross compiler (see the section below)
  • qemu-system-x86 for testing
  • bochs-x bochsbios vgabios for debugging
  • your preferred text editor

A major change in Part 11 was the move from make to scons. Most of the build scripts are now written in Python. Check the "Building" section if you are coming from Part 10, there are some new dependencies.

Building

  1. Install dependencies by running scripts/install_deps.sh. It detects your distro (Debian/Ubuntu, Fedora, Arch, openSUSE), or macOS, and installs the packages listed in scripts/deps/<distro>.txt. On macOS, it needs Homebrew and the Xcode command line tools (xcode-select --install). To install them yourself instead, use that list with your package manager, for example:
sudo apt install $(sed 's/#.*//' scripts/deps/debian.txt)
  1. Check the build_scripts/config.py configuration file. The toolchain variable specifies where the toolchain will be downloaded and installed. The default path is ../.toolchains, which is in the parent directory to where you cloned the repo.

Coming from Part 10, you might want to reuse the old toolchain you have already built. Simply change the path toolchain variable to point to the correct directory.

Another important variable is mountMethod. See the section below for details.

  1. Run scons toolchain, this should download and build the required tools (binutils and GCC). If you encounter errors during this step, you might have to modify scripts/setup_toolchain.sh and try a different version of binutils and gcc. Using the same version as the one bundled with your distribution is your best bet.

  2. Run scons. If you are using the mount method, type your sudo password when prompted, this is required for running losetup, mount, umount.

Building with docker

If you'd rather not install everything on your machine, ./build-docker.sh runs the build in a container, so you only need docker or podman. Any arguments are passed to scons, for example ./build-docker.sh imageType=floppy.

The first run builds a local nanobyte-build image with the dependencies and the cross compiler, which takes a while. Later runs reuse it. When the files it's built from change (scripts/docker/Dockerfile, scripts/install_deps.sh, scripts/deps/debian.txt, scripts/setup_toolchain.sh), the script builds a new image and lists the old ones, which you can delete.

The container always uses the mountless mount method. To run the OS, use scripts/run.sh on your machine (it needs qemu-system-x86), for example scripts/run.sh disk build/i686_debug/image.img. scons run would rebuild everything with your local toolchain.

Mount methods

The mountMethod variable in build_scripts/config.py sets how files are copied into the disk image:

  • mountless (default) creates the file system with the files already in it, without mounting anything: mtools writes them into FAT, mkfs.ext2 -d fills ext2 from a directory. No sudo, and it works in WSL and containers, and on macOS for FAT. ext2 needs mkfs.ext2 from e2fsprogs.

  • guestfs mounts the image with guestmount (libguestfs), without sudo. Use it if your distro has no mtools; install libguestfs yourself (libguestfs-tools on Debian/Ubuntu, guestfs-tools on Fedora and openSUSE, libguestfs on Arch). It doesn't work properly on some systems, most notably WSL.

  • mount uses losetup and mount. The disadvantage is that it requires typing your password every time you rebuild the disk image.

Warning

** DO NOT use sudo to run the build**. This will mess up file permissions for all the files in the build directory, and has the potential of damaging your system. The build script will request elevated privileges only when performing the mount operations.

Running

  • run scons run to test your OS using qemu.

  • to make a bootable ISO, build a floppy image (scons imageType=floppy), then run scripts/img_to_iso.sh build/i686_debug/image.img nbos.iso. It needs xorriso. The ISO boots in floppy emulation mode: qemu-system-i386 -cdrom nbos.iso.

Debugging with qemu and GDB

  • run scons debug.

Debugging with bochs

  • run scons bochs.

Troubleshooting: Bochs has proven to be pretty unreliable. Check this article for some troubleshooting tips.

Links

Explore related projects

Loading…