DOSBox-X is an open-source PC emulator. FreeDOS is an open-source DOS compatible operating system. This document describes how to setup networking under FreeDOS running in DOSBox-X. My goal was to get the FTP server in the MTCP FreeDOS package running so that I could easily transfer files between the host and FreeDOS virtual computers. (A few other ways of transferring files are also discussed.) I wrote it for my own future reference, but hope that it may be useful to others. It is mainly a compilation of instructions from DOSBox-X and FreeDOS guides found at their respective web sites.
I am running DOSBox-X on Windows 10, but this guide may be helpful if you are using other versions of Windows or perhaps even other operating systems.
Install DOSBox-X
In the DOSBox-X downloads site you will find zip versions of DOSBox-X built for Windows using both Visual Studio and MinGW. There is also an installer based on Visual Studio. The Visual Studio builds do not support slirp (which I used) so I downloaded the MinGW-based, 64-bit zip archive.
DOSBox-X emulates an NE2000 NIC using either the pcap or slirp backends. The pcap backend supports the IPX/SPX protocol in addition to TCP/IP. Using pcap requires that you install a pcap library (npcap.com) whereas slirp is built-in to the MinGW builds. Installing pcap requires administrative privileges on the host machine. The slirp backend is more likely to support wireless adapters. The pcap IP address will be the same as the host IP address, while the slirp interface appears to be behind a NAT gateway and will receive an IP address on a virtual network. You have to set up port forwarding in order to reach the FTP server (or any other services) running on the FreeDOS virtual machine. (You do not have to do anything special to connect from FreeDOS clients to outside servers.) See the “Setting up networking in DOSBox-X” guide on the DosBox-X Wiki site for additional pros and cons of each. I was only looking for TCP/IP support and didn’t mind the port forwarding restriction so I decided to use slirp.
Create a FreeDOS Directory
Create a FreeDOS directory installation directory. Copy the FreeDOS 1.3 disk/CD images (fd13boot.img, fd13live.iso, fd13bns.iso) into this directory. Copy the dosbox-x.conf file from the dosbox-x installation into this directory and rename it freedos.conf. Create a Windows shortcut to the dosbox-x.exe application. Change the properties of the shortcut so that starts in this directory. Also add the command argument “-conf freedos.conf” to the end of the Target line in the Properties window. Rename the shortcut FreeDOS.
Create a FreeDOS Disk Image
DOSBox-X supports raw hard drive images (extension .img) and Microsoft virtual hard drives (extension .vhd). Hard drive images are of fixed size while virtual hard drives grow dynamically, i.e. a 520MB IMG file will take up 520MB of space on the host computer while a 520 MB VHD file will only take up the space needed to hold the files within the virtual drive and can increase in size up to 520MB. VHD images can be mounted as drives in the Windows host just by clicking on the file in Explorer (may require administrative privileges) and so allow you to easily transfer files between the host and virtual computers. (The mtools utilities can be used to transfer files to/from an IMG disk and the host, but you are unlikely to have mtools unless you have MSYS2 or Cygwin.) You can create IMG disks from the DOSBox-X DOS menu. You can use the DOSBox-X imgmake command to create either IMG or VHD disk images. I chose to use a 520MB VHD image. Note: A 520MB disk will hold a “Full” FreeDOS installation, but if you plan to install a lot of optional FreeDOS packages the disk can fill up quickly (the DJGPP or WATCOM development packages in particular take up a lot of space). You may want to create a larger virtual drive or use multiple (C:, D:, etc) virtual drives. The FreeDOS documentation says it supports up to 2TB partitions with FAT32 formatting.
To create the virtual drive start DOSBox-X by double-clicking the FreeDOS shortcut created previously. At the DOSBox-X command prompt enter:
imgmake drivec.vhd –t vhd –size 520
This will create a 520MB VHD image in your FreeDOS working directory. The drivec.vhd file will be only a few kB in size at this point.
Install FreeDOS
We are now going to mount the VHD image as our C: drive, the FD13LIVE.ISO CD image as our D: drive, and the FD13BOOT.IMG image as our A: drive. (I could never figure out to get DOSBox-X to boot from the FD13LIVE.ISO image). Use the following DOSBox-X commands:
imgmount c drivec.vhd
imgmount d fd13live.iso
imgmount a fd13boot.img
Now boot into FreeDOS and start the FreeDOS installation:
boot a:
See the FreeDOS web site for installation instructions. You may want to increase the emulated CPU speed from the CPU menu to speed up the installation. (I use the “Emulate CPU speed” submenu and select a 166MHz Pentium.)
Run FreeDOS
After rebooting the virtual machine you will be back at the DOSBox-X prompt. You can boot into FreeDOS using:
imgmount c drivec.vhd
imgmount d fd13live.iso -t iso -ide 2m
imgmount e fd13bns.iso -t iso -ide 2s
boot c:
If everything works okay, add these same lines to the bottom (the [autoexec] section) of your freedos.conf file. Reboot by typing reboot at the FreeDOS command prompt and you should automatically boot into FreeDOS. Enter fdimples or fdimples e: to install additional FreeDOS packages from either the live or bonus FreeDOS CD images. (The size of the VHD image on the host will increase as you install packages.) You can delete the FreeDOS CD images to free up space on the host if you wish (also remove the corresponding imgmount lines from your freedos.conf file).
Transferring Files to/from Host and FreeDOS
Mounting the VHD image under Windows or using the mtools utilities for IMG drives were previously mentioned as ways to transfer files between FreeDOS and the host. You run the risk of corrupting the file system if you try to simultaneously run the FreeDOS machine while copying files to the drive image using one of these methods, so don’t do that.
DOSBos-X allows you to mount a host directory as a drive in read-only mode. Use the command “mount f drivef” to mount the host directory drivef as virtual drive F:. This is a DOSBox-X command, not a FreeDOS command so must be placed in the [autoexec] section of your freedos.conf file. You can use this method to copy files from the host to FreeDOS. Note 1: FreeDOS may assign the drive letters differently than DOSBox-X and/or overwrite drive letters. You may need to play around with the –ide option for imgmount or re-order your mount and imgmount commands to get your desired drive lettering in FreeDOS. Note 2: You can copy files to the mounted directory in FreeDOS and they will appear to be there, they won’t show up in the directory on the host however.
I prefer to run an FTP server on FreeDOS and then use a graphical FTP client on Windows (I like FileZilla and WinSCP) to drag and drop files between the host and FreeDOS. This is similar to mounting the VHD drive on the Windows host and using explorer to drag-and-drop but doesn’t require admin privileges and works for both VHD and IMG drives. Besides, to get the FTP server working we need to set up networking and there are lots of other advantages to networking under FreeDOS.
Configure DOSBox-X Networking
Edit your freedos.conf file so that it looks as follows:
[ne2000]
ne2000 = true
nicbase = 300
nicirq = 3
macaddr = random
backend = slirp
[ethernet, slirp]
ipv4_network = 10.0.2.0
ipv4_netmask = 255.255.255.0
ipv4_host = 10.0.2.2
ipv4_nameserver = 10.0.2.3
ipv4_dhcp_start = 10.0.2.15
tcp_port_forwards = 8021:21
I believe the changes in the [ne2000] sections are to the ne2000 and backend lines. The only change to the [ethernet, slirp] section is the addition of the tcp_port_forwards line. This will forward TCP port 8021 on the host to TCP port 21 (the FTP server listening port) on the virtual machine.
Configure FreeDOS Networking
Boot into FreeDOS. A full install should have created MTCP and FDNET directories under the C:\NET directory. If you did not do a full install use fdimples to install the MTCP and FDNET packages. Copy the C:\NET\MTCP\SAMPLES\SAMPLE.CFG file to C:\NET\MTCP\MTCP.CFG and copy the C:\NET\MTCP\SAMPLES\FTPPASS.TXT file to C:\NET\MTCP\FTPPASS.TXT.
Edit the MTCP.CFG file and uncomment (remove the leading #) the ftpsrv_password_file line. (This is line 80 in my version of the MTCP.CFG file.) Change it so that it reads:
ftpsrv_password_file = c:\net\mtcp\ftppass.txt
Optionally change the hostname (line 28).
You can add an FTP user to the ftppass.txt file. In my version there is a pre-defined user with username brutman and password password. If your host is connected to a public network you will probably want to change these.
Start FreeDOS Networking
We are going to add the mtcp tools to our path, set the MTCPCFG environment variable so that the tools know where to find the MTCP.CFG file, load the network card driver and then request an IP address from the DOSBox-X DHCP server. Enter the following at the FreeDOS command line:
path C:\NET\MTCP;%PATH
set MTCPCFG=C:\NET\MTCP\MTCP.CFG
C:\NET\FDNET\NE2000 0x60 3 0x300
DHCP
If everything is working correctly you should see a good news message along with your assigned IP address. You can add the lines above to your fdauto.bat file so that networking is started automatically when you boot into FreeDOS.
Note: When I reboot (fdapm warmboot) FreeDOS I get an error message at the point where the NE2000 device driver is loaded. The error indicates that a driver is already installed. I have to halt (fdapm poweroff) and then restart the FreeDOS machine or remember to unload the driver (C:\NET\FDNET\NE2000 -u) before rebooting.
The ping tool is included in the MTCP package so you can now try ping google.com. If your host computer is connected to the Internet, you can update your installed FreeDOS packages:
fdnpkg update
You can use the fdnpkg tool to install FreeDOS packages from the Internet also.
Start the FTP Server
To start the MTCP FTP server, just type ftpsrv at the FreeDOS command line. Hopefully you will see messages indicating that the server started. You will see additional messages when users connect and disconnect. Note that you use [Ctrl-C] or [Alt-X] to shut down the server.
You can connect to the server using an FTP client on the host. We are using port forwarding so you will want to connect port 8021 (instead of port 21) on the localhost (127.0.0.1). I have found that I have to configure the client to use passive mode. This may be under your client’s advanced settings. Use the username and password from the ftppass.txt file.
To use the Windows command line ftp client, enter ftp at the Windows command line and at the ftp> prompt enter open localhost 8021.
Notes on MSYS2 mtools
I found the MSYS2 mtools utilities to be a little quirky. I’ve used them without problems under Linux and Cygwin. I created a .mtoolsrc file containing:
drive f:
file=”C:/dosbox/drivec.img”
partition=1
Commands such as “mcd f:”, “mdir” behaved as expected. For many of the other commands (mcopy, mtype, etc) that tried to access files on the drive image I had to use the binary image file option:
mcopy -i C:/dosbox/drivec.img@@63S ::/docs/readme.txt .
The @@63S skips the first 63 sectors on the image (which contain the MBR and unallocated space) to access the first/only partition in the drive image. The : is used instead of a drive letter to indicate a file on the binary image. The simpler:
mcopy f:/docs/readme.txt .
would return an error message saying the file could not be found.