This is chapter 19 of my Linux Assembly book. However, it has a ton of information about Linux in general. I also cover how to run the Tiny Core Linux distribution inside of the QEMU emulator. This will give current Windows users a way to try out Linux without having to give up Windows until they are sure they no longer need it. Even if you don’t plan to do Assembly programming, this is a great way to get a retro computing feel because a terminal only Linux system is very similar to DOS, except the names of all the commands are different!
Chapter 19: Getting Started with Linux
This whole book was written on Debian version 12 (bookworm). This has been my Linux distribution on my desktop computer since at least 2024 when Microsoft Windows decided to overwrite my bootloader when I had a dual boot between Windows and Ubuntu. I installed the newest version of Debian available at the time and have never looked back.
I got my start in the Linux world back in 2005 during the time of Ubuntu 5.10 (Breezy Badger). Ubuntu was my first distribution and I used it without problem for years. But since Ubuntu was based on Debian, I decided to go with the original distribution. I highly recommend either of them because both of these projects have great websites with detailed installation guides.
https://www.debian.org/
https://ubuntu.com/
If you have an old machine running Windows but it is kind of slow, I recommend following the official instructions and installing one of these distributions of Linux to your hard disk by booting either a live CD or USB drive and following the instructions. I figured it out with no background in Linux when I was 18 years old. They have done great work making Linux easy for beginners.
But what I am going to do is share a method of trying out Linux for people who don’t have a space computer in their house and they can’t risk deleting Windows because their job or school requires specific Windows software.
Just as I used a DOS emulator to emulate DOS for the DOS edition of Assembly Arithmetic Algorithms, it is also possible to run Linux in an emulator.
There are some things you should know about running Linux in an emulator.
-
Emulators are slower than real hardware and cannot be used to judge Linux. Just because you ran Linux in an emulator and it was slow does not mean that the operating system is a failure or that you should give up the idea.
-
Emulators have many different options that you should read about and the reason I recommend learning how to use an emulator is because it teaches you to understand hardware better. Files are used as virtual compact disks or hard disks but the emulators see them as being the same as real hardware.
-
Portability is the best reason to use an emulator. Because an emulator can run software for the same machine type or even a different architecture, you can use the information in this book even if you are running an Intel emulator on an ARM or RISC-V processor.
The emulator I will be using for this example is called QEMU.
https://www.qemu.org/
https://www.qemu.org/docs/master/system/invocation.html
And the distro I will be using is called Tiny Core Linux.
You will want to go to the downloads page and get the smallest of the three files. It will be named “Core-current.iso”.
Install QEMU on whatever OS you are currently using. QEMU is available for Windows, Mac, and Linux.
Once you have QEMU installed and downloaded “Core-current.iso” to a directory somewhere, you can launch it with QEMU by using this command.
qemu-system-x86_64 -drive file=Core-current.iso,media=cdrom
You can also use the shorter form of the command which means the same thing.
qemu-system-x86_64 -cdrom Core-current.iso
Either way, it will boot into a tiny Linux system that is only a command line. You can use standard Linux commands such as ls,cat,sed,cp,rm,cd, and exit. There is even the “vi” editor built in. If you have not used the vi or vim editors before, don’t worry about it. However, if you have used them, go ahead and practice by making some text files and saving them.
When you are done using Tiny Core Linux, just use this command:
sudo poweroff
How does Tiny Core work?
Everything will shut down and the emulator will also stop. If you clicked on the QEMU Window and your mouse cursor disappeared, press Ctrl+Alt+G on your keyboard to grab it back from the emulator so you can do other things while the emulator is still running Tiny Core Linux.
Tiny Core Linux runs entirely in RAM when you run it using only the ISO image for the cdrom drive. Any changes you make will not be saved when you exit the emulator.
I am sure you are wondering what good an operating system is that doesn’t save your work. For that, I have 2 answers.
-
Because Tiny Core starts fresh each time using only the files in the CD image, it means each time you have a new chance to do something new and test things without any fear of messing up your system.
-
There is a way to install it to a hard disk and configure it to save changes. I will be explaining more about this in this chapter.
Installing Software Temporarily
Before trying to permanently install Tiny Core to a hard disk, it is important to understand the package manager that it uses. It is called tce-ab. You can run it by its name.
tce-ab
It has a lot of text with instructions that let you search for and install packages. For example, on my machine when I booted into Tiny Core on QEMU, I was able to search for and install the “nano” text editor and the “nasm” assembler.
You can also directly install programs with the tce-load program. This is often faster than navigating the menus of tce-ab.
tce-load -wi nano
However, because even previously installed programs will be gone on the next reboot, it is time to teach you how to create a virtual hard disk and reboot into the emulator with a hard disk that we will install to.
Installing to a Hard Disk
First, exit the emulator and then use the qemu-img command below to create a 1 Gigabyte empty file that will be used as a hard disk.
qemu-img create harddisk.img 1G
qemu-system-x86_64 -drive file=Core-current.iso,media=cdrom -drive file=harddisk.img,format=raw,media=disk
The Tiny Core install program is ironically not included in the cdrom file we are booting from. Therefore, it becomes necessary to install the installer!
While you are booted into QEMU with both the cdrom and harddisk images, install the install script with the tce-load command below.
tce-load -wi tc-install
It will take some time to install the dependencies of the Tiny Core install script. Notable dependencies are Perl (a popular scriping language) and syslinux (the bootloader).
After it finished installing, run this command:
sudo tc-install.sh
The installer asks a lot of questions about what options you want when you want to install.
- i for installing from booted cdrom
- f for frugal hard drive installation
- 1 for whole disk installation
- 2 for sda (first hard disk)
- y for installing the bootloader
- 3 for the ext4 file system
Most other options you can leave blank and press enter.
I know that process may have been a little complex but it highlights the difference between installing Linux and installing Windows.
You don’t install Windows. It was already on your computer when you bought it. This means somebody else chose all the options for you.
When you install Linux, you need to know some basic facts or at least google them when in doubt. This takes some time to learn but it gives you unrestricted control in the kind of system you are building for your software development.
In fact Tiny Core provides a helpful book that explains some of these options.
http://www.tinycorelinux.net/book.html
The book covers the graphical interface which is available on a much larger ISO file. I chose to go the pure command line only route and adapt the instructions for the tc-install.sh script which only got a passing mention in the book.
When you have completed those steps, it is now possible to boot directly into the hard disk without the cdrom!
qemu-system-x86_64 -drive file=harddisk.img,format=raw,media=disk
The main benefit of installing to a hard disk instead of just booting from the cd image each time is that any programs you install with tce-ab or tce-load will stay there and be available to use each time you reboot.
Making a Persistent Home Directory
However, the files in your home directory are deleted each time you reboot. However, there is an easy fix for this. We will open the bootloader configuration and add an option to restore the backup from sda1.
First, open the config file:
nano /mnt/sda1/tce/boot/extlinux/extlinux.conf
And add this option to the line that starts with APPEND.
home=sda1
This means that the home directory will become an actual directory on the hard disk instead of a temporary location only loaded into RAM. With this step completed, you can begin programming in Assembly on your Tiny Core Linux system! Time to install the tools.
NASM is already in the repository and this is the standard way to install it.
tce-load -wi nasm
However, FASM is not available in the repository but it can be easily downloaded from the official website. However, this system only has a terminal with no web browser. Don’t worry, there is a way! We can use the wget command that is already in Tiny Core Linux!
wget http://flatassembler.net/fasm-1.73.35.tgz
After the TGZ (Tar with GZip compression) file downloads, we need to extract the files from it.
tar -xf fasm-1.73.35.tgz
Now you can change to the fasm directory that was just created.
cd fasm
Inside are several files including “fasm” (the actual executable that can assembly all the programs in this book), “fasm.txt” the manual in plain text that describes both how to use FASM and also introduces the Intel instruction set. The “license.txt” may also be of interest.
To install fasm, we should add it to somewhere where it can be in the current path. Check what the path is currently with this command.
echo $PATH
One of the directories that is in the path is “/home/tc/.local/bin”. This gives us the information we need to install fasm permanently there. Just copy fasm there like this:
cp fasm ~/.local/bin
Now enter “fasm” as a command and see what happens. If you see the following output, then it was done correctly!
flat assembler version 1.73.35
usage: fasm <source> [output]
optional settings:
-m <limit> set the limit in kilobytes for the available memory
-p <limit> set the maximum allowed number of passes
-d <name>=<value> define symbolic variable
-s <file> dump symbolic information for debugging
This means that you can assembly and run any program that I have included in this book, Assembly Arithmetic Algorithms for Linux.
Keep in mind however that programming in this terminal based environment may feel different because you have to use terminal text editors like vi,vim, or nano. These text editors are just as good as graphical ones except that there is no mouse support. However, I was hoping to give you the retro feeling of programming like a crazy person in the 1980s.
This is just the tip of the iceberg about what Tiny Core Linux can do. However, I wanted to at least spend this chapter introducing this lesser known distro because it is small enough that it emulates with QEMU flawlessly.
Although Debian, Ubuntu, Linux Mint, and many others are better than Tiny Core because they have more programs in their repositories, they are too large to emulate because their graphical X Windows System displays use a lot more memory and it is harder for a PC emulator like QEMU to emulate them properly.
Consider Tiny Core Linux as a way to test the waters and get used to running commands in a Linux terminal before you are ready to install a more mainstream distro like Debian. However, once you have made the jump into the wonderful world of Linux, you will not be disappointed as a programmer because there is no shortage of text editors, assemblers, compilers, and even video games. For example, Final Fantasy 6 and Chrono Trigger from my Steam game collection both work on my Debian Linux system. Ironically, my Windows 11 laptop could not run Chrono Trigger.
I wrote this chapter to do my small part in the world to help people discover the things I like about Linux and the freedom it offers.
Tiny Core Linux makefile
The following makefile is something I use to run commands for emulating Tiny Core Linux inside QEMU. I use it to remind myself what commands I use to set up a new installation of Tiny Core Linux.
Core-harddisk:
qemu-system-x86_64 -drive file=harddisk.img,format=raw,media=disk
Core-cdrom:
qemu-system-x86_64 -drive file=Core-current.iso,media=cdrom
Core-cdrom-short:
qemu-system-x86_64 -cdrom Core-current.iso
Core-cdrom_and_harddisk:
qemu-system-x86_64 -drive file=Core-current.iso,media=cdrom -drive file=harddisk.img,format=raw,media=disk
harddisk:
qemu-img create harddisk.img 1G
Of course, this chapter also serves as a reminder to myself about how to use Tiny Core Linux and also why it is one of my favorite distributions of Linux. I like it because sometimes I just want to have a text-only system upon which I can improve my scripting and command line usage skills. Modern Linux distros include Graphical User Interfaces where you can point and click your way to doing anything, but from the beginning it was not this way. Therefore, I always promote learning the Linux terminal because it is the one thing that stays consistent and trustworthy no matter which distro you are using at the time.
I will admit that using the command line is a huge learning curve when you are first getting started. Perhaps I found it easier because I grew up with MS-DOS where text commands were all I had. In any case, knowing how to navigate directories on Linux to edit, copy, rename, and delete files is helpful because there are so many different graphical user interfaces and I can’t remember which menus to click on.
But the real reason text commands are the best is because text can be copy pasted and then I am able to give you the exact commands to run so that you don’t have to spend months google searching for the right documentation on all these different things!
