How to Create CD ISO Image from Linux

Mkisofs command in Linux is used to create filesystems for writing on CD-ROM devices. The cdrecord utility will actually burn the disk. The mkisofs command prepares the files to be burnt on the medium.

Mkisofs creates an iso file, which is the image file (archive) of the optical disk.

This tutorial explains mkisofs tool in Linux to create iso image.

Using Mkisofs

According to the manual page of mkisofs command

"The mkisofs command creates a hybrid ISO9660/JOLIET/HFS filesystem with optional Rock Ridge attributes."
"mkisofs takes a snapshot of a given directory tree, and generates a binary image which will correspond to an ISO9660 or HFS filesystem when written to a block device."

ISO9660 filesystem has some limitations

• The filenames must be in 8.3 format, i.e. filename can have maximum 8 characters with 3 characters extension using uppercase letters, numbers and underscore only.

• Maximum directory depth is 8.

• File names cannot have any spaces. Maximum one dot is allowed in the file name. The directories shall not contain any dot.

While creating an iso9660 file, the filenames will be mapped as follows

• filenames are truncated to 8 characters.
• all dots in filenames except the last one are translated to underscore.
• filename version is appended to file name as ;n.
• For example, 'initrd-latest.img' will be mapped to 'initrd_l.img'.

In RRIP (Rock Ridge Interchange Protocol) extension allows

• Longer filenames (upto 255 bytes) and fewer restrictions on allowed characters (support for lowercase etc.)
• UNIX-style file modes, user ids and group ids, and file timestamps
• Support for Symbolic links and device files
• Deeper directory hierarchy (more than 8 levels)
• Efficient storage of sparse files

(From Wikipedia)

By default, mkisofs command dumps the output on the STDOUT. The output filename can be given with -o switch. A simple example of using mkisofs:

$ mkisofs -o bootiso.iso /boot
INFO: UTF-8 character encoding detected by locale settings.
Assuming UTF-8 encoded filenames on source filesystem,
use -input-charset to override.
mkisofs: Symlink /boot/grub/menu.lst ignored - continuing.
Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 4096
Path table size(bytes): 38
Max brk space used 19000
5078 extents written (9 MB)

How to List Content of ISO file

Content of an ISO file can be listed using isoinfo and extracted using p7zip.

The following command will list the content of a ISO file.

$ isoinfo -l -i bootiso.iso

The following command will extract files to 'extracted_folder' from 'bootiso.iso' file.

$ 7z x -o extracted_folder bootiso.iso

Mount ISO file on Directory

Lets mount iso file on to a directory. Run the following command:

$ mount -o loop bootiso.iso looped

The original contents of /boot directory is:

$ ls /boot/
config-2.6.18-238.el5 grub initrd-2.6.18-238.el5.img initrd-latest.img lost+found symvers-2.6.18-238.el5.gz vmlinuz-2.6.18-238.el5

The filenames are mapped as follows:

$ ls looped/
config_2.el5 grub initrd_2.img initrd_l.img lost_fou symvers_.gz system_m.el5 vmlinuz_.el5 _vmlinuz.hma

The uppercase filenames are mapped to lowercase while showing these contents.

The -R option tells mkisofs to use Rock Ridge protocol. Other useful options to mkisofs are:

-L - allow dot files (hidden)
-l - allow full 31 character filenames.
-allow-lowercase - allows lower case characters to appear in iso9660 filenames.
-allow-multidot - allows more than one dot to appear in filenames.
-input-charset - specify a character set.

Now, using these options:

$ mkisofs -l -L -input-charset default -allow-lowercase -allow-multidot -o bootiso.iso /boot
mkisofs: The option '-L' is reserved by POSIX.1-2001.
mkisofs: The option '-L' means 'follow all symbolic links'.
mkisofs: Mkisofs-2.02 will introduce POSIX semantics for '-L'.
mkisofs: Use -allow-leading-dots in future to get old mkisofs behavior.
Warning: creating filesystem that does not conform to ISO-9660.
mkisofs: Symlink /boot/grub/menu.lst ignored - continuing.
Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 4096
Path table size(bytes): 40
Max brk space used 0
5078 extents written (9 MB)
$ mount -o loop bootiso.iso looped/
$ ls -a looped/
. .. config_2.6.18_238.el5 grub initrd_2.6.18_238.el5.img initrd_latest.img lost_found symvers_2.6.18_238.el5.gz system.map_2.6.18_238.el5 vmlinuz_2.6.18_238.el5 .vmlinuz_2.6.18_238.el5.hmac

In this tutorial, we learned how to create an iso image in Linux. If you have any questions or feedback, feel free to leave a comment.

Leave a Comment