Getting started with ELKS

Contents

  1. What is ELKS?

  2. First steps with ELKS

  3. Downloading and Compiling ELKS

  4. Configuring the kernel and selecting the keyboard driver

  5. Generating and mounting disk images

  6. Making a bootable CD image with ELKS

  7. Development tools for ELKS



1. What is ELKS?

ELKS is a Linux-like system for 16-bit x86 PCs and embedded systems. The entire system can fit on a single floppy disk image. ELKS is free software and available under the GNU General Public License (GPL).

ELKS was named Linux-8086, when its development started in 1995 by Linux kernel developers Alan Cox and Chad Page as a fork of the standard Linux. By early 1996 the project was already renamed ELKS. Many developers have contributed to this project since 1995. In 2012 ELKS migrated to GIT and numerous patches from the Linux-8086 mailing list were committed to the new repository.

The objective of the ELKS project is to create a Linux option for 8086 class PC's since Linux itself requires a 32 bit processor. However, there is only very few hardware for embeddable systems available now which would require a system like ELKS. Most hardware platforms have got far more powerful since the beginning of ELKS.

The ELKS concept is very similar to Linux so that you can use a lot of the available information for Linux to get to know ELKS. The documentation that is available for Linux on the internet can to a large extend be used to explain the code in ELKS. However, some parts are based on the Minix operating system, for example the format of the executable files and the use of the Minix file system.

2. First steps with ELKS

The easiest way to get to know ELKS is to use a prepared ELKS disk image. If you have an account with GitHub and can log into it, you can download a disk image here: https://github.com/elks-org/elks/actions
ELKS uses Continuous Integration (CI) with GitHub actions. On this web page there is a list showing when the „main“ or „cross“ workflows
have been executed. The main workflow will build disk images based on the latest version. If you click on „main“ at the top of the list, you will see e.g. „fd1440.bin“ as an artifact. This file is a disk image you can download and execute e.g. in Qemu. You can run that with Qemu with the following command: „qemu-system-i386 -fda fd1440.bin

On Windows you can install the Qemu Manager from many sites e.g. here: http://qemu-manager.en.lo4d.com/ Configure the fd1440.bin image file as the floppy to boot from and it will run.

If you cannot download the artifact mentioned above, you have to download and compile the source code and compile it as described in the next chapter.

After ELKS has booted log in as „root“ without entering a password. Following that the current directory is the empty home directory of root. From there get into the ELKS root directory by entering „cd /“ or „cd ..“. If you then enter „ls -l“ you see the directory structure. The programs you can run are in etc/bin and usr/bin. The file /usr/bin/ed is an editor.
Here is a description how to use it: https://www.geeksforgeeks.org/ed-command-in-linux-with-examples/ So in the root directory you could enter „usr/bin/ed var/www/index.html“. This will load the index.html file. The command „ ,p “ will display it in the editor and „q“ will terminate ed again.

If you want to test ELKS on a real PC you can write the fd1440.bin image file to a floppy disk. Check first what the device name for the floppy disk is on your PC, it may be /dev/fd0, /dev/sdb or /dev/sdd. The command „df“ will tell you that as long as a floppy is inserted in the drive. Use dd to copy the image file to the floppy: dd if=fd1440.bin of=/dev/sdd bs=2048“.
Using Windows you can use the Rawwrite utility to write the floppy image to a real floppy.

ELKS has the following default directory structure:

\       = root
\-bin   = binary executables providing common linux commands such as ls, cp, ps.
\-dev   = device files such as fd0, hda0, tty1 (floppy, hard disk, terminal)
\-etc   = configuration files such as inittab, passwd, rc.d, termcap
\-home  = home directories
\-lib   = library files
\-linux = kernel file
\-mnt   = mount directory to mount filesystems
\-root  = root user’s home directory
\-sbin  = system binaries such as fdisk, fsck, mkfs, partype, ramdisk
\-tmp   = temporary files
\-usr---        
        \-bin   = application programs and user binaries
\-var--- 
        \- run  = run-time variable data containing system information

        \- www  = pages for the webserver application

With the „du“ command entered in the root directory you can determine how much disk space in kbyte is used by the files in the directories. The „meminfo“ command shows the current memory usage and the „ps“ command the currently running processes.

Further commands are documented in the „Documentation/html/technical/ELKS_commands_and_utilities.html“ file and there is also a One-Page-Manual available: „Documentation/html/user/ELKS_OPM.html“.

In the /bin directory there are also the „Mtools“ commands which all begin with the letter „M“. This is a group of MSDOS tools to allow you to read and write to MSDOS formatted diskettes from a Unix based system like ELKS. These commands are documented in the „elks/elkscmd/mtools/Readme“ file.

If you want to terminate your ELKS session you should not just turn your PC off or terminate the Qemu emulation. ELKS keeps files in its internal buffers and these get lost this way. Typically new files which you generated will be missing next time you start ELKS.

To avoid this use the “shutdown”, “poweroff” or “reboot” commands. The shutdown and poweroff commands are kernel options which may not be compiled in. Poweroff supports APM.

These commands will execute the „sync“ command to write the buffers to the disk and use the “umount /” command to unmount the root file system to avoid data loss. If the shutdown command is not available you have to enter these on the command line before switching off the power of your PC.

3. Downloading and compiling ELKS

Download the latest version from GitHub. Select 'clone or download' from this page: https://github.com/elks-org/elks and click on 'download zip'. Then unpack the downloaded 'elks-master.zip' archive into an 'elks' directory in the root of your home directory.

If you have GIT installed on your system, you can clone ELKS with the following command in your home directory:

git clone https://github.com/elks-org/elks.git

This will generate an elks directory in your home directory. You can now execute the './build.sh' script in the elks directory which will do it all for you. Before that, generate a directory called 'cross', where the GCC-ia16 compiler will be put into.

After the 'build.sh' script has finished you can set the environment variables with ' . env.sh' - observe the dot command here. Then, provided you have already installed qemu, enter ./qemu.sh to run the fd1440.bin image with ELKS on it. This was generated with the 'build.sh' script. You may have to modify the 'qemu.sh' script removing the 'tsc' parameter after 486.

4. Configuring the kernel and selecting the keyboard driver

The default configuration does not include all available features due to memory constraints. There is a configuration script which allows you to select the available options from a menu system. To execute this, run 'make menuconfig' in the elks directory to configure the kernel and add options. Before that run the „. ./env.sh“ script to set the required environment variables, if you have not already done so. Most of the options you can choose from are explained in the file 'elks/config/Configure.help'. The selected options will be stored in the file „elks/.config“. When you exit menuconfig it will ask you to save the selected settings as the current configuration. Do not select „Save Configuration to an Alternate File“ before, because this configuration will not be used as the current configuration after being saved.

If you require a non-US keyboard driver you have to use 'make menuconfig' to configure this. Select „Kernel & Hardware→Drivers→Character device drivers→(American) XT Keyboard support. If you click on the last item a menu will open where you can select various keyboard drivers different from the (American) XT keyboard support. Also check that networking and unix domain sockets are enabled if you want to use these. Remember that you cannot select all the options due to memory constraints.

After selecting your options with 'make menuconfig' you have to compile the kernel again. For this enter „make clean“ and then enter „make all“ to compile ELKS with the newly selected options and generate a floppy disk image file called „fd1440.bin“ in the elks/image directory. You can execute this image file using the „./qemu.sh“ script.

5. Generating and mounting disk images

Using menuconfig you can select different disk images, floppy images and hard disk images, and compile ELKS again to get these generated. If you select the „Build extra binary images“ option in the „Target image“ section, ELKS will generate images of all the available disk types in the image directory. You can also configure one of these images as a second disk in the „./qemu.sh“ script with the line:

IMAGE="-boot order=a -fda image/fd1440.bin -drive file=image/hd.bin,format=raw,if=ide"

This way ELKS boots from the fd1440.bin image. After booting ELKS you have to mount these second disk images with the mount command using „/mnt“ as the mount point:

mount /dev/bda /mnt

Or, if the disk is formated as a FAT disk you enter:

mount -t msdos /dev/bda /mnt

After that you can enter „cd /mnt“ to get into the second hard disk, use e.g. „mkdir tmp“ to put to a new directory on it and enter „ls“ to see this displayed on the screen. Menuconfig allows you to specify if the generated hard disk image will allow to boot ELKS. Currently the generated disk images will have no partition table.

Now, this is how you can make a disk image with a partition table. First generate an empty disk image on your Linux system:

dd if=/dev/zero of=hdisk.img bs=1024 count=32200

Then specify two disks with this line in the qemu.sh:

IMAGE="-boot order=a -fda image/fd1440.bin -drive file=hdisk.img,format=raw,if=ide"

This will boot ELKS from the fd1440.bin floppy image. The new disk image will be the „/dev/bda“ device. Using the fdisk utility on ELKS you can configure partitions on this hard disk image. Enter „fdisk /dev/bda“ to run fdisk. Use the „n“ command to create a new partition, use „t“ to set the ID to 80, select „w“ to write the new partition table to the disk image and „q“ to exit fdisk again. Then generate a Minix file system on the first partition:

/bin/mkfs /dev/bda1 32200

If you partitioned the /dev/bda disk into four partitions these will be called /dev/bda1, /dev/bda2, /dev/bda3 and /dev/bda4. You can then mount these partitions with the command:

mount /dev/bda1 /mnt

On Linux you can mount the disk image as a loop device and write your required files on it. This operation is explained in the document „writing apps in C for elks.html“.

6. Making a bootable CD image with ELKS

You can make a bootable ELKS CD from the fd1440.bin image. Use mkisofs with Linux to generate an elks.iso image:

mkisofs -r -b image/fd1440.bin -c boot/boot.catalog -o elks.iso . 

Now you can burn the elks.iso image on a CD. If you only have one CD drive in your PC you can enter:

sudo cdrecord speed=2 elks.iso

This will result in a CD which will boot ELKS on power up. If the CD drive is not the first drive your PC will select to boot from, select the CD drive from the boot menu of the BIOS.

Or run the elks.iso image in qemu:

qemu-system-i386 -boot d -cdrom elks.iso 

To burn a hard disk image instead of a floppy image on a CD you have to add the -hard-disk-boot option:

mkisofs -r -hard-disk-boot -b image/hd.bin -c boot/boot.catalog -o elks.iso .

You can also run ELKS in a browser using a Javascript or Java based PC emulator. For example after making a bootable CD image (El Torito) from an ELKS hard disk image I could load and run it in virtual x86 on this page: http://copy.sh/v86/ The floppy image did not work though.There are further emulators like JPC http://jpc.sourceforge.net/home_home.html or PCjs http://www.pcjs.org/ which may work as well.

7. Development tools for ELKS

ELKS and application programs for ELKS are cross-compiled on a standard Linux system with GCC for IA16, a 16 bit version of GCC.

If you compiled ELKS as described above with the „build.sh“ script, the gcc-ia16 compiler has been installed already. Otherwise you could run the script „tools/build.sh“ while being in the „elks/“ directory. This script will automatically download and build the gcc-ia16 tool chain into the „cross“ directory.

For Ubuntu and Debian distributions you can download a pre-compiled cross directory from here: https://github.com/elks-org/elks/actions On this web page there is a list showing when the „main“ or „cross“ workflows have been executed. The cross workflow will build a tool chain in a cross directory. If you click on the top „cross“ entry of the list, you will see the „cross“ directory as an artifact. You can download that, provided you are logged into GitHub, and add it into the elks directory on your local disk.

If you want to develop applications using the C language, see the document „writing apps with C.html“. There is also a document for assembler programs: „writing apps with assembler.html“.

The ELKS package includes the elksemu program in the elksemu directory which allows to run 8086 ELKS programs under Linux. This way new programs can be tested quickly without adding them to the ELKS image file and booting ELKS.


16th April Georg Potthast