An ISO image file is an archive of files and directories compressed using the ISO 9660 format. It is suitable for writing CD or DVD discs, sector by sector.
When you download an operating system or even some games, they give you their ISO image file. Either you can uncompress/mount them on your system or burn a CD/DVD disc using the ISO image file.
However, we have already written a detailed guide on how to mount and unmount an ISO image on Linux. Therefore, today’s focus will be on creating an ISO image file from a collection of files or media devices in Linux.
Table of Contents
How to Create an ISO Image File in Linux
In Linux, you will get two commands to create an ISO image file: dd
(abbreviation of Data Definition) and the mkisofs
command.
Does dd create an ISO image? The dd
command is commonly used for copying or converting files. However, you can use the same command to create an ISO image from a media device connected to your system, like CD/DVD discs.
What are mkisofs
used for? It is used to create an ISO image file from a bunch of files located in your system for writing to CDs or DVDs.
Prerequisite
First, you need to insert the media devices like CDs or DVDs and find the full path to these devices using the df command.
trendoceans@linux:~$ df Filesystem 1K-blocks Used Available Use% Mounted on tmpfs 810756 2028 808728 1% /run /dev/sda3 102106072 10405360 86467868 11% / tmpfs 4053768 0 4053768 0% /dev/shm tmpfs 5120 4 5116 1% /run/lock /dev/sda2 524252 5364 518888 2% /boot/efi tmpfs 810752 116 810636 1% /run/user/1001 /dev/sdb1 iso9660 2.2G 2.2G 0 100% /media/trendoceans/Ubuntu <== DVD Media
However, if you want to create an ISO image file from a group of files and directories stored on your machine, find the path to that directory using the pwd command.
Once you have the location of the file, you can continue to perform any of the below steps to create an ISO image file from a bunch of files or directories in Linux.
Using the dd command
The dd command is a utility for Linux systems that provides you with features like converting and copying files from two different sources.
On the Linux system, hardware devices or special device files (like /dev/zero
and /dev/random
) are usually mapped as system files.
The dd command has the capability to read or write these files and perform tasks such as backing up the boot sector of a hard drive.
It can also perform conversions on the data as it is copied, including byte order swapping and conversion to and from the ASCII and EBCDIC text encodings.
The same command can easily create an ISO image file from the inserted disc on your machine. Just use the following command and do not forget to replace the mount location with your own.
$ sudo dd if=/dev/sdb1 of=/home/trendoceans/Documents/ubuntu.iso
Whereas,
if
requires the mount location of the media devices (CD or DVD) instead of stdin.of
requires the location to save the ISO image file instead of stdout.
Using the mkisofs command
The mkisofs
command is used to create an ISO file from a directory containing a bunch of files that can be used to burn CDs or DVDs later.
For example, you have a directory located at /home/trendoceans/mydir/
which contains a lot of files, and you want to create an ISO image file of that directory.
For that, you can use the mkisofs
command with the -o
option, specifying the location to save the ISO file and the path of the directory containing the bunch of files, as shown below.
$ mkisofs -o ~/image.iso /home/trendoceans/mydir/
$ ls -lah image.iso
Below is the output of the above command.
These are the two methods used to create an ISO image file from the command line. However, if you have any queries regarding the topic, feel free to comment.
Innovative tech mind with 12 years of experience working as a computer programmer, web developer, and security researcher. Capable of working with a variety of technology and software solutions, and managing databases.