rar2fs on FreeNAS 9.2 embeded

This is a quick guide on how I configured rar2fs on my FreeNAS- and shared a rar2fs directory using Samba. My disk is mounted on /mnt/vol1.
Did some tests on my “a few years old hardware” and I got average file transfer speeds around 50 MB/s using cifs.


unionfs: http://forums.nas4free.org/viewtopic.php?f=72&t=210
rar2fs: https://code.google.com/p/rar2fs/

I found that fusefs-kmod and fusefs-libs packages comes with the FreeNAS embeded install – nice. The module is however not loaded by default.

This can be verified with this command:
>kldstat | grep fuse
27 1 0xffffffff81aaa000 aa63 fuse.ko
That row will not be returned by default.

Load the module with command “kldload fuse.ko”.

To be able to add the rar2fs binary to /usr/local/bin/ and the unrar library to /usr/local/lib/  you need to use unionfs.
First create a directory on your data disk which you can use to mount to /usr/local
>mkdir -p /mnt/vol1/opt/usr_local
Now mount the drive with command:
>mount_unionfs /mnt/vol1/opt/usr_local /usr/local

Note: If you also like to install ports using pkg_add , you also need create directory /mnt/vol1/opt/var and do a mount_unionfs /mnt/vol1/opt/var /var .

Now create a directory somewhere to put the source for unrar, fuse and rar2fs.
>mkdir -p /mnt/vol1/opt/build

Download the needed files.
>cd /mnt/vol1/opt/build
>wget http://www.rarlab.com/rar/unrarsrc-5.2.1.tar.gz
See: http://sourceforge.net/projects/fuse/files/fuse-2.X/ (In my case 2.9.3)
See: https://code.google.com/p/rar2fs/ (in my case 1.20.0)

Extract fuse.
>tar zxvf fuse-2.9.3.tar.gz

Compile libunrar.
>tar zxvf unrarsrc-5.2.1.tar.gz ; cd unrar
For some reason I needed to edit the makefile and make the below changes, otherwise I got some errors, not sure if it is due to differences between linux and freebsd. (Using gmake may also work but its not included in freenas embeded)

Change row 98:

Comment out these 2 rows around row number 134.

Compile and copy the unrar library.
>make lib -f makefile
If I remember correctly, I got some make error regarding missing lgcc , I solved it by creating a temporary mount like “mount_unionfs /mnt/vol1/opt/usr/lib /usr/lib” and then a “ln -s /usr/lib/libgcc_s.so /lib/libgcc-something”. Only needed when building libunrar.

>cp libunrar.so /usr/local/lib/

Now you can compile rar2fs.
>tar zxvf rar2fs-1.20.0.tar.gz ; cd rar2fs
> ./configure –with-fuse=/mnt/vol1/opt/build/fuse-2.9.3/include –with-fuse-lib=/usr/local/lib –with-unrar=/mnt/vol1/opt/build/unrar –with-unrar-lib=/usr/local/lib


>cp rar2fs /usr/local/bin/

Try if its working (don´t forget to do a kldload fuse.ko first):

>/usr/local/bin/rar2fs /mnt/vol1/path/to/your/rars/dir /mnt/vol1/rar2fs_myrars
rar2fs[90982]: mounted /mnt/vol1/rar2fs_myrars

If its not working, you can add “-o debug” to run it in debug mode.

If it is working, unmount your rarfs with “umount /mnt/vol1/rar2fs_myrars”.

Now create a startup script to run at freenas start. I added it to /mnt/vol1/opt/rar2fs.sh , dont forget to chmod 755 rar2fs.sh.
I´ve added seek-length=1 option to rar2fs for performance reasons.
The allow_other option is needed for non-root access to the file system. If you want to browse it with samba, you need this option.

echo "Loading module fuse.ko ..."
/sbin/kldload fuse.ko
echo "Mounting unionfs filesystem /mnt/vol1/opt/usr_local => /usr/local ..."
/sbin/mount_unionfs /mnt/vol1/opt/usr_local /usr/local
# Uncomment below if you want this as well.
#echo "Mounting unionfs filesystem /mnt/vol1/opt/var => /var ..."
#/sbin/mount_unionfs /mnt/vol1/opt/var /var
echo "Starting rar2fs ..."
/usr/local/bin/rar2fs --seek-length=1 -o allow_other /mnt/vol1/path/to/your/rars/dir /mnt/vol1/rar2fs_myrars

Create a init script in FreeNAS. Go to System / Add Init/Shutdown scripts.

Type: Script
Path: /mnt/vol1/opt/rar2fs.sh
Pre init

Reboot your freenas box.
You can check the console output and you should see the script output like “Starting rar2fs …” etc. (Make note of any error messages)
If your rar2fs mounts well, share it using CIFS if you like.
Note: Sharing using NFS is not working according to some forum threads, something about NFS interacts with the filesystem differently.
You can also add the rar2fs filesystem as storage to a freenas jail, like Plex 🙂

UPDATE: Someone told me that gcc isnt a part of FreeNAS 9.3 , I haven´t confirmed it myself though. Its possible to just add a compiled rar2fs executable and unrar library to a 9.3 install so I made it available in the tar archive below.
If you use these you could get by with just copying rar2fs/unrar-lib to your data disk and perhaps setting LD_LIBRARY_PATH to the correct directory before running rar2fs.

THE QUICK WAY (verified it myself on a clean 9.2 and 9.3 installation):
mkdir /mnt/vol1/opt
# Download the file below
tar xvf rar2fs-freenas9-x86_64.tar
setenv LD_LIBRARY_PATH /mnt/vol1/opt ; /sbin/kldload fuse.ko ; /mnt/vol1/opt/rar2fs –seek-length=1 -o allow_other /mnt/vol1/path/to/your/rars/dir /mnt/vol1/rar2fs_mountpoint


16 thoughts on “rar2fs on FreeNAS 9.2 embeded

  1. hasse69

    Nice post. Have never tried FreeNAS myself but there is always a time for everything…
    Some minor remark on your guide though. Your are missing the slight detail that after configuring the rar2fs package you also need to build it 😉 Also, I am really surprised you had to change the unrarsrc makefile. If possible, could you please mail me the actual errors you got and I can take a look at it or even forward it to the upstream maintainer for a possible future update. Another thing that puzzles me is the exclude of file .r[1-9]. Any particulars you would like to share? 😉


  2. goran Post author

    Hi Hasse and thanks for the feedback. Will email you details…

    “Your are missing the slight detail that after configuring the rar2fs package you also need to build it”.
    Corrected 🙂

    This is what I get with unrarsrc-5.2.1 on freenas 9.2 (FreeBSD 9.2-RELEASE-p12) when I try:
    [root@freenas] /mnt/vol1/opt/build/unrar# make lib -f makefile
    make: don’t know how to make WHAT=RARDLL. Stop

    Did some trial and error and found that changing these lines in the makefile helped:
    lib: WHAT=RARDLL
    lib: clean $(OBJECTS) $(LIB_OBJ)
    @rm -f libunrar.so
    $(LINK) -shared -o libunrar.so $(LDFLAGS) $(OBJECTS) $(LIB_OBJ)

    If I moved the first 2 rows according to my article , I could make the lib.
    Not sure why though but guessed it was freenas/make specific error.

    “Another thing that puzzles me is the exclude of file .r[1-9]”
    Just me trying to make rar2fs faster when parsing my rar library and making it only look for the .rar file and not all the part files which are named .r01 , r02 etc.
    Not sure if there any difference though, haven´t done any comparison …

  3. goran Post author

    Got some nice feedback from Hasse…

    “gmake lib” could solve the “make” issue for libunrar. gmake is however not included in freenas by default so you would need to install it first.
    EDIT: This is the error I received with “make lib” on my freenas install: “make: don’t know how to make WHAT=RARDLL. Stop”

    Plus: Using –exclude option in rar2fs for excluding all part file like .r01, r02 etc is not needed, this is what the –seek-length option is used for.
    So I removed the exclude option since it wasnt needed 🙂

  4. Mats

    Cheers for this, been trying to get this working on and off for a time now without great results. Your guide here helped me get everything up and running! Thanks and fortsätt såhär! Jävligt bra jobbat! 🙂

  5. Paul Barns

    Thanks Hasse! I’ve just come across this thread and attempting to learn from the above… will let you know how I get on 😉

    1. Paul Barns

      Attempted the quick way, and libunrar.so couldn’t be found as a shared resource, resolved that but I’m back to the same problem that I had when attempting to do it inside a jail of receiving this error:
      usr/local/bin/rar2fs: invalid source and/or mount point

      As far as I understand, the source cannot be a volume; I’m attempting to mount a folder from within a mounted volume. The mount point is a non-existing folder where I want to access the files…

      Any ideas? 🙁 Thanks!

      1. goran Post author

        Hi Paul,

        “The mount point is a non-existing folder”.

        You need to create an empty directory that you mount your rar2fs filesystem in.
        The same directory is used when sharing with samba/cifs.
        Example: /mnt/mydisk/my-rar2-mountpoint

        Does that help with the problem?

        1. Paul Barns

          Oh dear… thanks so much Goran! Such a simple thing… I’ve not been able to work that out for days haha! Much appreciated.
          Thanks again to both of you! 😀

  6. Paul Barns

    For some reason Plex does not have access to the underlying folders in the rar2fs mounts, but I’ve got that working in the past on an old Ubuntu box, so I’m sure I can do it again. The folders are appearing on the drive ok, it’s probably just a permissions thing. Thanks again Goran!

  7. hasse69

    I use plex without any special permission that I am aware of. Hope you figure it out. Otherwise just let us know.

  8. Paul Barns

    Hey Goran, Hasse69!
    Hope you’re both well? Just a quick one, my server doesn’t power off very often, but when it does, I need to run the rar2fs command manually. I can’t to do this day work out how to get it to run from within the FreeNAS tasks to get it to run after the hard drive have been initialised, with the right permissions and before the jails have started.
    I’m probably just being really dumb (again), but wondered if you guys had automated this at all…

    1. goran Post author

      Hi there,
      Everyhing is fine thanks 🙂

      A bit late reply but did you try the start script above?
      “Now create a startup script to run at freenas start. I added it to /mnt/vol1/opt/rar2fs.sh , dont forget to chmod 755 rar2fs.sh.”

  9. Paul Barns

    Hey guys,

    Quick update, I recently installed FreeNAS Corral (10).

    THE QUICK WAY is now also verified on a clean 10 installation

    🙂 Thanks again!

  10. Niklas

    OK so i had this working on my 9.3 freenas but not after upgrade to 11.0-u2. Using the rar2fs command im able to mount the rar dirs from the Freenas shell and i can check the contents of the rar files.

    When i try to share the /mnt/vol0/unrar dir with smb file share i get access denied. \\freenas\unrar is not accessible. You might not have permissions to use this network resource. Viewing the original share (not using rar2fs) at \\freenas\rar works.

    It feels like the –allow-others command is not working. Has anyone had experience with rar2fs and freenas 11?

    1. goran Post author

      Sounds like a permissions problem.
      Have you tried to do a “chmod o+rx /path/to/rar2fs-mount”

      Otherwise Im not sure what the problem could be Im afraid …


Leave a Reply

Your email address will not be published. Required fields are marked *