mkisofs is a powerful command line utility that allows you to create ISO image files from directories or optical media. An ISO image is an archive file containing the complete contents of a CD, DVD, or Blu-ray disc. The ISO image can then be mounted, allowing you to access the files as if the disc was inserted into the computer.
In this comprehensive guide, you‘ll learn how to use mkisofs to:
- Install mkisofs on Ubuntu
- Create an ISO image from a directory
- Set ISO image options like Rock Ridge and Joliet
- Allow special characters and uppercase filenames
- Mount the resulting ISO for access
- List and verify an ISO‘s contents
- Unmount and remove an ISO when finished
So if you need to back up optical discs or distribute software on Linux, mkisofs is an essential tool. Follow along below to master ISO creation and handling on Ubuntu.
Installing mkisofs
mkisofs is provided by the genisoimage package. To install on Ubuntu:
sudo apt update
sudo apt install genisoimage
This will install mkisofs and other helper utilities for working with ISO images.
Creating an ISO Image
The basic syntax for mkisofs is:
mkisofs -o output.iso input_directory
This will create an ISO image file called output.iso containing the contents of the input_directory.
For example, to make an ISO containing my backups folder:
mkisofs -o backups.iso /home/user/backups
By default this will create an ISO-9660 filesystem with support for long filenames via the Joliet extension. But additional options can customize the ISO for different uses.
Configuring Rock Ridge and Joliet Support
The ISO-9660 standard has several extensions that allow for longer filenames, UNIX permissions, symlinks and more. The most common ISO extensions are:
Joliet – Allows filenames up to 64 Unicode characters in length
Rock Ridge – Provides UNIX-style file info like permissions, ownership, symlinks
To include any extension, use the -R
option followed by the extension name. For example, to enable Rock Ridge and Joliet:
mkisofs -o disk.iso -R -J /backup/disk_image
Now the ISO image will support long filenames and retain the original file permissions and metadata.
Allowing Special Characters in Filenames
By default, ISO-9660 is limited to alphabetical characters, numbers and underscores in filenames. To allow additional symbols:
Use -allow-multidot
– Allows multiple periods in filenames
Use -l
– Enables 30 character filenames including special chars
Here is an example:
mkisofs -o disk.iso -R -J -l -allow-multidot /backup/disk_image
Now filenames with spaces, periods and other symbols will be preserved.
Preserving Case in Filenames
ISO-9660 filenames are case-insensitive, so uppercase characters get converted to lowercase. To preserve uppercase as is:
Use -allow-lowercase
– Disables converting uppercase filenames to lowercase.
Use -input-charset default
– Leaves input filenames unmodified.
For example:
mkisofs -o disk.iso -R -J -l -allow-lowercase -input-charset default /backup/disk_image
Now filenames like Backup-Clients.txt won‘t get converted to backup-clients.txt.
Mounting an ISO Image
Once the ISO image file has been created with mkisofs, you can mount it to access the contents just like a normal disk.
First create a mount point. This is an empty directory that will be used to access the ISO:
sudo mkdir /media/iso
Next, mount the ISO using the loop device interface:
sudo mount -o loop disk.iso /media/iso
The -o loop tells mount to treat the ISO file as a block device.
Now browse to /media/iso and the ISO image contents appear as files and folders. Edit, copy or view them normally.
When finished, use umount
to safely detach the ISO:
sudo umount /media/iso
Listing ISO Contents
You can view the contents of an ISO image file without needing to mount it using the isoinfo tool.
To list all files and folders in an ISO:
sudo isoinfo -l -i disk.iso
This will print out the full directory tree so you can confirm filenames, sizes other metadata before burning to disk.
Converting a Physical CD/DVD to ISO
Instead of making ISO images from directories, you can also create ISO files from optical media like CDs and DVDs.
First insert the physical disc you wish to archive as an ISO image file. Determine the block device pathname, which is typically:
/dev/cdrom
Or:
/dev/dvd
Then run mkisofs, replacing /dev/cdrom with your appropriate optical media device:
mkisofs -o cd_backup.iso /dev/cdrom
Now a complete 1:1 copy is saved in the cd_backup.iso file. You can re-burn this ISO to duplicate the CD, or mount the ISO to access the original files.
This provides a fast way to back up optical discs without needing additional tools.
Automating ISO Creation with a Bash Script
Since mkisofs works via the command line, the ISO generation process can be easily automated using a Bash script.
For example, save this script as make_iso.sh:
#!/bin/bash
# Settings
SOURCE=/home/user/backups
ISO_FILENAME=backups.iso
# Make the ISO image
mkisofs -R -J -l -allow-multidot -allow-lowercase -input-charset default -o $ISO_FILENAME $SOURCE
# List contents
isoinfo -l -i $ISO_FILENAME
# Mount the ISO
mkdir /media/iso
mount -o loop $ISO_FILENAME /media/iso
echo "ISO mounted at /media/iso"
# Add your automated tasks here...
# Unmount when done
umount /media/iso
Now whenever you run ./make_iso.sh
, this will automatically:
- Generate an ISO containing /home/user/backups
- List the ISO contents for review
- Mount the ISO to /media/iso
- Run any commands on the mounted ISO
- Unmount the ISO when finished
So with a few lines of Bash, you can simplify regularly creating and handling ISOs of a particular folder.
Conclusion
mkisofs and its related utilities give you full control over ISO image generation from the Ubuntu command line. Wrap them in scripts to automate regular backup or distribution tasks.
Some key points covered include:
- Installing mkisofs with genisoimage package manager
- Making ISO files from directories or optical media
- Configuring ISO options for long filenames, metadata support
- Allowing special characters while adhering to standards
- Mounting ISOs for access as virtual drives
- Listing an ISO manifest to validate contents
- Automating the process with BASH scripts
With this foundation you can now easily manage optical disc images for backups, software distribution and more. So give mkisofs a try and see how it can benefit your projects!