How to extract an ISO image

During my recent activity I have noted to check out how to extract an ISO image in a traditional way using only shell utilities. It turned out to be easier than I thought, so I will present you three different solutions.

Extract an ISO image using p7zip

p7zip is a file archiver which supports most file-system images.

Installation and usage

This solution requires p7zip-full package.

$ sudo apt-get install p7zip-full

Now you can extract image.iso ISO image to the extracted_image directory using the following command.

$ 7z x -oextracted_image image.iso

Example

Extract debian-7.6.0-amd64-CD-1.iso ISO image to the debian_cd1 directory.

$ 7z x -odebian_cd1 debian-7.6.0-amd64-CD-1.iso
7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=pl_PL.UTF-8,Utf16=on,HugeFiles=on,4 CPUs)

Processing archive: debian-7.6.0-amd64-CD-1.iso

Extracting  .disk
Extracting  .disk/base_components
Extracting  .disk/base_installable
Extracting  .disk/cd_type
Extracting  .disk/info
Extracting  .disk/mkisofs
Extracting  .disk/udeb_include
Extracting  README.html
[..]
Extracting  tools/loadlin.txt
Extracting  win32-loader.ini
Extracting  [BOOT]/Bootable_NoEmulation.img

Everything is Ok

Folders: 852
Files: 2823
Size:       660989403
Compressed: 665845760

The [BOOT] directory

You can safely remove the [BOOT] directory as it contains Bootable_NoEmulation.img bootable image file and is not actually present inside directory tree.

Incorrect command line error

You need to remember that p7zip does not like spaces between switches and its arguments.

To visualize this problem look at the following example, then notice that space between -o switch and its output_directory argument is generating incorrect command line error.

$ 7z x -o output_directory image.iso

Error:
Incorrect command line

Extract an ISO image using xorriso

xorriso is a Swiss Army knife when it comes to ISO 9660 file-system image manipulation.

Installation and usage

This solution requires xorriso package.

$ sudo apt-get install xorriso

Now you can extract image.iso ISO image to the extracted_iso_image directory using the following command.

$ xorriso -osirrox on -indev image.iso -extract / extracted_iso_image

Example

Extract debian-7.6.0-amd64-CD-1.iso ISO image to the debian_cd1 directory.

$ xorriso -osirrox on -indev debian-7.6.0-amd64-CD-1.iso -extract / debian_cd1
xorriso 1.3.2 : RockRidge filesystem manipulator, libburnia project.

Copying of file objects from ISO image to disk filesystem is: Enabled
xorriso : NOTE : Loading ISO image tree from LBA 0
xorriso : UPDATE : 3695 nodes read in 1 seconds
xorriso : NOTE : Detected El-Torito boot information which currently is set to be discarded
Drive current: -indev 'debian-7.6.0-amd64-CD-1.iso'
Media current: stdio file, overwriteable
Media status : is written , is appendable
Boot record  : El Torito , ISOLINUX isohybrid MBR pointing to boot image
Media summary: 1 session, 325120 data blocks,  635m data, 25.3g free
Volume id    : 'Debian 7.6.0 amd64 1'
xorriso : UPDATE : 3028 files restored ( 494.9m) in 1 seconds , 374.7xD
xorriso : UPDATE : 3581 files restored ( 614.4m) in 2 seconds , 90.2xD
xorriso : UPDATE : 3695 files restored ( 630.4m) in 2 seconds = 220.0xD
Extracted from ISO image: file '/'='/home/milosz/Pobrane/debian_cd1'

Mount an ISO image and copy its contents

Solution with root privileges

This solution is the simplest one and does not require any additional utilities.

Create iso_contents directory and mount image.iso ISO image using loop device.

$ mkdir -p iso_contents
$ sudo mount -o loop image.iso iso_contents

Copy ISO image contents to desired iso_contents_copy directory.

$ mkdir iso_contents_copy
$ rsync -a -H iso_contents/ iso_contents_copy

Umount ISO image.

$ sudo umount iso_contents

You can inspect losetup utility to explore this solution further.

Solution without root privileges

This solution requires fuseiso utility which provides a module to mount ISO file-system images using FUSE.

$ sudo apt-get install fuseiso

Mount image.iso ISO image to the ~/iso_contents directory without root privileges using the following command.

$ mkdir ~/iso_contents
$ fuseiso image.iso ~/iso_contents

Verify mount point.

$ mount -l -t fuse.fuseiso | grep user=$(whoami)
fuseiso on /home/milosz/iso_contents type fuse.fuseiso (rw,nosuid,nodev,user=milosz)

Copy ISO image contents to desired iso_contents_copy directory.

$ mkdir iso_contents_copy
$ rsync -a -H ~/iso_contents/ iso_contents_copy

Umount ISO image.

$ fusermount -u ~/iso_contents

This solution can be easily scripted to mount desired ISO image without root privileges.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a system administrator working for a successful Polish company and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu