its contents, etc. Whatever your purpose, it is fairly trivial to
mount the image file and access it. The following are our host details:
HOSTS: tux (Linux), beastie (FreeBSD), snorkle (Solaris) PROMPT: host [0] OSes: CentOS 5.4 (tux) FreeBSD 8.1 (beastie) Solaris 10 (snorkle) ISO IMAGE: sol-11-exp-201011-text-x86.iso USER: rootIn each example, the following steps are performed:
0) test for and optionally create a mount point 1) if not handled automatically by the OS, create the requisite loop device associated with the image file (FreeBSD, Solaris) 2) mount the loop device to the mount point 3) verify the loop device is attached, review the files contained within the image file 4) unmount the loop device 5) if not handled automatically by the OS, remove the loop device associated with the image file (FreeBSD, Solaris)Starting things off, Linux allows you to mount an image file directly
without needing to first create the requisite loop device. The mount
command will handle this for you automatically (see note 4):
tux [0] [ ! -d /a ] && /bin/mkdir /a tux [1] /bin/mount -o loop -t iso9660 /tmp/sol-11-exp-201011-text-x86.iso /a tux [0] /bin/df -h /a Filesystem Size Used Avail Use% Mounted on /tmp/sol-11-exp-201011-text-x86.iso 479M 479M 0 100% /a tux [0] /bin/ls /a bin dev jack platform reconfigure save solaris.zlib tmp boot devices mnt proc root solarismisc.zlib system tux [0] /bin/umount /aFreeBSD, like Solaris, requires a loop device be created in order to
mount the image file. In FreeBSD 5.x and newer, 'mdconfig' is used to
create the loop device whereas in versions prior, 'vnconfig' is used.
The following uses 'mdconfig':
beastie [0] [ ! -d /a ] && /bin/mkdir /a beastie [1] /sbin/mdconfig -a -t vnode -f /tmp/sol-11-exp-201011-text-x86.iso md0 beastie [0] /sbin/mount -t cd9660 /dev/md0 /a beastie [0] /bin/df -h /a Filesystem Size Used Avail Capacity Mounted on /dev/md0 478M 478M 0B 100% /a beastie [0] /bin/ls /a .catalog dev root .cdrom devices save .image_info jack solaris.zlib .livecd-cdrom-content mnt solarismisc.zlib .volsetid platform system bin proc tmp boot reconfigure beastie [0] /sbin/umount /a beastie [0] /sbin/mdconfig -d -u 0In the final command above, '-u 0' informs 'mdconfig' which 'md' device
to work on (md0). Finally, in Solaris the process is much like that
in FreeBSD. In this case, 'lofiadm' is used to create the loop device:
snorkle [0] [ ! -d /a ] && /usr/bin/mkdir /a snorkle [0] /usr/sbin/lofiadm -a /tmp/sol-11-exp-201011-text-x86.iso /dev/lofi/1 snorkle [0] /usr/sbin/mount -F hsfs -o ro /dev/lofi/1 /a snorkle [0] /usr/sbin/df -h /a Filesystem size used avail capacity Mounted on /dev/lofi/1 478M 478M 0K 100% /a snorkle [0] /usr/bin/ls /a bin jack reconfigure solarismisc.zlib boot mnt root system dev platform save tmp devices proc solaris.zlib snorkle [0] /usr/sbin/umount /a snorkle [0] /usr/sbin/lofiadm -d /dev/lofi/1
NOTES
1. In the above a CD image is mounted, though any FS type known to the OS
could have been used (see mount man page).
2. While not explicitly set except in the Solaris example, the mount is
read only since this is an ISO image (see mount man page).
3. In all three examples, we allow the OS to decide what loop device
to use. We could control this by specifically identifying the intended
loop device:
- Linux, as an option to 'mount': mount -o loop=/dev/loop2 -t FS_TYPE /path/to/image /mount/point - FreeBSD, as an option to 'mdconfig': mdconfig -a -t MD_TYPE -f /path/to/image -u 2 - Solaris, as an option to 'lofiadm': lofiadm -a /path/to/image /dev/lofi/24. If you should want or need to manually manage the loop device handling
in Linux:
tux [0] /sbin/losetup -f /tmp/sol-11-exp-201011-text-x86.iso tux [0] /sbin/losetup -a /dev/loop0: [0808]:56918026 (/tmp/sol-11-exp-201011-text-x86.iso) tux [0] /bin/mount -t iso9660 /dev/loop0 /a tux [0] /bin/umount /a tux [0] /sbin/losetup -d /dev/loop0- to specify the intended loop device to create via losetup:
losetup /dev/loop2 /path/to/image