Re: Automating mounting of ISO images
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 3/23/11 2:49 PM, Ryan Coleman 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?) 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. Hi Ryan, You can put something like this in /etc/rc.conf to get the device files created automatically: mdconfig_md0=-t vnode -f /mount/disc_images/Image1.iso mdconfig_md1=-t vnode -f /mount/disc_images/Image2.iso mdconfig_md2=-t vnode -f /mount/disc_images/Image3.iso Because these devices (/dev/md0, /dev/md1, /dev/md2) will be created before /etc/fstab is processed, you can then add the following entries in that file: /dev/md0/mount/office_files/images/Image1cd9660ro00 /dev/md1/mount/office_files/images/Image2cd9660ro00 /dev/md2/mount/office_files/images/Image3cd9660ro00 Check out the rc(8) man page (http://bit.ly/fuwn5n) for more information about how the startup scripts work, as well as the one that processes the device creation directives above - /etc/rc.d/mdconfig Finally, you can always add your own custom startup scripts to /usr/local/etc/rc.d if you need to do something that the standard startup scripts can't handle. Hope that helps, Greg - -- Greg Larkin http://www.FreeBSD.org/ - The Power To Serve http://www.sourcehosting.net/ - Ready. Set. Code. http://twitter.com/sourcehosting/ - Follow me, follow you -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk2KTn4ACgkQ0sRouByUApCAiwCfZzO8jnaKIFxuOoZotU8Ac49I MMIAni1KMFDqLe1YeMaS/LZUsgrV1PfY =JUk3 -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Wed, 23 Mar 2011 13:49:46 -0500, Ryan Coleman edi...@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, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Automating mounting of ISO images
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?) 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. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
Hi-- On Mar 23, 2011, at 11:49 AM, Ryan Coleman wrote: 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 might do (untested, though): #! /bin/sh for FILE in /mount/disc_images/*; do DEST=$FILE:r mount -t cd9660 /dev/`mdconfig -f ${FILE}` /mount/office_files/images/${DEST} done Might need to add quotes if you have spaces or other unusual characters in your ISO filenames Regards, -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Wed, 23 Mar 2011 13:49:46 -0500, Ryan Coleman edi...@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, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 3/23/11 2:49 PM, Ryan Coleman 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?) 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. Hi Ryan, You can put something like this in /etc/rc.conf to get the device files created automatically: mdconfig_md0=-t vnode -f /mount/disc_images/Image1.iso mdconfig_md1=-t vnode -f /mount/disc_images/Image2.iso mdconfig_md2=-t vnode -f /mount/disc_images/Image3.iso Because these devices (/dev/md0, /dev/md1, /dev/md2) will be created before /etc/fstab is processed, you can then add the following entries in that file: /dev/md0/mount/office_files/images/Image1cd9660ro00 /dev/md1/mount/office_files/images/Image2cd9660ro00 /dev/md2/mount/office_files/images/Image3cd9660ro00 Check out the rc(8) man page (http://bit.ly/fuwn5n) for more information about how the startup scripts work, as well as the one that processes the device creation directives above - /etc/rc.d/mdconfig Finally, you can always add your own custom startup scripts to /usr/local/etc/rc.d if you need to do something that the standard startup scripts can't handle. Hope that helps, Greg - -- Greg Larkin http://www.FreeBSD.org/ - The Power To Serve http://www.sourcehosting.net/ - Ready. Set. Code. http://twitter.com/sourcehosting/ - Follow me, follow you -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk2KTn4ACgkQ0sRouByUApCAiwCfZzO8jnaKIFxuOoZotU8Ac49I MMIAni1KMFDqLe1YeMaS/LZUsgrV1PfY =JUk3 -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
We're close on this (thanks for the push). It wants to load the entire path up in ${DEST} which is not ideal but I can live with that. I am also trying to make the directories right before the attempt to mount the image (a 'duh' moment just now). So I'd like to have just the filename, not the full path, made as a folder... In other news: The ISOs are all made by me, so no special chars, just capital and lowercase letters, sometimes numbers, no spaces and use of underscores and hyphens. thanks! On Mar 23, 2011, at 2:11 PM, Chuck Swiger wrote: Hi-- On Mar 23, 2011, at 11:49 AM, Ryan Coleman wrote: 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 might do (untested, though): #! /bin/sh for FILE in /mount/disc_images/*; do DEST=$FILE:r mount -t cd9660 /dev/`mdconfig -f ${FILE}` /mount/office_files/images/${DEST} done Might need to add quotes if you have spaces or other unusual characters in your ISO filenames Regards, -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Wed, 23 Mar 2011 15:06:14 -0500, Ryan Coleman edi...@d3photography.com wrote: I am also trying to make the directories right before the attempt to mount the image (a 'duh' moment just now). So I'd like to have just the filename, not the full path, made as a folder... A directory. :-) In other news: The ISOs are all made by me, so no special chars, just capital and lowercase letters, sometimes numbers, no spaces and use of underscores and hyphens. Underscores and hypens are traditionally not a problem. Spaces can be and need extra attention. But as you're using PROPER filenames, it should be easy to get the target directory name from the ISO filename. The unelegant way is to use basename: DIRNAME=`basename ${FILE} .iso` Of course, there's a sh builtin for the same purpose: DIRNAME=${FILE%.iso} Adding this to the iteration list, you can easily create the directories needed prior to the mount attempt. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Mar 23, 2011, at 3:16 PM, Polytropon wrote: On Wed, 23 Mar 2011 15:06:14 -0500, Ryan Coleman edi...@d3photography.com wrote: I am also trying to make the directories right before the attempt to mount the image (a 'duh' moment just now). So I'd like to have just the filename, not the full path, made as a folder... A directory. :-) Thank you. :-) slip of the fingers... In other news: The ISOs are all made by me, so no special chars, just capital and lowercase letters, sometimes numbers, no spaces and use of underscores and hyphens. Underscores and hypens are traditionally not a problem. Spaces can be and need extra attention. But as you're using PROPER filenames, it should be easy to get the target directory name from the ISO filename. The unelegant way is to use basename: DIRNAME=`basename ${FILE} .iso` Of course, there's a sh builtin for the same purpose: DIRNAME=${FILE%.iso} Adding this to the iteration list, you can easily create the directories needed prior to the mount attempt. I'll give this a whirl in a bit. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
Here's the working script (Yay!) #! /bin/sh for FILE in /mount/disc_images/*.iso; do DEST=$FILE 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. On Mar 23, 2011, at 3:16 PM, Polytropon wrote: On Wed, 23 Mar 2011 15:06:14 -0500, Ryan Coleman edi...@d3photography.com wrote: I am also trying to make the directories right before the attempt to mount the image (a 'duh' moment just now). So I'd like to have just the filename, not the full path, made as a folder... A directory. :-) In other news: The ISOs are all made by me, so no special chars, just capital and lowercase letters, sometimes numbers, no spaces and use of underscores and hyphens. Underscores and hypens are traditionally not a problem. Spaces can be and need extra attention. But as you're using PROPER filenames, it should be easy to get the target directory name from the ISO filename. The unelegant way is to use basename: DIRNAME=`basename ${FILE} .iso` Of course, there's a sh builtin for the same purpose: DIRNAME=${FILE%.iso} Adding this to the iteration list, you can easily create the directories needed prior to the mount attempt. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Wed, 23 Mar 2011 15:35:21 -0500, Ryan Coleman edi...@d3photography.com wrote: Here's the working script (Yay!) #! /bin/sh for FILE in /mount/disc_images/*.iso; do DEST=$FILE 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 desired. 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. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Mar 23, 2011, at 3:45 PM, Polytropon wrote: On Wed, 23 Mar 2011 15:35:21 -0500, Ryan Coleman edi...@d3photography.com wrote: Here's the working script (Yay!) #! /bin/sh for FILE in /mount/disc_images/*.iso; do DEST=$FILE 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 desired. 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. :-) I did try that once and it didn't strip the directory structure out so when basename worked I didn't mess with it too much. If we have 100+ ISOs to mount then I'll worry. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Wed, 23 Mar 2011 16:05:12 -0500, Ryan Coleman edi...@d3photography.com wrote: I did try that once and it didn't strip the directory structure out so when basename worked I didn't mess with it too much. I've just checked - you're right. While `basename` works as intended, ${%} can be applied to pure filenames only in this case. If we have 100+ ISOs to mount then I'll worry. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Mar 23, 2011, at 1:06 PM, Ryan Coleman wrote: I am also trying to make the directories right before the attempt to mount the image (a 'duh' moment just now). So I'd like to have just the filename, not the full path, made as a folder... Ah, yes-- add mkdir -p /mount/office_files/images/${DEST} before the mount command. Someone else mentioned a use of basedir command Regards, -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Wed, 23 Mar 2011 14:17:38 -0700, Chuck Swiger cswi...@mac.com wrote: Ah, yes-- add mkdir -p /mount/office_files/images/${DEST} before the mount command. Someone else mentioned a use of basedir command Prefix it with a test: [ -d /mount/office_files/images/${DEST} ] mkdir... mount... so there will be no error if the script is started for the second time (and the directories still exist), means: create them only if not yet present. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Mar 23, 2011, at 2:21 PM, Polytropon wrote: Prefix it with a test: [ -d /mount/office_files/images/${DEST} ] mkdir... mount... so there will be no error if the script is started for the second time (and the directories still exist), means: create them only if not yet present. While I agree with this suggested change from the perspective of only doing work if you actually need to do it, note that mkdir -p doesn't return an error if the directory already exists. :-) Regards, -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Automating mounting of ISO images
On Wed, 23 Mar 2011 14:24:43 -0700, Chuck Swiger cswi...@mac.com wrote: While I agree with this suggested change from the perspective of only doing work if you actually need to do it, note that mkdir -p doesn't return an error if the directory already exists. :-) You're telling this to a man who checks the results of fopen(), fgets(), fprintf() and even of fclose(). :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org