Automating mounting of ISO images

Polytropon freebsd at edvax.de
Wed Mar 23 19:20:37 UTC 2011


On Wed, 23 Mar 2011 13:49:46 -0500, Ryan Coleman <editor at d3photography.com> wrote:
> I have a folder full of ISOs that we're sharing on the
> network instead of having the discs available (seems 
> like a good idea, right?)

Please use the correct terminology: FreeBSD (as any UNIX
operating systems) calls them DIRECTORIES. "Folders" is
something else, it's not equivalent to a directory, so
"folders" is wrong.



> But I want to automate the process on boot instead of
> having to write a static script  to do the work.
> 
> Disc images are located in /mount/disc_images/ (all are ISOs)
> They need to mount into /mount/office_files/images/FILENAME
> [without the .iso extension]
> 
> How can I do this? I've always been given these types of
> scripts in the past at an old job but I don't have access
> to those examples anymore.

Something like this (not even tested, but quite verbose and
unelegant) should work:

#!/bin/sh
NODE=0
for IMAGE in /mount/disc_images/*.iso; do
	mdconfig -a -t vnode -u $NODE -f $IMAGE
	mount -t cd9660 -o ro /dev/md$NODE /mount/office_files/images/`basename $IMAGE .iso`
	NODE=`expr $NODE + 1`
done

This of course assumes that you have PROPER file names. In
case the ISO file names contain special characters, attention
has to be paid for quoting and escaping. Worth reading:

http://www.dwheeler.com/essays/filenames-in-shell.html

http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html

After reading it, you'll easily recognize that I did it wrong
in the suggestive script. :-)



I'm not sure if you can mount from ISO files directly, but
maybe you can try that too.

Remember unmounting the files when not in use (scripted: umount
and mdconfig -d).




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list