Systems Administration

Merging .iso files on Debian, Ubuntu, and most likely Linux in general

Published · 1min

I hardly ever have to do this, so I can never remember precisely how to do it. Hopefully by noting it here, I won’t forget again.

Specifically, I want to do this so that I can create a single DVD image from the FreeBSD 6.3 CD images I have. Here’s more-or-less how it goes:

mount -t iso9660 -o loop disc1-mountpoint
mount -t iso9660 -o loop disc2-mountpoint
mkisofs -l -J -R -o dvd.iso disc1-mountpoint disc2-mountpoint

Don’t forget to unmount those mountpoints afterwards.

Here’s a shell script to do the work. It assumes it’s in a directory with a subdirectory called isos, which contains the source .iso images. It has no error handling, so the usual caveats apply:

#!/bin/sh

rm -rf mnt contents
mkdir mnt contents
for i in isos/*.iso; do
    mount -t iso9660 -o loop $i mnt
    cp -av mnt/* contents
    umount mnt
done

# This bit is specific to merging FreeBSD .isos.
sed -i -e 's/^CD_VOLUME = .$/CD_VOLUME = 1/' contents/cdrom.inf
sed -i -e 's/|.$/|1/' contents/packages/INDEX

mkisofs -l -J -R -o dvd.iso contents
rm -rf mnt contents

And here’s how you merge several .iso files into a single one on FreeBSD, and how to do it for FreeBSD .iso images.