FreeNAS 9.10 Setup Notes

I’m not yet sure if I will update this post with future notes, or if I will make new posts and turn this into a series of posts…

Switching from Synology DiskStation to FreeNAS

A few weeks ago I noticed that my Synology NAS (the DS716+ II unit) was running low on available space. As this device only has 2 bays, both of which are occupied with 3TB HDDs (using Synology’s Hybrid RAID), I figured it would be wiser to acquire new enclosure with more bays, rather than to swap in larger HDDs and have to mount the current drives somewhere else to facilitate the data transfer.

However, I couldn’t bring myself to spend hundreds of dollars on a pre-made device with such under-powered hardware, and I definitely couldn’t justify spending $1000.00 (or more) on the few devices that better aligned with my hardware requirements.

So I spent many nights researching both hardware and software for a DIY NAS. I may post my actual NAS build at some point, but this post is specifically for documenting some of the nuances I encountered with FreeNAS (which is what I have currently elected to use on my DIY NAS).

Enabling SSH (and Mounting the FreeNAS Filesystem)

I sincerely hope this is just a bug with FreeNAS 9.10, but for me, simply enabling the SSH service didn’t actually allow me to connect via SSH to the box. Using the shell tool built into the FreeNAS Web GUI, I found that sshd wasn’t running (service sshd status).

So I had to manually enable sshd by adding sshd_enable="YES" to the /etc/rc.conf file. After that I could SSH into my NAS and everything seemed fine. Upon rebooting the machine, though, SSH was once again disabled, and the /etc/rc.conf file no longer had my addition to enable sshd. What gives?!

It turns out you have to mount the FreeNAS filesystem root in write mode before making changes to the system files. So here’s what I had to do:

mount -uw /
nano /etc/rc.conf    # or whatever your editor of choice is, as long as it isn't vim...

Bottom line: if you are going to modify any files from the FreeNAS filesystem, make sure you mount it first. Even though you can see and modify the files, they are reset when the system reboots.

User Storage and “Dynamic” Windows Shares (via SMB)

This caused me tremendous headache, and, to be honest, my solution may not be complete (or secure).

What I wanted to do was share each user’s home directory to Windows, but do so with a “dynamic” mount point. Synology DiskStation exposes this functionality very simply, and I have found it to be tremendously useful for a network with a handful of users.

What I wanted:

Any user on the network could mount \\ [SERVER_NAME] \ Home (spaces added for legibility) as a network drive in Windows, and have that automatically point to their own home directory on the NAS with write permissions.

After searching the Internet, I realized that most guides and forum posts where for FreeNAS 9.3 or earlier, which utilized CIFS for the Windows shares. Unfortunately, FreeNAS 9.10 uses Samba instead, and the configuration is notably different.

So here’s a step-by-step of what I have done. Some of these steps may be unnecessary, but none of them are counter-productive (as best I can tell).

  1. Create a dataset for the home(s) root directory
    • Example path: / mnt / [POOL_NAME] / [DATASET_NAME] / homes (spaces added for legibility)
    • I used a Unix share type, as at least my own user would be using the same directory in Linux and Windows
  2. Create a dataset for each user under the home(s) dataset
    • The dataset name should match the user’s Windows username
    • Example path: / mnt / [POOL_NAME] / [ROOT_DATASET_NAME] / homes / [USERNAME] (spaces added for legibility)
    • I again used a Unix share type for these directories
  3. Create a “users” group
  4. Create a user for each person who will be accessing the NAS
    • I left the primary group as their username (typical for Linux), and added them to the “users” group as an auxiliary
    • The username must match their username from Windows, unless you want to create more headache down the road…
    • Point their home directory to the directory you created in step 2
  5. Back under the storage section, ensure the home(s) dataset has the following permission settings:
    • Apply Owner: checked
    • Owner (user): root
    • Apply Group: checked
    • Owner (group): users
    • Apply Mode: checked
    • Mode (check the following):
      • Read: Owner, Group, Other
      • Write: Owner, Group
      • Execute: Owner, Group, Other
    • Permission Type: Unix
  6. Now ensure each of the datasets for your users have the following permission settings:
    • Apply Owner: checked
    • Owner (user): [username]
    • Apply Group: checked
    • Owner (group): [username]
    • Apply Mode: checked
    • Mode (check the following):
      • Read: Owner, Group, Other
      • Write: Owner, Group
      • Execute: Owner, Group, Other
    • Permission Type: Unix
  7. Create a new Windows (SMB) Share as follows
    • Path: select the home(s) folder from step 2
      • Example path: / mnt / [POOL_NAME] / [DATASET_NAME] / homes (spaces added for legibility)
    • Use as home share: UNCHECKED
      • This is what threw me for a long time, as normally you would want to check this box, but doing so has several caveats
    • Name: Home
      • Whatever value you use here will be the “folder” of the network path used in Windows
      • Do NOT use “homes” as that is a special value in Samba that will have some unwanted results
    • Apply Default Permissions: checked
    • Browsable to Network Clients: checked
    • Allow Guest Access: UNCHECKED
      • You don’t want someone to be able to access a different user’s stuff, do you?
    • Auxiliary Parameters:
      • valid users = %U
        path = %H
  8. Wait for the Samba service to restart (or manually restart it using service samba_server restart via shell/SSH)
  9. On a Windows machine, access \\ [SERVER_NAME] \ Home (removing the spaces I added for legibility)
    • Assuming your Windows username matches one of the users you setup in FreeNAS, you should be taken to “your” home directory, and you should be able to create, update, and delete files and folders

The Resulting Samba Configuration

Your /etc/local/smb4.conf file should end up with an entry like this (note the 2 bottom lines):

[Home]
    path = /mnt/my-pool/data/homes
    comment = Home Directories
    printable = no
    veto files = /.snapshot/.windows/.mac/.zfs/
    writeable = yes
    browseable = yes
    shadow:snapdir = .zfs/snapshot
    shadow:sort = desc
    shadow:localtime = yes
    shadow:format = auto-%Y%m%d.%H%M-1m
    shadow:snapdirseverywhere = yes
    vfs objects = shadow_copy2 zfs_space zfsacl streams_xattr aio_pthread
    hide dot files = yes
    guest ok = no
    nfs4:mode = special
    nfs4:acedup = merge
    nfs4:chown = true
    zfsacl:acesort = dontcare
    valid users = %U
    path = %H

The Important Pieces

  • Don’t use the “Use as home share” option for your Windows (SMB) Share of the home(s) directory, as that exposes folders for each user to the network (as well as an extra “homes” folder), and doesn’t seem to correctly set access permissions.
  • Use the Auxiliary Parameters I provided above for the Windows (SMB) Share of the home(s) directory.
    • These values remap the path to the connecting user’s home directory (instead of exposing the parent home(s) directory to everyone) and ensures that user is given access.
  • Don’t just manually add an entry to the /etc/local/smb4.conf file, as the FreeNAS Web GUI doesn’t seem to pick those up (which means you can end up with duplicate entries). Always create a new share via the FreeNAS Web GUI and just add your auxiliary Samba configs there.

PHP: Implode a Multidimensional Array

I can’t image this is a common problem, but I recently needed to implode a multidimensional array into all possible combinations for a side project. Since I may need to use this again (or maybe someone else needs something similar), I thought I would post my solution here and attempt to explain it. I also put together a live demo; you might want to check it out before reading the rest of this post.

Final Result

Here is the final result for anyone just looking for the code:

function multidimensional_implode($glue, $pieces) {
    $total = 1;
    foreach ($pieces as $piece)
        $total *= count($piece);

    $variations = array_fill(0, $total, array_fill(0, count($pieces), null));

    foreach ($pieces as $j => $piece) {
        $step = ceil((count($variations) / count($piece)) / (pow(count($piece), $j)));
        for ($i = 0; $i < count($variations); $i++) {
            $k = (floor($i / $step) % count($piece));
            $variations[$i][$j] = $pieces[$j][$k];
        }
    }

    foreach ($variations as $i => $variation)
        $variations[$i] = implode($glue, $variation);

    return $variations;
}

Now that the copy-pasters have their code, the rest of us can dive in.

Continue reading “PHP: Implode a Multidimensional Array” →

Sublime Text 3: Markdown and Live Reload

Recently I have started using the Markdown syntax for all of my notes, to-do lists, etc. due to the readability it offers (not to mention I have been using a similar syntax of my own for years). Obviously one of the biggest perks to using Markdown is that you can quickly generate an HTML document from it for a more polished presentation.

I have also been using Sublime Text for well over a year now, and I absolutely love it. I consider it to be a Vim/Notepad++ hybrid, bringing nearly all of my favorite features (more on that later…) from both together into one editor. Today I wanted to try using Markdown to actually generate an entire webpage, and I quickly realized that I would like to live preview my changes in a browser; enter the Markdown Preview and LiveReload packages.

Setup for this was actually very simple, except for one oversight that took me far too long to resolve…

Continue reading “Sublime Text 3: Markdown and Live Reload” →

The Five Stages of Insomnia

I actually wrote most of this a few nights ago when I was unable to sleep (shock, I know). The nearly exclusive reason for my occasional insomnia is that my brain is not ready to let me sleep, despite the rest of my body eagerly waiting rest. So there I was, not sleeping, when I realized over the last hour or so I had transitioned through several “phases.” Thinking back on those “phases,” I realized they were noticeably similar to the infamous Five Stages of Grief. Coincidence or not, I had to document my observations.

Stage 1: Denial

The denial stage is not so much about denying you are unable to obtain sleep. Instead, it occurs prior to the lack of obtaining sleep; specifically, when you decide to go to bed for various reasons other than you are literally falling asleep. Perhaps you have to be up earlier than normal the following day, or maybe it is fast approaching 2:15 AM and society tells us that we should be asleep at this time (unless you work a night shift, or you play video games). Regardless of the reason you decide to go to bed, it is not a good enough reason. This is denial, as it relates to insomnia.

Stage 2: Anger

At this point you are lying in your bed (or hanging from the rafters if conventional beds are too cliché for you). You realize you are not sleeping, primarily because you are able to realize you are not sleeping. A few minutes later you grumpily change your position in bed (or face a new wall, for you rafter-dwellers). The anger is slowly building inside you; a few more useless sleeping position adjustments and you may as well be a Sith apprentice.

“Come on,” you angrily think to yourself. “I need to be up in 4 hours. At this rate I will be lucky if I get a solid 3 hours of sleep.” Your anger has caused you to preclude the possibility of falling asleep this very instant, and instead have made the assumption that your lack of rest will continue for a while longer, but hopefully not more than another 60 minutes.

Eventually the anger passes, but you are still left awake.

Continue reading “The Five Stages of Insomnia” →

Pedestrian Roadkill

Maybe it’s just me, but don’t most pedestrians seem like morons around motor vehicles? Perhaps their self-preservation instincts shut off when they are walking in and around traffic. It seems abundantly obvious that motor vehicles should always have the right of way, given that in the event of a collision, people on foot stand no chance against automobiles. I understand that there are many situations where, by law, car traffic must yield to foot traffic, but I am speaking in regards to the people who will cross a street without even looking to see if the surrounding vehicles are yielding to them.

Where I come from, it doesn’t matter if you, as the pedestrian, have the right of way or not: you always check to make sure you won’t be hit before crossing in front of traffic. And not only do you stop and check, but you wave towards any vehicles that stopped for you, even if traffic laws dictate they stop for pedestrians. Your wave is a simple, polite way of saying, “Thank you for not running me the **** over.

Continue reading “Pedestrian Roadkill” →

Twenty Twelve

That just rolls off the tongue, doesn’t it? Not like 2011, which often came out as “twen’y ‘leven” if you were unwilling to take the time to say “two thousand eleven.” Say it one more time, now that you are thinking about your enunciation: 2012.

Despite that heart-warming moment we just shared, I am not writing a post solely on how easy it is to say 2012. I actually set out to write my first actual blog post, ever; it just so happens that this is also my first post of the year 2012, hence the title. It feels good to be writing something, but I am already feeling slightly overwhelmed. It’s not so much the act of writing; it’s actually just the idea that I need to organize my thoughts. Typically my thought process is chaotic at best, so I imagine my first few posts will seem at least slightly scatter-brained. I think most people’s thought process is that way, but they either don’t admit it, or they don’t realize it.

Continue reading “Twenty Twelve” →