Automating mounting of ISO images

four.harrisons at four.harrisons at
Thu Mar 24 16:28:09 UTC 2011

On Wed, 23 Mar 2011 13:49:46 -0500, Ryan Coleman <editor at> 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:

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`

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:

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

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
freebsd-questions at mailing list
To unsubscribe, send any mail to "freebsd-questions-unsubscribe at"

More information about the freebsd-questions mailing list