This blog post shows a method to boot Linux on DOSBox-X.
I have always wanted to boot a simple Linux distro using DOSBox. What are the challenges, you may ask? Well, the short answer lies in DOSBox’s name – its main purpose is for booting DOS. The long answer is that, apart from CPU limitations (which can be overcome by using a release such as DOSBox-X that can emulate a Pentium III CPU, more than enough for an early Linux distro such as Ubuntu 8), DOSBox does not fully emulate various devices such as floppy or IDE. These devices are only presented to the guest via the BIOS, which works for DOS (and early version of Windows) which queries the BIOS for system information, but not enough for Linux, which talks to the controller directly, only to find out that the floppy/IDE device is not responding.
After mounting the image on DOSBox-X with imgmount 0 -fs none floppy.img
and booting them with boot -l 0
, various floppy-only Linux releases fail to boot, despite me selecting the latest possible CPU (pentium_iii) inside dosbox.conf. With the default configuration, all tested releases first report “fd0 is 1.44M
” followed by “no floppy controllers found
”, and then kernel panic:
Booting from hard drive or CD-ROM is out of the question too as the same error message will be shown for the IDE controller. After tweaking various floppy and IDE settings in the [fdc] and [ide] such as floppy drive data rate limit, int13fakeio, mode, and enable pio32, the best I can get is an error messaging saying “floppy read timeout
”. Apparently, DOSBox floppy/IDE controllers emulation is insufficient for Linux booting.
But all is not lost. After further efforts, I located a pre-installed version of Ubuntu 9.10 Alpha, meant for VirtualBox, but boots up just fine to initramdisk
under DOSBox with just some minor modifications. The startup process drops to initramdisk
because the IDE controller could not be located and sda1
can’t be mounted, but is still a major improvement:
Believe it or not, the limited initramfs
shell is still very useful. A lot of common Linux commands such as ls
, cd
, cat
, cp
or rm
are supported. You can always add the module you want to be loaded prior to dropping to the initramfs
shell by editing /etc/initramfs-tools/modules and then run update-initramfs
:
# List of modules that you want to include in your initramfs.
# They will be loaded at boot time in the order below.
#
# Syntax: module_name [args ...]
#
# You must run update-initramfs(8) to effect this change.
#
# Examples:
#
# raid1
# sd_mod
For my usage, this solution is good enough as I simply want to study how a particular Linux device driver interacts with the hardware. The device driver I am interested in can be loaded via modprobe from the initramfs prompt. If you want to do the same, you will need to pick a 32-bit build of Linux, as early as possible, and one that does not require Physical Address Extension, or PAE which is not emulated by DOSBox. You might also want to increase RAM to 256MB, else there will not be enough memory for the ramdisk
image. You can run this command to convert VirtualBox VDI disks to the raw (DD) disk format that is supported by DOSBox:
C:\Program Files\Oracle\VirtualBox\VBoxManage.exe clonehd ubu910.vdi c:\dosbox\ubu910.raw --format raw
My debugging efforts were done on DOSBox-X, whose source codes are available here and can be compiled out of the box using Visual Studio 2019 or Visual Studio 2022. During the process, I discovered that if DOSBox-X is running in the background when it accidentally gains focus due to me still typing, the initramfs console window would be cleared and show just a blinking cursor. The emulated machine would then hang, with a lot of C++ exceptions printed in the output window, and a reset is needed.
The root cause of this issue is the NUM LOCK/CAPS LOCK/SCROLL LOCK synchronization code located in sdlmain.cpp around line 5974. Commenting out these lines fixes the error, at the expenses of lack of synchronization. For some reasons, this issue only happens with Linux, and not with DOS or Windows.
SetPriority(sdl.priority.focus);
CPU_Disable_SkipAutoAdjust();
if (strcmp(RunningProgram, "LOADLIN")) {
BIOS_SynchronizeNumLock();
BIOS_SynchronizeCapsLock();
BIOS_SynchronizeScrollLock();
}
On a side note, to get the mouse to work in DOSBox-X, you will need to use the Capture Mouse menu, otherwise your mouse will not move inside DOSBox.
For the record, I was not able to get DOSBox 0.74 as well as some other forks to boot Linux. I guess DOSBox-X, with its advanced features such as parallel port support and saving/loading of states, is a much better choice for those of us who still love playing with DOS.