Automating mounting of ISO images

Polytropon freebsd at
Wed Mar 23 20:45:19 UTC 2011

On Wed, 23 Mar 2011 15:35:21 -0500, Ryan Coleman <editor at> wrote:
> Here's the working script (Yay!)
> #! /bin/sh
> for FILE in /mount/disc_images/*.iso; do
>   DIRNAME=`basename ${FILE} .iso`
>   echo ${DIRNAME} ${FILE}
>   mkdir /mount/new_brighton/images/${DIRNAME}
>   mount -t cd9660 /dev/`mdconfig -f ${FILE}`    /mount/new_brighton/images/${DIRNAME}
> done
> Thanks to Polytropon and Chuck for their guidance.

Just a little note:

Make sure you're mounting the ISOs as "-o ro" to prevent
write access to them. If users don't have +w access to
the mounted directories, you can leave out this step.
Depending on the permissions used, this might corrupt
(or at least change) the image files which may not be

If you want to omit one external program call (one per
iteration step), use DIRNAME=${FILE%.iso} instead of the
`basename ${FILE} .iso` - although it's more obvious what
DIRNAME gets designated to. :-)

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

More information about the freebsd-questions mailing list