Mounting locally in FreeBSD with SSHFS
Mounting your offsite filesystem in FreeBSD
It is possible to mount your offsite filesystem as a local filesystem on your FreeBSD 6.x (or newer) system using sshfs (part of the Filesystem in Userspace, or FUSE package).
FUSE and sshfs are not available on FreeBSD 4.x or 5.x - only FreeBSD 6.x or later can use this functionality. Further, out of the box, FreeBSD 6.0-RELEASE does not contain the /usr/ports/sysutils/fusefs-sshfs port. You will need to cvsup this yourself.
This document will describe in detail the process of obtaining the fusefs-sshfs port, installing it, and using it to mount your offsite filesystem locally.
Step 1: Obtain the fusefs-sshfs port with cvsup
If you already have cvsup installed on your system, simply run these commands:
cvsup -g -L 2 /usr/share/examples/cvsup/ports-supfile -h cvsup2.freebsd.org -i ports/sysutils/fusefs-sshfs
cvsup -g -L 2 /usr/share/examples/cvsup/ports-supfile -h cvsup2.freebsd.org -i ports/sysutils/fusefs-libs
cvsup -g -L 2 /usr/share/examples/cvsup/ports-supfile -h cvsup2.freebsd.org -i ports/sysutils/fusefs-kmod
If you do not already have cvsup installed, you will need to:
# cd /usr/ports/net/cvsup-without-gui
# make install
Step 2: Port cleanup
Unfortunately, the fusefs-libs port, which is installed by fusefs-sshfs, has an error in the Makefile. This error has been confirmed in both the standard ports of 6.0-RELEASE and 6.1-RELEASE.
First, edit the file /usr/ports/sysutils/fusefs-libs/Makefile, and replace all occurances of ${REINPLACE_CMD} with the word sed
So, this block of Makefile:
post-patch:
${REINPLACE_CMD} -e 's,-lpthread,${PTHREAD_LIBS},' \
-e 's,-D_FILE_OFFSET_BITS=64,-D_FILE_OFFSET_BITS=64 ${PTHREAD_CFLAGS},' \
${WRKSRC}/fuse.pc.in
${REINPLACE_CMD} -e 's,-lpthread,${PTHREAD_LIBS},' \
${WRKSRC}/lib/Makefile.in \
${WRKSRC}/example/Makefile.in
Should look like:
post-patch:
sed -e 's,-lpthread,${PTHREAD_LIBS},' \
-e 's,-D_FILE_OFFSET_BITS=64,-D_FILE_OFFSET_BITS=64 ${PTHREAD_CFLAGS},' \
${WRKSRC}/fuse.pc.in
sed -e 's,-lpthread,${PTHREAD_LIBS},' \
${WRKSRC}/lib/Makefile.in \
${WRKSRC}/example/Makefile.in
Second, be prepared for your first attempt at `make install` in /usr/ports/sysutils/fusefs-sshfs to bomb out at the very end complaining of package registration failure for fusefs-libs.
Third, be prepared for your second attempt at `make install` to bomb out for the same reason, this time for registration failure for fusefs-kmod.
Step 3: Install
# cd /usr/ports/sysutils/fusefs-sshfs
# make install
(will possibly bomb out on package registration failure for fusefs-libs, if so, simply run `make install` again)
You will be asked, via an option checkbox, whether to use AUTOSETUP - check that box by pressing the space bar, then tab down to OK, and hit enter.
(will possibly bomb out again on package registration failure for fusefs-kmod, if so, simply run `make install` again)
Step 4: Check for loaded kernel module
The installation of the port will load the fuse.ko kernel module. You can verify this by issuing the command:
# kldstat
and seeing:
3 1 0xc3865000 b000 fuse.ko
in the output. In the future, you can load or unload the kernel module with these commands:
# kldload fuse.ko
# kldunload fuse.ko
Step 5: Mount your offsite filesystem locally
First, create a mount point:
# mkdir /mnt/synchaven
Then issue the sshfs command:
# sshfs -o idmap=user This e-mail address is being protected from spambots. You need JavaScript enabled to view it : /mnt/synchaven
NOTE: the sshfs command _must be_ run as root. Not as any other user, not through sudo. sshfs calls the mount system call, which must be run by root. Once your sshfs filesystem is mounted, however, it can be accessed by any user.
You will then be asked for your sync.synchaven.net password. After entering your password, the command will complete with no messages or indication of success, however, issuing the mount command with no arguments:
# mount
Will show you that your filesystem is indeed mounted:
/dev/fuse0 on /mnt/synchaven (fusefs, local, synchronous)
Later, you can unmount the filesystem with:
# umount /dev/fuse0
Step 6: Alternate usage
Another way you can mount your offsite filesystem with sshfs is to run:
# mount_fusefs auto /mnt/synchaven sshfs -o idmap=user This e-mail address is being protected from spambots. You need JavaScript enabled to view it :