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 article explains this mkisofs tool in Linux.


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."

The 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)

ISO file can be viewed/listed

$ ls -l bootiso.iso
-rw-r--r-- 1 root root 10399744 Dec 9 11:58 bootiso.iso

Mount ISO file On Directory

$ mount -o loop bootiso.iso looped

The original contents of /boot directory

$ 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

Bobbin Zachariah 11:25 am

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.