HOWTO: Mount ISO files into a specified directory

Hey guys!

It always bugged me that when I mount an ISO/IMG file via WebGUI, and create a mount point to it under SMB Shares, I have yet another high-level folder to look at when browsing my network shares. What I wanted to do is:
* To have a 2 Directories:
- Mount point on a HDD that will contain my ISO files (e.g. \\FreeNAS\ISO\Images)
- Folder that would contain my mount points to ISO files based on category (e.g. \\FreeNAS\ISO\Mounts\Apps or \\FreeNAS\ISO\Mounts\Movies)

By default, when you mount an ISO file, you will get a folder created under /mnt/ and you will see it as \\FreeNAS\.

Here's what I did to get to the scenario explained above...

1) Install full version of FreeNAS (I don't know if this will work on an embedded install)
2) Get to the shell or to the Advanced->File Editor in your WebGUI
3) Navigate to the folder: /etc/inc and select disks.inc for editing
4) Find function called disks_mount
5) Replace:

// Set mount name
$mountname = "{$g['media_path']}/{$mount['sharename']}";

With:

// Set mount name
if ($mount['type'] == 'disk') {
  $mountname = "{$g['media_path']}/{$mount['sharename']}";
} else {
  $mountname = "{$g['media_path']}/ISOs/Mounts/{$mount['isotype']}/{$mount['sharename']}";
}

NOTE: If you want your ISOs to be mounted to a different folder, replace /ISOs/Mounts with a folder of your choice!
6) Replace:

// Create one directory for each device under /mnt
if (!@mkdir($mountname)) {
  write_log("Error: Failed to create directory {$mountname}");
}

With:

// Create one directory for each device under /mnt
if (!@mkdir($mountname, 0777, true)) {
  write_log("Error: Failed to create directory {$mountname}");
}

7) Find function called disks_umount and replace:

// Unmount mount point
  $mountname = "{$g['media_path']}/{$mount['sharename']}";

With:

// Unmount mount point
if ($mount['type'] === "disk") {
  $mountname = "{$g['media_path']}/{$mount['sharename']}";
} else {
  $mountname = "{$g['media_path']}/ISO/Mounts/{$mount['isotype']}/{$mount['sharename']}";
}

NOTE: Make sure that path to your ISO/Mounts matches that in step 5!
8) Now that we have finished working with the disks.inc file, let's update the Web interface. For that we need to navigate to /usr/local/www and open disks_mount_edit.php for editing using either nano from the shell or Web Interface.
9) Locate line that starts with: if (!$input_errors) and go to the case "iso": section.
10) At the end of the case, but before the break; add $mount['isotype'] = $_POST['isotype'];
11) Find function type_change and add showElementById('iso_type_tr','hide'); for case 0: and showElementById('iso_type_tr','show'); for case 1:
12) Locate
and after

<tr id="partitiontype_tr">
  <td width="22%" valign="top" class="vncellreq"><?=gettext("Partition type");?></td>
  <td class="vtable">
  <select name="partitiontype" class="formfld" id="partitiontype" onClick="partitiontype_change()">
    <option value="p" <?php if ($pconfig['partitiontype'] === "p") echo "selected";?>>GPT partition</option>
    <option value="s" <?php if ($pconfig['partitiontype'] === "s") echo "selected";?>>MBR partition</option>
    <option value=" " <?php if (empty($pconfig['partitiontype'])) echo "selected";?>><?=gettext("CD/DVD or Old Software RAID");?></option>
  </select><br/>
  <span class="vexpl"><?=gettext("<b>EFI GPT</b> if you want to mount a GPT formatted drive (<b>default partition since 0.684b</b>).<br><b>MBR</b> partition, for UFS formatted drive or Software RAID volume (<b>created before 0.684b</b>) or imported disks from other OS.<br><b>CD/DVD or Old software RAID</b> for old SoftwareRAID volumes (<b>created before version 0.68</b>) or CD/DVD.");?></span>
  </td>
</tr>

add the following:

<tr id="iso_type_tr">
  <td width="22%" valign="top" class="vncellreq"><?=gettext("Type of ISO (e.g. OS)");?></td>
  <td class="vtable">
    <select id="isotype" class="formfld" onclick="isotype_change()" name="isotype">
      <option value="Programs">Programs</option>
      <option value="Operating_Systems">Operating Systems</option>
      <option value="Games">Games</option>
      <option value="Movies">Movies</option>
      <option>Music</option>
   </select><br />
  </td>
</tr>

13) Save the file and exit. Next time you'll try to mount an ISO, you'll be prompted to enter ISO type!

Comments