{GUIDE} How to Easily Create .CHD Files on Linux

I have been converting my game files to .chd to save storage space and clear up all the extra .bin files in my playlists on RetroArch. I had a few questions and ran into some issues while figuring this out for myself so I wanted to share my solution so people can easily find out what to do.

This was done on Linux Mint (Ubuntu based), I don’t know if it’s the same process for other non-Ubuntu based distros.

  1. Install “Mame-tools” from your package manager or elsewhere. This will allow you to use CHDman in terminal.

  2. Go to your folder that is storing the game files for your particular game/ROM in question. You’ll likely see one or more .bin files and a .cue file.

  3. Right click on the folder background and select “Open in Terminal”.

  4. Type: chdman createcd -i “name of rom (USA) (Rev 2).cue” -o "name of rom (USA) (Rev 2).chd"

4.1. -i is the input file name with a .cue suffix, not .bin. -o (the letter, not a zero) is the output name you wish to name the file with a suffix of .chd. Be sure to name it the same thing as the -i so the game will be read properly for your RetroArch playlist and boxart. You can rename the file afterwards by right clicking on it and renaming like normal if you messed it up in terminal.

4.2. I had issues in my troubleshooting of the terminal displaying this message: bash: syntax error near unexpected token `(’ This means something along the lines that you didn’t enlcose your parantheses correctly in bash. To avoid this just be sure to follow my template above and place the " in the spots I have shown.

  1. You’ll see the terminal run and see the .chd file appear in your game folder with the other files. Once the terminal is done processing you can delete all your .bin and .cue files and just keep the .chd file.

PS. Be sure your core can read .chd files and be sure the name your chose doesn’t have any typos.

1 Like

Manual conversion tutorials that explain are always welcome. So people actually learn and understand how it works. But after a while you want to have some automation.

https://github.com/thingsiplay/tochd: I wrote a Python program (Linux only) that automates a few steps for this, such as naming the output file automatically. You need Mame-tools and 7z program.

Supports .cue, .iso and even archive files. Archives such as .7z or .zip are unpacked to convert the content of it (if it contains convertable files). In example command tochd * will read all files in directory and convert all supported files to .chd with correct name, if it does not exist already.

1 Like

Very good!

I use this script that I took from a friend of the forum and added a few more things to automate.

It can be used for a single set or several sets in batch processing.

What this does is; unzip the game, delete the compressed files, convert CUE+BIN to CHDs, delete the CUE+BIN…

At the end you are left with only the CHDs with the correct names.

7z x '*.7z'; 7z x '*.zip'; unrar x '*.rar'; rm *.zip *.7z *rar; for i in *.cue; do chdman createcd -i "$i" -o "${i%cue}chd"; done; rm *.bin *.cue

PS: Obviously, if you want to decompress all these formats you need to have the compressors installed.
sudo apt install p7zip rar unrar unace zip unzip p7zip-full p7zip-rar -y

You should be careful with those lines. Because you could end up deleting archive files that do not contain any game files to convert. Or those which have subfolders in example would fail to convert, but then you already delete the archive. The second for loop uses extractcd, which will extract any chd into its parts, then delete the .chd files too. So you end up deleting all archives, cue and the chd files! If you want automatically delete files, then I recommend at least to check if the final .chd creation exist already, to make sure it was a success.

To do this correctly, it would require a rewrite. A starting point is the following, but it does nothing else than just output the input file path. To do this right it requires careful handling, so you don’t end up losing files.

#!/usr/bin/env bash

# shopt nullglob is needed, so the bottom for loop does not use *.cue literally
# as a "file", if there is no file with that extension. This is complicated to
# explain. In short it makes the for loop work as a sane people would expect to.
shopt -s nullglob

# Loop over all files with the following extensions between the {}-brackets.
for file in *.{cue,iso,7z,zip}; do
    echo "${file}"
done

I’ve gone through all of this already, that’s why I recommend my script (just a single tochd.py script).

Thank goodness you noticed. I’ve already accommodated it. This way I use it to convert multiple BINs to single BIN (DOSBox does not support multiple BINs).

I have been using this for a long time to convert folders with redump games, I don’t think I have any problems, if there is any failure, it stops in ‘done’. Now, if you have in the folder zips of all kinds, well, it does not do the magic.