怎么在 Linux 中运行 DOS 程序
FreeDOS DOS QEMU

> 
> QEMU 和 FreeDOS 使得很容易在 Linux 中运行老的 DOS 程序
> 
> 
> 


 


![](/data/attachment/album/201710/31/214631f37i3qb0ics4c4ss.jpg)


传统的 DOS 操作系统支持的许多非常优秀的应用程序： 文字处理，电子表格，游戏和其它的程序。但是一个应用程序太老了，并不意味着它没用了。


如今有很多理由去运行一个旧的 DOS 应用程序。或许是从一个遗留的业务应用程序中提取一个报告，或者是想玩一个经典的 DOS 游戏，或者只是因为你对“传统计算机”很好奇。你不需要去双引导你的系统去运行 DOS 程序。取而代之的是，你可以在 Linux 中在一个 PC 仿真程序和 [FreeDOS](http://www.freedos.org/) 的帮助下去正确地运行它们。


FreeDOS 是一个完整的、免费的、DOS 兼容的操作系统，你可以用它来玩经典的游戏、运行旧式业务软件，或者开发嵌入式系统。任何工作在 MS-DOS 中的程序也可以运行在 FreeDOS 中。


在那些“过去的时光”里，你安装的 DOS 是作为一台计算机上的独占操作系统。 而现今，它可以很容易地安装到 Linux 上运行的一台虚拟机中。 [QEMU](https://www.qemu.org/) （<ruby> 快速仿真程序 <rt>  Quick EMUlator </rt></ruby>的缩写） 是一个开源的虚拟机软件，它可以在 Linux 中以一个“<ruby> 访客 <rt>  guest </rt></ruby>”操作系统来运行 DOS。许多流行的 Linux 系统都默认包含了 QEMU 。


通过以下四步，很容易地在 Linux 下通过使用 QEMU 和 FreeDOS 去运行一个老的 DOS 程序。


### 第 1 步：设置一个虚拟磁盘


你需要一个地方来在 QEMU 中安装 FreeDOS，为此你需要一个虚拟的 C: 驱动器。在 DOS 中，字母`A:` 和 `B:` 是分配给第一和第二个软盘驱动器的，而 `C:` 是第一个硬盘驱动器。其它介质，包括其它硬盘驱动器和 CD-ROM 驱动器，依次分配 `D:`、`E:` 等等。


在 QEMU 中，虚拟磁盘是一个镜像文件。要初始化一个用做虚拟 `C:`  驱动器的文件，使用 `qemu-img` 命令。要创建一个大约 200 MB 的镜像文件，可以这样输入：



```
qemu-img create dos.img 200M

```

与现代计算机相比， 200MB 看起来非常小，但是早在 1990 年代， 200MB 是非常大的。它足够安装和运行 DOS。


### 第 2 步： QEMU 选项


与 PC 仿真系统 VMware 或 VirtualBox 不同，你需要通过 QEMU 命令去增加每个虚拟机的组件来 “构建” 你的虚拟系统 。虽然，这可能看起来很费力，但它实际并不困难。这些是我们在 QEMU 中用于去引导 FreeDOS 的参数：




|  |  |
| --- | --- |
| `qemu-system-i386` | QEMU 可以仿真几种不同的系统，但是要引导到 DOS，我们需要有一个 Intel 兼容的 CPU。 为此，使用 i386 命令启动 QEMU。 |
| `-m 16` | 我喜欢定义一个使用 16MB 内存的虚拟机。它看起来很小，但是 DOS 工作不需要很多的内存。在 DOS 时代，计算机使用 16MB 或者 8MB 内存是非常普遍的。 |
| `-k en-us` | 从技术上说，这个 `-k` 选项是不需要的，因为 QEMU 会设置虚拟键盘去匹配你的真实键盘（在我的例子中， 它是标准的 US 布局的英语键盘）。但是我还是喜欢去指定它。 |
| `-rtc base=localtime` | 每个传统的 PC 设备有一个实时时钟 (RTC) 以便于系统可以保持跟踪时间。我发现它是设置虚拟 RTC 匹配你的本地时间的最简单的方法。 |
| `-soundhw sb16,adlib,pcspk` | 如果你需要声音，尤其是为了玩游戏时，我更喜欢定义 QEMU 支持 SoundBlaster 16 声音硬件和 AdLib 音乐。SoundBlaster 16 和 AdLib 是在 DOS 时代非常常见的声音硬件。一些老的程序也许使用 PC 喇叭发声； QEMU 也可以仿真这个。 |
| `-device cirrus-vga` | 要使用图像，我喜欢去仿真一个简单的 VGA 视频卡。Cirrus VGA 卡是那时比较常见的图形卡, QEMU 可以仿真它。 |
| `-display gtk` | 对于虚拟显示，我设置 QEMU 去使用 GTK toolkit，它可以将虚拟系统放到它自己的窗口内，并且提供一个简单的菜单去控制虚拟机。 |
| `-boot order=` | 你可以告诉 QEMU 从多个引导源来引导虚拟机。从软盘驱动器引导（在 DOS 机器中一般情况下是 `A:` ）指定 `order=a`。 从第一个硬盘驱动器引导（一般称为 `C:`） 使用 `order=c`。 或者去从一个 CD-ROM 驱动器（在 DOS 中经常分配为 `D:` ） 使用 `order=d`。 你可以使用组合字母去指定一个特定的引导顺序， 比如 `order=dc` 去第一个使用 CD-ROM 驱动器，如果 CD-ROM 驱动器中没有引导介质，然后使用硬盘驱动器。 |


### 第 3 步： 引导和安装 FreeDOS


现在 QEMU 已经设置好运行虚拟机，我们需要一个 DOS 系统来在那台虚拟机中安装和引导。 FreeDOS 做这个很容易。它的最新版本是 FreeDOS 1.2， 发行于 2016 年 12 月。


从 [FreeDOS 网站](http://www.freedos.org/)上下载 FreeDOS 1.2 的发行版。 FreeDOS 1.2 CD-ROM “standard” 安装器 （`FD12CD.iso`） 可以很好地在 QEMU 上运行，因此，我推荐使用这个版本。


安装 FreeDOS 很简单。首先，告诉 QEMU 使用 CD-ROM 镜像并从其引导。 记住，第一个硬盘驱动器是 `C:` 驱动器，因此， CD-ROM 将以 `D:` 驱动器出现。



```
qemu-system-i386 -m 16 -k en-us -rtc base=localtime -soundhw sb16,adlib -device cirrus-vga -display gtk -hda dos.img -cdrom FD12CD.iso -boot order=d

```

正如下面的提示，你将在几分钟内安装完成 FreeDOS 。


![Starting FreeDOS installation](/data/attachment/album/201710/31/214640lx55gm1f11xjbb5j.png "Starting FreeDOS installation")


![Select your keyboard layout](/data/attachment/album/201710/31/214640vhaawkwgwjnjazh2.png "Select your keyboard layout")


![Selecting which packages to install](/data/attachment/album/201710/31/214641g7hw0zobrijh1o6p.png "Selecting which packages to install")


![Rebooting after installation](/data/attachment/album/201710/31/214641agkiu1ic4d7d133k.png "Rebooting after installation")


在你安装完成之后，关闭窗口退出 QEMU。


### 第 4 步：安装并运行你的 DOS 应用程序


一旦安装完 FreeDOS，你可以在 QEMU 中运行各种 DOS 应用程序。你可以在线上通过各种档案文件或其它[网站](http://www.freedos.org/links/)找到老的 DOS 程序。


QEMU 提供了一个在 Linux 上访问本地文件的简单方法。比如说，想去用 QEMU 共享 `dosfiles/` 文件夹。 通过使用 `-drive` 选项，简单地告诉 QEMU 去使用这个文件夹作为虚拟的 FAT 驱动器。 QEMU 将像一个硬盘驱动器一样访问这个文件夹。



```
-drive file=fat:rw:dosfiles/

```

现在，你可以使用合适的选项去启动 QEMU，加上一个外部的虚拟 FAT 驱动器：



```
qemu-system-i386 -m 16 -k en-us -rtc base=localtime -soundhw sb16,adlib -device cirrus-vga -display gtk -hda dos.img -drive file=fat:rw:dosfiles/ -boot order=c

```

一旦你引导进入 FreeDOS，你保存在 `D:` 驱动器中的任何文件将被保存到 Linux 上的 `dosfiles/` 文件夹中。可以从 Linux 上很容易地直接去读取该文件；然而，必须注意的是，启动 QEMU 后，不能从 Linux 中去改变 `dosfiles/` 这个文件夹。 当你启动 QEMU 时，QEMU 一次性构建一个虚拟的 FAT 表，如果你在启动 QEMU 之后，在 `dosfiles/` 文件夹中增加或删除文件，仿真程序可能会很困惑。


我使用 QEMU 像这样运行一些我收藏的 DOS 程序， 比如 As-Easy-As 电子表格程序。这是一个在上世纪八九十年代非常流行的电子表格程序，它和现在的 Microsoft Excel 和 LibreOffice Calc 或和以前更昂贵的 Lotus 1-2-3 电子表格程序完成的工作是一样的。 As-Easy-As 和 Lotus 1-2-3 都保存数据为 WKS 文件，最新版本的 Microsoft Excel 不能读取它，但是，根据兼容性， LibreOffice Calc 可以支持它。


![As-Easy-As spreadsheet program](/data/attachment/album/201710/31/214642h4cgh0e8klxu0lda.png "As-Easy-As spreadsheet program")


*As-Easy-As 电子表格程序*


我也喜欢在 QEMU中引导 FreeDOS 去玩一些收藏的 DOS 游戏，比如原版的 Doom。这些老的 DOS 游戏玩起来仍然非常有趣， 并且它们现在在 QEMU 上运行的非常好。


![Doom](/data/attachment/album/201710/31/214643zunqji9tx9hyblul.png "Doom")


*Doom*


![Heretic](/data/attachment/album/201710/31/214644vyzlp3767uub5c6u.png "Heretic")


*Heretic*


![Jill of the Jungle](/data/attachment/album/201710/31/214644ozgp1yyue8u460on.png "Jill of the Jungle")


*Jill of the Jungle*


![Commander Keen](/data/attachment/album/201710/31/214644tnny43c8zn6o04qo.png "Commander Keen")


*Commander Keen*


QEMU 和 FreeDOS 使得在 Linux 上运行老的 DOS 程序变得很容易。你一旦设置好了 QEMU 作为虚拟机仿真程序并安装了 FreeDOS，你将可以在 Linux 上运行你收藏的经典的 DOS 程序。


*所有图片要致谢 [FreeDOS.org](http://www.freedos.org/)。*




---


作者简介：


Jim Hall 是一位开源软件的开发者和支持者，可能最广为人知的是他是 FreeDOS 的创始人和项目协调者。 Jim 也非常活跃于开源软件适用性领域，作为 GNOME Outreachy 适用性测试的导师，同时也作为一名兼职教授，教授一些开源软件适用性的课程，从 2016 到 2017， Jim 在 GNOME 基金会的董事会担任董事，在工作中， Jim 是本地政府部门的 CIO。




---


via: <https://opensource.com/article/17/10/run-dos-applications-linux>


作者：[Jim Hall](https://opensource.com/users/jim-hall) 译者：[qhwdw](https://github.com/qhwdw) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
The classic DOS operating system supported a lot of great applications: word processors, spreadsheets, games, and other programs. Just because an application is old doesn't mean it's no longer useful.

There are many reasons to run an old DOS application today. Maybe to extract a report from a legacy business application. Or to play a classic DOS game. Or just because you are curious about "classic computing." You don't need to dual-boot your system to run DOS programs. Instead, you can run them right inside Linux with the help of a PC emulator and [FreeDOS](http://www.freedos.org/).

FreeDOS is a complete, free, DOS-compatible operating system that you can use to play classic DOS games, run legacy business software, or develop embedded systems. Any program that works on MS-DOS should also run on FreeDOS.

In the "old days," you installed DOS as the sole operating system on a computer. These days, it's much easier to install DOS in a virtual machine running under Linux. [QEMU](https://www.qemu.org/) (short for Quick EMUlator) is an open source software virtual machine system that can run DOS as a "guest" operating system Linux. Most popular Linux systems include QEMU by default.


Here are four easy steps to run old DOS applications under Linux by using QEMU and FreeDOS.

## Step 1: Set up a virtual disk

You'll need a place to install FreeDOS inside QEMU, and for that you'll need a virtual **C:** drive. In DOS, drives are assigned with letters—**A:** and **B:** are the first and second floppy disk drives and **C:** is the first hard drive. Other media, including other hard drives or CD-ROM drives, are assigned **D:**, **E:**, and so on.

Under QEMU, virtual drives are image files. To initialize a file that you can use as a virtual **C: **drive, use the **qemu-img** command. To create an image file that's about 200MB, type this:

`qemu-img create dos.img 200M`


Compared to modern computing, 200MB may seem small, but in the early 1990s, 200MB was pretty big. That's more than enough to install and run DOS.

## Step 2: QEMU options

Unlike PC emulator systems like VMware or VirtualBox, you need to "build" your virtual system by instructing QEMU to add each component of the virtual machine. Although this may seem laborious, it's really not that hard. Here are the parameters I use to boot FreeDOS inside QEMU:

|
QEMU can emulate several different systems, but to boot DOS, we'll need to have an Intel-compatible CPU. For that, start QEMU with the i386 command. |

|
I like to define a virtual machine with 16MB of memory. That may seem small, but DOS doesn't require much memory to do its work. When DOS was king, computers with 16MB or even 8MB were quite common. |

|
Technically, the -k option isn't necessary, because QEMU will set the virtual keyboard to match your actual keyboard (in my case, that's English in the standard U.S. layout). But I like to specify it anyway. |

|
Every classic PC provides a real time clock (RTC) so the system can keep track of time. I find it's easiest to simply set the virtual RTC to match your local time. |

|
If you need sound, especially for games, I prefer to define QEMU with SoundBlaster16 sound hardware and AdLib Music support. SoundBlaster16 and AdLib were the most common sound hardware in the DOS era. Some older programs may use the PC speaker for sound; QEMU can also emulate this. |

-device cirrus-vga |
To use graphics, I like to emulate a simple VGA video card. The Cirrus VGA card was a common graphics card at the time, and QEMU can emulate it. |

|
For the virtual display, I set QEMU to use the GTK toolkit, which puts the virtual system in its own window and provides a simple menu to control the virtual machine. |

-boot order= |
You can tell QEMU to boot the virtual machine from a variety of sources. To boot from the floppy drive (typically A: on DOS machines) specify order=a. To boot from the first hard drive (usually called C:) use order=c. Or to boot from a CD-ROM drive (often assigned D: by DOS) use order=d. You can combine letters to specify a specific boot preference, such as order=dc to first use the CD-ROM drive, then the hard drive if the CD-ROM drive does not contain bootable media. |


## Step 3: Boot and install FreeDOS

Now that QEMU is set up to run a virtual system, we need a version of DOS to install and boot inside that virtual computer. FreeDOS makes this easy. The latest version is FreeDOS 1.2, released in December 2016.

Download the FreeDOS 1.2 distribution from the [FreeDOS website](http://www.freedos.org/). The FreeDOS 1.2 CD-ROM "standard" installer (**FD12CD.iso**) will work great for QEMU, so I recommend that version.

Installing FreeDOS is simple. First, tell QEMU to use the CD-ROM image and to boot from that. Remember that the **C:** drive is the first hard drive, so the CD-ROM will show up as the **D:** drive.

`qemu-system-i386 -m 16 -k en-us -rtc base=localtime -soundhw sb16,adlib -device cirrus-vga -display gtk -hda dos.img -cdrom FD12CD.iso -boot order=d`


Just follow the prompts, and you'll have FreeDOS installed within minutes.

![Starting FreeDOS installation](https://opensource.com/sites/default/files/u128651/install1a.png)

opensource.com

![Select your keyboard layout](https://opensource.com/sites/default/files/u128651/install2_0.png)

opensource.com

![Selecting which packages to install](https://opensource.com/sites/default/files/u128651/install3.png)

opensource.com

![Rebooting after installation](https://opensource.com/sites/default/files/u128651/install4.png)

opensource.com

After you've finished, exit QEMU by closing the window.

## Step 4: Install and run your DOS application

Once you have installed FreeDOS, you can run different DOS applications inside QEMU. You can find old DOS programs online through various archives or other [websites](http://www.freedos.org/links/).

QEMU provides an easy way to access local files on Linux. Let's say you want to share the **dosfiles/** folder with QEMU. Simply tell QEMU to use the folder as a virtual FAT drive by using the **-drive** option. QEMU will access this folder as though it were a hard drive.

`-drive file=fat:rw:dosfiles/`


Now, start QEMU with your regular options, plus the extra virtual FAT drive:

`qemu-system-i386 -m 16 -k en-us -rtc base=localtime -soundhw sb16,adlib -device cirrus-vga -display gtk -hda dos.img -drive file=fat:rw:dosfiles/ -boot order=c`


Once you're booted in FreeDOS, any files you save to the **D:** drive will be saved to the **dosfiles/** folder on Linux. This makes reading the files directly from Linux easy; however, be careful not to change the **dosfiles/** folder from Linux after starting QEMU. QEMU builds a virtual FAT table once, when you start QEMU. If you add or delete files in **dosfiles/** after you start QEMU, the emulator may become confused.

I use QEMU like this to run my favorite DOS programs, like the As-Easy-As spreadsheet program. This was a popular spreadsheet application from the 1980s and 1990s, which does the same job that Microsoft Excel and LibreOffice Calc fulfill today, or that the more expensive Lotus 1-2-3 spreadsheet did back in the day. As-Easy-As and Lotus 1-2-3 both saved data as WKS files, which newer versions of Microsoft Excel cannot read, but which LibreOffice Calc may still support, depending on compatibility.

![As-Easy-As spreadsheet program](https://opensource.com/sites/default/files/u128651/aseasy-regress1.png)

opensource.com

I also like to boot FreeDOS under QEMU to play some of my favorite DOS games, like the original Doom. These old games are still fun to play, and they all run great under QEMU.

![Doom](https://opensource.com/sites/default/files/u128651/qemu-doom.png)

opensource.com

![Heretic](https://opensource.com/sites/default/files/u128651/qemu-heretic.png)

opensource.com

![Jill of the Jungle](https://opensource.com/sites/default/files/u128651/qemu-jill.png)

opensource.com

![Commander Keen](https://opensource.com/sites/default/files/u128651/qemu-keen.png)

opensource.com

QEMU and FreeDOS make it easy to run old DOS programs under Linux. Once you've set up QEMU as the virtual machine emulator and installed FreeDOS, you should be all set to run your favorite classic DOS programs from Linux.

*All images courtesy of FreeDOS.org.*

## 16 Comments