mkisofs Command in Linux

Introduction

In this tutorial, we will delve into the Linux mkisofs command, a valuable tool for systemadmin tasks involving ISO image creation. The mkisofs command is a key component of the cdrkit package, a suite of utilities designed for managing CD/DVD media. This guide will walk you through the process of creating a fundamental ISO image and tailoring it with custom directories and files. The mkisofs command effectively creates an ISO image file from a directory structure, which can subsequently be burned onto a CD or DVD, or utilized within a virtual machine environment, or other deployment scenarios.

To leverage the capabilities of the mkisofs command, our initial step involves installing the cdrkit package. Once the installation is complete, we can proceed to generate a basic ISO image by designating the output file and specifying the directory that holds the content intended for inclusion in the ISO. Furthermore, we have the flexibility to personalize the ISO image by incorporating additional directories and files into the designated content directory.

Introduction to mkisofs Command

In this section, we will explore the mkisofs command, a potent utility for generating ISO images on Linux systems. The mkisofs command resides within the cdrkit package, which encompasses a collection of tools specifically designed for interacting with CD/DVD media.

The mkisofs command serves the purpose of constructing an ISO image file from a hierarchical directory structure. This resulting ISO image can then be burned to optical media such as a CD or DVD, or employed within a virtual machine or another compatible environment. Understanding the mkisofs command is essential for any systemadmin who needs to create and manage ISO images.

Let's begin by installing the cdrkit package, which provides access to the mkisofs command:

sudo apt-get update
sudo apt-get install -y cdrkit

Example output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libfile-listing-perl libhtml-parser-perl libhtml-tagset-perl libhttp-cookies-perl libhttp-date-perl libhttp-message-perl libio-html-perl libio-socket-ssl-perl libnet-http-perl liburi-perl
Suggested packages:
  libdigest-md5-perl libdigest-sha-perl
The following NEW packages will be installed:
  cdrkit libfile-listing-perl libhtml-parser-perl libhtml-tagset-perl libhttp-cookies-perl libhttp-date-perl libhttp-message-perl libio-html-perl libio-socket-ssl-perl libnet-http-perl liburi-perl
0 upgraded, 11 newly installed, 0 to remove and 0 not upgraded.

With the cdrkit package now successfully installed, we are ready to utilize the mkisofs command to create an ISO image.

Creating a Basic ISO Image

In this segment, we will create a simple ISO image using the mkisofs command. This is a foundational skill for any systemadmin.

First, let's establish a directory that will hold the content for our ISO image:

mkdir ~/project/iso-content

Now, we can use the mkisofs command to create the ISO image:

sudo mkisofs -o ~/project/basic.iso ~/project/iso-content

This command will generate an ISO image file named basic.iso within the ~/project directory, incorporating the contents of the ~/project/iso-content directory.

Example output:

Succes - wrote /home/labex/project/basic.iso - 0 bytes, 0.000s

The -o option designates the name of the output file, while the final argument represents the directory encompassing the files destined for inclusion in the ISO image.

To confirm the successful creation of the ISO image, execute the following command:

ls -l ~/project/basic.iso

Example output:

-rw-r--r-- 1 labex labex 0 Apr 18 12:34 /home/labex/project/basic.iso

Customizing ISO Image with Directories and Files

In this section, we will explore the process of customizing the ISO image by incorporating custom directories and files. This is a crucial aspect for systemadmin tasks requiring specific content in ISO images.

First, let's construct a directory structure and create sample files that we intend to include within the ISO image:

mkdir -p ~/project/iso-content/documents
touch ~/project/iso-content/documents/file1.txt
touch ~/project/iso-content/documents/file2.txt

Now, we can utilize the mkisofs command to generate the ISO image, incorporating the custom content:

sudo mkisofs -o ~/project/custom.iso -V "My Custom ISO" -p "Labex" -publisher "Labex" ~/project/iso-content

Here's a breakdown of the command options:

  • -o: Specifies the output file name.
  • -V: Assigns the volume label to the ISO image.
  • -p: Sets the preparer information.
  • -publisher: Defines the publisher information.
  • The final argument is the directory containing the files that will be included within the ISO image.

Example output:

Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 0
Path table size(bytes): 10
Max brk space used 0
0.01% done, estimate finish Tue Apr 18 12:34:56 2023
0.02% done, estimate finish Tue Apr 18 12:34:56 2023
0.03% done, estimate finish Tue Apr 18 12:34:56 2023
[...]
100.00% done, estimate finish Tue Apr 18 12:34:56 2023
Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 0
Path table size(bytes): 10
Max brk space used 0
wrote /home/labex/project/custom.iso - 4096 blocks

To verify the successful creation of the custom ISO image, execute the following command:

ls -l ~/project/custom.iso

Example output:

-rw-r--r-- 1 labex labex 2097152 Apr 18 12:34 /home/labex/project/custom.iso

Summary

In this lab, we explored the mkisofs command, a powerful tool for creating ISO images on Linux. We began by installing the cdrkit package, which provides access to the mkisofs command. Subsequently, we created a basic ISO image using the mkisofs command to generate an ISO file from a directory. Finally, we learned how to customize the ISO image by adding directories and files to the content, making this a valuable skill for any systemadmin working with Linux.

400+ Linux Commands