Build A Dwarf Fortress Bootable USBsenior_internBlockedUnblockFollowFollowingMar 30A few weeks ago at work, I had a project that required me to build a custom bootable Linux cd.
I had played with bootable Linux distros before, like Knoppix, DSL, Puppy Linux, Kali Linux, and others.
Often having one of these bootable distros around can be a useful tool — Knoppix, for instance, comes with a surprisingly complete set of software packages.
Others, like Kali Linux, give you a set of tools for a specific range of tasks.
Ultimately, my work project lead me to Slax, a Debian based, customizable, portable operating system.
Dwarf Fortress is a fantasy simulation game written by Tarn and Zach Adams and has been continuously improving for more than a decade.
They recently announced that they are going to release it on Steam.
You are of course free to go and get the current version of Dwarf Fortress, no bootable Linux system needed (but honestly, apart from being a fun and challenging game, where is the fun in that.
) This is not even the first time that someone has tried to build a bootable dwarf fortress USB drive.
So today, what I am going to show you how to do, is to take these two great pieces of work (Slax and Dwarf Fortress) and combine them together to build a dedicated dwarf fortress operating system.
1) Download SlaxThis step is fairly easy.
The latest version of Slax is available free for download here.
For this blog post, I have been using the file “slax-64bit-9.
2) Boot Slax in a Virtual MachineProbably the easiest virtual machine to get running is Oracle VirtualBox.
Once you have VirtualBox installed, run it and click on “New”.
It will take you through a wizard to create a new virtual machine (sometimes referred to here as a vm).
On the first page, give it a name and select Linux as the operating system.
The version doesn’t really matter a whole lot, as long as you pick a 64-bit version.
Dwarf Fortress can be a bit of a memory hog, but we are not really running it in the virtual machine here.
Still, give yourself a couple of GB of ram (we need it because we are ultimately going to save the .
iso file that we build to a ram based file system):No hard drive needed.
When you hit the “create” button, VirtualBox will warn you that you won’t be able to do much until you create a hard drive.
We’re ok with that.
So, with the vm created, we need to select the boot cd image.
Select the new vm in the left panel and hit the “Settings” gear icon.
Click on “Storage” and then click on the “empty” item with a CD icon.
This part of VirtualBox’s configuration screen can be a little confusing.
If you succeed in getting to the storage configuration screen, you should see something like this:Click on the CD icon to the right of “Optical Drive” and then click on “Choose Virtual Optical Disk Drive” in the popup menu, and navigate to the slax .
iso image that you downloaded before.
Then enable the “Live CD/DVD” checkbox.
When you are done, the storage configuration page should look like this:Hit “Ok”.
And then click on the “Start” icon to boot the vm:You may have to hit enter on the boot menu or it may boot automatically for you.
VirtualBox may give you some notifications about how the virtual machine’s keyboard and mouse interact with the host system — these are safe to close and ignore.
If everything goes well, you should boot into Slax:3) Install Dwarf FortressIn this step, we are going to prepare the virtual machine to be able to run Dwarf Fortress.
There is a slight wrinkle here, in that the dwarf fortress package we are going to install does not like it if you run it as root, but Slax Linux only has the root user out of the box, so we are going to have to set up a new user and configure the operating system for multiple users.
The first thing to note is that Slax boots into the FluxBox window manager.
To get it to do anything, you have to right click on the desktop to get a menu.
Do that, and select “Terminal”, as we are going to have to edit some files and install some things.
Slax is based on Debian, and Debian uses a tool called “apt” to install and remove software packages.
We are going to use the editor that comes with slax called “nano” to change the configuration file for where apt looks to get software packages.
In the terminal window, typenano /etc/apt/sources.
listand hit enter.
list, we need to add the linedeb http://deb.
org/debian sid main contrib non-freeThe “sid” repository for Debian holds unstable packages, one of which is the Debian maintained installer for Dwarf Fortress.
The order of the lines in sources.
list does not matter a whole lot, so I just added the line for “sid” at the end of the file.
On a side note, nano is really quite a good editor.
I have worked as a programmer for years, and have developed a relationship with many editors over time.
I am comfortable using vi, vim, emacs, atom, notepad++, visual studio code, eclipse, and many others.
Full blown integrated development environments are great when you are writing software, but when you need to get into a remote machine and edit a configuration file, you really want just a good solid text editor, and often you can not rely on bringing a bunch of configuration settings with you.
While vim and emacs are both great editors, they are often not available on a bare-bones system, but nano often is.
To me, the default key bindings for nano seem a little strange, but I have come to respect the editor and just learn them (objectively, they are certainly no stranger than those for vim or emacs).
The basics you might need for efficiently getting through your task of editing /etc/apt/sources.
list are as follows:Control-G gets you into a help screen.
Control-X gets you out of the help screen.
You can select text for cutting and copying with shift-arrow keys.
Control-K is Cut, Alt-6 is Copy, Control-U is Paste, and Control-X will ask you to save the file and exit the editor.
When you have /etc/apt/sources.
list setup, get back into the terminal and runapt updateThis will cause apt to go download the available list of packages, including the new ones in the “sid” repository.
This will take a minute or so, and it will report on its progress as it goes, ending with a message about how there are hundreds of packages that can be updated.
In another context, it would probably be a good idea to get up to date on all of those packages to avoid bugs and security vulnerabilities, but for this project, it is not necessary to have the latest of everything.
Next, we are going to use apt to install three packages (and their dependencies).
The packages are “dwarf-fortress” — the game we are trying to install, “libopenal1” — this is a sound library that will keep dwarf fortress from complaining every time it opens up, and “lxdm” — a display manager that helps with our multi-user situation.
To accomplish this, just typeapt install -y dwarf-fortress libopenal1 lxdminto the terminal window.
It will ask you a question about services, use the arrow keys to select “yes” and hit enter.
Congratulations, dwarf-fortress is now installed.
As a bonus, let’s go ahead and install a utility called “dwarf therapist”.
There are folks who assert that it is impossible to play dwarf fortress without it, so this guide would probably be incomplete without it.
Luckily, it is fairly easy to install.
Again, in the terminal, typewget https://github.
AppImage -O /usr/games/dwarf-therapistAnd thenchmod +x /usr/games/dwarf-therapist4) Set up a UserIt seems like we are there, but unfortunately, we can not run dwarf-fortress as root:To fix this, we need to add a non-privileged user.
The steps to do this are fairly simple, but we then need to make it so that the non-privileged user is logged in automatically so we can play dwarf-fortress without having to log in or anything complicated like that.
This is where lxdm comes in.
First, the user.
Run:adduser dorfand answer the questions.
I set the password to be “frod”, sort of in keeping with the Slax password of “toor” for the root user.
Next, to get it so that dorf is logged in automatically, we runlxdm-config –user dorfClick on the checkbox near “Automatic Login” and close the window.
Next, we need to do some things so that dorf’s desktop is set up appropriately.
We need to copy the .
fluxbox directory from the root user’s home to dorf’s home directory and add another file.
cp -a .
fluxbox ~dorfThen edit the “.
dmrc” file in dorf’s homenano ~dorf/.
dmrcAdd the two lines shown above to the .
dmrc file, this will make it so that lxdm will start fluxbox when dorf logs in.
Next, we need to set up menu entries for dorf to run dwarf-fortress.
Again we need to edit a file for this.
fluxbox/menuHere we have added the two lines for dwarf fortress and dwarf therapist.
Basically, I just copied the line for Terminal and replaced “xterm -ls” with the commands “/usr/games/dwarf-fortress” and “/usr/games/dwarf-therapist”.
I don’t actually know what fbstartupnotify does, but for now I am happy to remain ignorant.
After we save that file, we need to edit one more.
fluxbox/startupHere, we add the line/usr/games/dwarf-fortress &near the end of the startup file.
It should basically be the last command that gets run before the “exec fluxbox” command at the end of the file.
This will arrange it so that when dorf logs in, dwarf fortress is run automatically for him.
We could do the same with dwarf therapist, but it complains unless dwarf fortress is already running, with an actual fortress in progress, so we will just let the user start that on his own when he feels the need.
Finally, we should make sure that dorf owns all of his own fileschown dorf:dorf -R ~dorf5) Build a Bootable ISOThis is where the magic of Slax really comes to play.
We are going to save our progress in the form of a layered file system file, and then build a new .
iso file so that we can boot our game.
Saving our changes is simplesavechanges /tmp/df.
sbThis takes a minute or two.
When it is done, it reports some statistics of the new squashfs filesystem layer it built.
We then use it to build a new isogenslaxiso /tmp/df.
sbAnd that’s that.
Only, we wrote it to temporary storage on our virtual machine, so somehow we have to get it out to a place where we can use it.
There are lots of clever ways to do this, I personally have an ssh server running on my workstation, so I can use that to copy the file from the virtual machine to the real machine without having to mess around with other file transfer schemes.
6) Testing it OutIf we repeat the process of creating a virtual machine, but this time using the newly created df.
iso, we can see what it is going to look like booting up.
7) Make a Bootable USBThe final step here is to turn the df.
iso file into a bootable USB drive.
With this, you can boot it up on more or less any 64bit pc compatible machine.
And once again, Slax makes this process fairly simple.
This is going to depend a little on the operating system you are running.
You have to open the df.
iso file in an archive manager and then extract the top level “slax” directory to a newly formatted USB drive.
You then have to go to the files you just copied onto the USB drive and execute the file “slax/boot/bootinst.
bat” or “slax/boot/bootinst.
sh” (depending on whether you are on linux or windows.
) If all goes well, you will have a USB drive that you can run dwarf fortress and dwarf therapist from.
8) ConclusionPortable Linux distributions have been around for quite a while.
Slax has made it particularly easy to customize a bootable USB drive.
While making a dedicated Dwarf Fortress distribution was fun, but it may not be particularly useful.
However, understanding how to craft a custom made bootable USB with just exactly what I need on it seems like a handy skill.
.. More details