Linux mkisofs Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the Linux mkisofs command, a powerful tool for creating ISO images. The mkisofs command is part of the cdrkit package, which provides a set of tools for working with CD/DVD media. We will learn how to create a basic ISO image and customize it with directories and files. The mkisofs command is used to create an ISO image file from a directory tree, which can then be burned to a CD or DVD, or used in a virtual machine or other environment.

To use the mkisofs command, we first need to install the cdrkit package. Once installed, we can create a basic ISO image by specifying the output file and the directory containing the content for the ISO. We can also customize the ISO image by adding directories and files to the content directory.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux/PackagesandSoftwaresGroup -.-> linux/apt("`Package Handling`") linux/FileandDirectoryManagementGroup -.-> linux/mkdir("`Directory Creating`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") linux/BasicFileOperationsGroup -.-> linux/touch("`File Creating/Updating`") subgraph Lab Skills linux/apt -.-> lab-422812{{"`Linux mkisofs Command with Practical Examples`"}} linux/mkdir -.-> lab-422812{{"`Linux mkisofs Command with Practical Examples`"}} linux/ls -.-> lab-422812{{"`Linux mkisofs Command with Practical Examples`"}} linux/touch -.-> lab-422812{{"`Linux mkisofs Command with Practical Examples`"}} end

Introduction to mkisofs Command

In this step, we will explore the mkisofs command, a powerful tool for creating ISO images on Linux. The mkisofs command is part of the cdrkit package, which provides a set of tools for working with CD/DVD media.

The mkisofs command is used to create an ISO image file from a directory tree. This ISO image can then be burned to a CD or DVD, or used in a virtual machine or other environment.

Let's start by installing the cdrkit package, which includes 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.

Now that we have the cdrkit package installed, we can use the mkisofs command to create an ISO image.

Creating a Basic ISO Image

In this step, we will create a basic ISO image using the mkisofs command.

First, let's create a directory that will serve as 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 create an ISO image file named basic.iso in the ~/project directory, using the contents of the ~/project/iso-content directory.

Example output:

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

The -o option specifies the output file name, and the last argument is the directory containing the files to be included in the ISO image.

Now, we can verify that the ISO image was created successfully:

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 step, we will learn how to customize the ISO image by including directories and files.

First, let's create a directory structure and some files that we want to include in 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 use the mkisofs command to create the ISO image with the custom content:

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

Here's what the various options mean:

  • -o: Specifies the output file name.
  • -V: Sets the volume label for the ISO image.
  • -p: Sets the preparer information.
  • -publisher: Sets the publisher information.
  • The last argument is the directory containing the files to be included in 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

Now, let's verify that the custom ISO image was created successfully:

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 first installed the cdrkit package, which includes the mkisofs command. Then, we created a basic ISO image by 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.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like