Mounting an ISO and extracting files from it. Command line techniques.
Loopmount an ISO without administrative privileges
Users seeking to view the contents of an ISO file or copy a file from it are frequently advised to mount the ISO with
mount -o loop example.iso /mnt
There are two aspects of this advice to consider:
* The command requires root privileges, which the user might not have. * Why invoke a root privilege (if available) when it is unnecessary?
The following programs allow loopmounting without administrative privileges.
apt-get install udisks2
The package contains the udisksctl program. The command
udisksctl loop-setup -f example.iso
attaches the ISO to a loop device in /dev. Logging out and back in again might be necessary to have success with this command as a user.
ls -l /dev/loop*
brw-rw---- 1 root disk 7, 0 Nov 16 15:14 /dev/loop0 brw-rw---- 1 root disk 259, 2 Nov 16 15:14 /dev/loop0p1 brw-rw---- 1 root disk 259, 3 Nov 16 15:14 /dev/loop0p2 brw-rw---- 1 root disk 7, 1 Nov 16 15:19 /dev/loop1 brw-rw---- 1 root disk 7, 2 Nov 16 15:14 /dev/loop2 brw-rw---- 1 root disk 7, 3 Nov 16 15:14 /dev/loop3 brw-rw---- 1 root disk 7, 4 Nov 16 15:14 /dev/loop4 brw-rw---- 1 root disk 7, 5 Nov 16 15:14 /dev/loop5 brw-rw---- 1 root disk 7, 6 Nov 16 15:14 /dev/loop6 brw-rw---- 1 root disk 7, 7 Nov 16 15:14 /dev/loop7 crw-rw---- 1 root disk 10, 237 Nov 16 15:14 /dev/loop-control
The ISO can be mounted and unmounted with the commands
udisksctl mount -b /dev/loop0p1 udisksctl unmount -b /dev/loop0p1
The mount point is at /media/$USER.
Unmounting still leaves example.iso associated with /dev/loop0. To unattach the device do
udisksctl loop-delete /dev/loop0
udisks2 appeared in Debian 8 (Jessie).
Intended as a udisks2 replacement but udevil can co-exist with it and will work to mount an ISO with or without its recommended packages.
udevil mount example.iso
udevil unmount example.iso
work out of the box. The mount point is in /media.
udevil appeared in Debian 8 (Jessie) but has been backported to Debian 7 (Wheezy).
archivemount example.iso iso/
fusermount -u iso/
Create the directory iso in the home directory ($HOME) and mount the iso with
fuseiso9660 example.iso iso/
fusermount -u iso/
fuseiso9660 deals only with the basic ISO9660 format (see the manual) so filenames are limited to uppercase and eight characters.
Viewing the contents of an ISO
Mounting the ISO and following up with
ls -l <mount_point>
is one method of seeing what the structure of the ISO and what it contains. However, there is a number of programs which will allow examination of the contents of an ISO archive without having to mount it and without administration rights.
A Jessie netinst ISO will be used as an example image in what follows.
bsdtar is a tar implemenation which can view the contents of various archive files, including ISO 9660 images. It can also extract files from the image. For a basic view of the contents of an ISO image do
bsdtar -tf debian-8.2.0-i386-netinst.iso
A detailed view would be obtained with
bsdtar -tvf debian-8.2.0-i386-netinst.iso
To look at a particular directory in the archive there is
bsdtar -tf debian-8.2.0-i386-netinst.iso pool/main/a
xorriso is a versatile program which manipulates ISO 9660 filesystem images. It can also extract files from the image.
Commands which correspond to the ones for bsdtar are
xorriso -indev debian-8.2.0-i386-netinst.iso -ls xorriso -indev debian-8.2.0-i386-netinst.iso -lsl xorriso -indev debian-8.2.0-i386-netinst.iso -ls pool/main/b
For basic listing:
isoinfo -J -l -i debian-8.2.0-i386-netinst.iso
For long listing:
isoinfo -J -f -i debian-8.2.0-i386-netinst.iso
7z l debian-8.2.0-i386-netinst.iso
gives a file listing of the archive.
Extraction of files from an ISO
If debian-8.2.0-i386-netinst.iso has been mounted and it is desired to have all the deb and udeb files copied to other media it should be sufficient to do
cp -a /media/<mount_point>/pool/main DESTINATION
Without mounting, all the programs mentioned above are capable of extracting the same files. The relevant commands are:
bsdtar -C DESTINATION -xf debian-8.2.0-i386-netinst.iso pool/main xorriso -osirrox on -indev debian-8.2.0-i386-netinst.iso -extract pool/main DESTINATION isoinfo -J -x /pool/main/a/adduser/adduser_3.113+nmu3_all.deb -i debian-8.2.0-i386-netinst.iso > DESTINATION/adduser_3.113+nmu3_all.deb 7z x -oDESTINATION -i\!pool/main debian-8.2.0-i386-netinst.iso
isoinfo only extracts single files and will display a file on stdin (possibly the screen) if it is not redirected somewhere.
7z doesn't like spaces between an option and its argument. Also, the bash shell sees ! as having a special meaning to it. This meaning can be removed by preceding ! with a backslash.