Skip to content

Samba and ZFS (NFSv4) ACL settings for FreeBSD

27-Apr-11

My latest security schemees that I’ve mapped the Samba guest user to a new user “samba_guest”. I’ve made nobody the owner of public shares. I’ve removed the allow settings for the “nobody” user. I then enable everyone to read:

owner@:————–:——:deny
group@:-w-p———-:——:deny
group@:r-x———–:——:allow
everyone@:—-Dd-A-W-Co-:f—–:deny
everyone@:rwxp–a-R-c–s:-d—-:allow

Note that I’ve set up Samba with the ZFS ACL module. For each share, I’ve added the following entries:


vfs objects = zfsacl
nfs4:mode = special
nfs4:acedup = merge
nfs4:chown = yes
Be the first to like.

Crashplan running on FreeBSD

07-Apr-11


Just gathering bits of information on how to get this done:

The first set of instructions (for FreeBSD 7.x) was here:CrashPlan on FreeBSD HOWTO

This didn’t work that well on FreeBSD 8.x. There was some problem with epoll. The breakthrough came from Aaron here:

Add -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.PollSelectorProvider to the bin/run.conf for the engine.

Finally, here’s an rc.d startup script for Crashplan running on FreeBSD – 1st Byte Solutions.

When I tried starting crashplan manually, it initially had a hard time finding my /tank mount point. Seems like linux compat on FreeBSD didn’t want to mount it. I played around with a bunch of stuff, including trying out nullfs (I didn’t have that kernel module built, so I had to rebuild it). I’m not sure what I did (maybe built the nullfs module) but eventually, it was able to find my /tank mount point without doing anything fancy.

graphic of selecting files to upload, including those in /tank ZFS pool

Be the first to like.

Putting freebsd /tmp and /var on a memory disk (md)

14-Feb-11

I’ve installed a FreeBSD system using gmirror onto a couple of USB drives. I’ve noticed that there’s a considerable lag when I’m doing certain things (running top for example). I’ve narrowed it down to the /tmp and /var file systems. These two file systems get written to often during normal system operation. I’ve recently aleviated this problem using the md facility–which creates a ramdisk.

Since I’m using USB drives for the root (a d the default /tmp and /var), the write latency is higher than read latency. In addition, gmirror exacerbates this tendency.

Update 2011-03-05 (again)

I now have everything contained within /etc/fstab. /tmp exists in memory (md), /var sits on USB, but a few key subdirectories of [/var] exist in memory as well. My /etc/fstab looks like so:

I’ve commented out all the md-related lines in /etc/rc.conf:

Update 2011-03-05

I’ve since this concluded that most of FreeBSD expects certain things within /var to be persistent across boots (namely /var/db). I’ve since put /var back on my USB drives. However, I’ve followed the advice given here: http://www.cabstand.com/usbflash.html#flash_parts and set noatime on my mounts, so that a read access doesn’t require a write. The system generally seems pretty responsive. My fstab now looks like:

I may go forward and make /var/run and /var/log md files as advised in the above link.

Update 2011-02-14

The below procedure had problems with samba. Unfortunately, samba puts a bunch of stuff in /var/log/samba, /var/run/samba and /var/db/samba. Not sure why you’d want another level of indirection below each of these directories. Unfortunately, this behavior is hard-coded into the samba ports Makefile. To get around it, you can either follow the original instructions using fstab below and modify /usr/local/etc/rc.d/samba with:

[cce_bash]
samba_start_precmd() {
mkdir -p /var/log/samba /var/run/samba /var/run/samba
# XXX: Never delete winbindd_idmap, winbindd_cache and group_mapping
[/cce_bash]

Which ensures that the directories are created before samba is started. Or, you can use the method with rc.conf. Either way, you’re editing two files: A)/usr/local/etc/rc.d/samba and /etc/fstab; or B)/etc/rc.conf and /etc/fstab.

Original Instructions (using fstab)

So, moving the /tmp and /var file systems into RAM makes things go much faster. It’s pretty easy to do so. You only have to edit /etc/fstab.

Here’s my /etc/fstab:

You can see that I labeled two new USB drives (4G each) to contain swap. I called them swap0 and swap1. The memory-based file system will use swap as a backing store (it’ll spill over into the swap space if the system runs low on RAM).

Alternative method using /etc/rc.conf and /etc/fstab

Edit /etc/rc.conf to look like so:

[cce_bash]
mdconfig_md0=”-t swap -s 32m”
mdconfig_md1=”-t swap -s 512m”
mdconfig_md1_cmd=”mkdir -p /var/log/samba /var/db/samba /var/run/samba”
[/cce_bash]

This instructs rc.conf (really mdconfig and mdconfig2 startup scripts) to create a md0 of size 32 MB and md1 of size 512MB. It also runs a command to create the directories samba expects (but does not create).

Unfortunately, you also have to add entries to fstab to mount the md devices as file systems:

Fixing portsnap

One problem with the above is that portsnap tends to dump things to /var/db/portsnap. Since /var is now in a memory file system, it’ll get cleared on each reboot. Instead, I now store portsnap fetches in /usr/local/portsnap. (This is the default if you install portsnap from the ports collection, but the base install of FreeBSD includes a portsnap which stores it in /var/db/portsnap.)

To make this change, I edited /etc/portsnap.conf:

[cc_bash]
# Default directory where compressed snapshots are stored.
# WORKDIR=/var/db/portsnap
WORKDIR=/usr/local/portsnap
[/cc_bash]

2 people like this post.

Kingston DataTraveler 101 Gen 2 4GB USB 2.0 Flash Drive Speed Test

14-Feb-11

Testing these drives: Newegg.com – Kingston DataTraveler 101 Gen 2 4GB USB 2.0 Flash Drive (Cyan) Model DT101G2/4GBZ

I got them free with some RAM. Here are the results:

Be the first to like.

Re-doing Public Samba Share with FreeBSD/ZFS

01-Feb-11

This time, I’m going to to try using FreeBSD’s support for NFS ACL’s, using http://forums.freebsd.org/showthread.php?t=17627 as a reference:


server# zfs set aclmode=passthrough tank/Users
server# zfs set aclinherit=passthrough tank/Users

I created ZFS filesystems within tank/Users/Public like so:

[cce_bash]
server% cat add_pub.sh
#!/bin/sh

u=”$1″
zfs create tank/Users/$u
chown nobody:nogroup /tank/Users/$u
for d in “Documents” “Music” “Videos” “Pictures”; do
zfs create tank/Users/$u/$d
zfs set aclmode=passthrough tank/Users/$u/$d
zfs set aclinherit=passthrough tank/Users/$u/$d
chown nobody:nogroup “/tank/Users/$u/$d”
done
zfs set compression=gzip tank/Users/$u/Documents
[/cce_bash]

Note the zfs set aclmode and zfs set aclinherit lines. These prevent a calculation of effective permissions based on the umask which pretty much renders the ACL commands useless (documented here). Now, to let myself read/write/etc tank/Users/Public:


server# setfacl -m "user:Poojan:rwxp:fd:allow" /tank/Users/Public

Or, more generally:

[cce_bash]
server% cat prm_pub.sh
#!/bin/sh

u=”$1″
for d in “Documents” “Music” “Videos” “Pictures”; do
setfacl -m “user:${u}:rwxp:fd:allow” “/tank/Users/Public/$d”
done
[/cce_bash]

I’ll admit that I have no idea how this works, but it looks like it does.

For samba, here’s my smb.conf:
[cce_ini]
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# For a step to step guide on installing, configuring and using samba,
# read the Samba-HOWTO-Collection. This may be obtained from:
# http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
#
# Many working examples of smb.conf files can be found in the
# Samba-Guide which is generated daily and can be downloaded from:
# http://www.samba.org/samba/docs/Samba-Guide.pdf
#
# Any line which starts with a ; (semi-colon) or a # (hash)
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command “testparm”
# to check that you have not made any basic syntactic errors.
#
#======================= Global Settings =====================================
[global]

# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
workgroup = MYGROUP

# server string is the equivalent of the NT Description field
server string = Samba Server

# Security mode. Defines in which mode Samba will operate. Possible
# values are share, user, server, domain and ads. Most people will want
# user level security. See the Samba-HOWTO-Collection for details.
security = user

# This option is important for security. It allows you to restrict
# connections to machines which are on your local network. The
# following example restricts access to two C class networks and
# the “loopback” interface. For more examples of the syntax see
# the smb.conf man page
; hosts allow = 192.168.1. 192.168.2. 127.

# If you want to automatically load your printer list rather
# than setting them up individually then you’ll need this
load printers = yes

# you may wish to override the location of the printcap file
; printcap name = /etc/printcap

# on SystemV system setting printcap name to lpstat should allow
# you to automatically obtain a printer list from the SystemV spool
# system
; printcap name = lpstat

# It should not be necessary to specify the print system type unless
# it is non-standard. Currently supported print systems include:
# bsd, cups, sysv, plp, lprng, aix, hpux, qnx
; printing = cups

# Uncomment this if you want a guest account, you must add this to /etc/passwd
# otherwise the user “nobody” is used
; guest account = pcguest

# this tells Samba to use a separate log file for each machine
# that connects
log file = /var/log/samba/log.%m

# Put a capping on the size of the log files (in Kb).
max log size = 50

# Use password server option only with security = server
# The argument list may include:
# password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name]
# or to auto-locate the domain controller/s
# password server = *
; password server =

# Use the realm option only with security = ads
# Specifies the Active Directory realm the host is part of
; realm = MY_REALM

# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.
; passdb backend = tdbsam

# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting.
# Note: Consider carefully the location in the configuration file of
# this line. The included file is read at that point.
; include = /usr/local/etc/smb.conf.%m

# Most people will find that this option gives better performance.
# See the chapter ‘Samba performance issues’ in the Samba HOWTO Collection
# and the manual pages for details.
# You may want to add the following on a Linux system:
; socket options = SO_RCVBUF=8192 SO_SNDBUF=8192

# Configure Samba to use multiple interfaces
# If you have multiple network interfaces then you must list them
# here. See the man page for details.
; interfaces = 192.168.12.2/24 192.168.13.2/24

# Browser Control Options:
# set local master to no if you don’t want Samba to become a master
# browser on your network. Otherwise the normal election rules apply
; local master = no

# OS Level determines the precedence of this server in master browser
# elections. The default value should be reasonable
; os level = 33

# Domain Master specifies Samba to be the Domain Master Browser. This
# allows Samba to collate browse lists between subnets. Don’t use this
# if you already have a Windows NT domain controller doing this job
; domain master = yes

# Preferred Master causes Samba to force a local browser election on startup
# and gives it a slightly higher chance of winning the election
; preferred master = yes

# Enable this if you want Samba to be a domain logon server for
# Windows95 workstations.
; domain logons = yes

# if you enable domain logons then you may want a per-machine or
# per user logon script
# run a specific logon batch file per workstation (machine)
; logon script = %m.bat
# run a specific logon batch file per username
; logon script = %U.bat

# Where to store roving profiles (only for Win95 and WinNT)
# %L substitutes for this servers netbios name, %U is username
# You must uncomment the [Profiles] share below
; logon path = \\%L\Profiles\%U

# Windows Internet Name Serving Support Section:
# WINS Support – Tells the NMBD component of Samba to enable it’s WINS Server
; wins support = yes

# WINS Server – Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
; wins server = w.x.y.z

# WINS Proxy – Tells Samba to answer name resolution queries on
# behalf of a non WINS capable client, for this to work there must be
# at least one WINS Server on the network. The default is NO.
; wins proxy = yes

# DNS Proxy – tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups. The default is NO.
dns proxy = no

# Charset settings
; display charset = koi8-r
; unix charset = koi8-r
; dos charset = cp866

# Use extended attributes to store file modes
; store dos attributes = yes
; map hidden = no
; map system = no
; map archive = no

# Use inherited ACLs for directories
; nt acl support = yes
; inherit acls = yes
; map acl inherit = yes

# These scripts are used on a domain controller or stand-alone
# machine to add or delete corresponding unix accounts
; add user script = /usr/sbin/useradd %u
; add group script = /usr/sbin/groupadd %g
; add machine script = /usr/sbin/adduser -n -g machines -c Machine -d /dev/null -s /bin/false %u
; delete user script = /usr/sbin/userdel %u
; delete user from group script = /usr/sbin/deluser %u %g
; delete group script = /usr/sbin/groupdel %g

# This is a DRAFT sample configuration for the ACLs on the ZFS partition.
#
nt acl support = yes
inherit acls = no
map acl inherit = yes

#============================ Share Definitions ==============================
[homes]
comment = Home Directories
browseable = no
writable = yes
path = /tank/Users/%S

# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]
; comment = Network Logon Service
; path = /usr/local/samba/lib/netlogon
; guest ok = yes
; writable = no
; share modes = no

# Un-comment the following to provide a specific roving profile share
# the default is to use the user’s home directory
;[Profiles]
; path = /usr/local/samba/profiles
; browseable = no
; guest ok = yes

# NOTE: If you have a BSD-style print system there is no need to
# specifically define each individual printer
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
# Set public = yes to allow user ‘guest account’ to print
guest ok = no
writable = no
printable = yes

# This one is useful for people to share files
;[tmp]
; comment = Temporary file space
; path = /tmp
; read only = no
; public = yes

# A publicly accessible directory, but read only, except for people in
# the “staff” group
;[public]
; comment = Public Stuff
; path = /home/samba
; public = yes
; writable = yes
; printable = no
; write list = @staff

# Other examples.
#
# A private printer, usable only by fred. Spool data will be placed in fred’s
# home directory. Note that fred must have write access to the spool directory,
# wherever it is.
;[fredsprn]
; comment = Fred’s Printer
; valid users = fred
; path = /homes/fred
; printer = freds_printer
; public = no
; writable = no
; printable = yes

# A private directory, usable only by fred. Note that fred requires write
# access to the directory.
;[fredsdir]
; comment = Fred’s Service
; path = /usr/somewhere/private
; valid users = fred
; public = no
; writable = yes
; printable = no

# a service which has a different directory for each machine that connects
# this allows you to tailor configurations to incoming machines. You could
# also use the %U option to tailor it by user name.
# The %m gets replaced with the machine name that is connecting.
;[pchome]
; comment = PC Directories
; path = /usr/pc/%m
; public = no
; writable = yes

# A publicly accessible directory, read/write to all users. Note that all files
# created in the directory by users will be owned by the default user, so
# any user with access can delete any other user’s files. Obviously this
# directory must be writable by the default user. Another user could of course
# be specified, in which case all files would be owned by that user instead.
;[public]
; path = /usr/somewhere/else/public
; public = yes
; only guest = yes
; writable = yes
; printable = no

# The following two entries demonstrate how to share a directory so that two
# users can place files there that will be owned by the specific users. In this
# setup, the directory should be writable by both users and should have the
# sticky bit set on it to prevent abuse. Obviously this could be extended to
# as many users as required.
;[myshare]
; comment = Mary’s and Fred’s stuff
; path = /usr/somewhere/shared
; valid users = mary fred
; public = no
; writable = yes
; printable = no
; create mask = 0765
;

# This is a DRAFT sample configuration for the ACLs on the ZFS partition.
#
; nt acl support = yes
; inherit acls = no
; map acl inherit = yes
;
;[zpool]
; path = /tank/zpool
; unix extensions = no
; vfs objects = zfsacl
; nfs4:mode = special
; nfs4:acedup = merge
; nfs4:chown = yes

[Public]
comment = Public (user-wide) directories
browseable = yes
read only = no
path = /tank/Users/Public
vfs objects = zfsacl
nfs4:mode = special
nfs4:acedup = merge
nfs4:chown = yes
[/cce_ini]

2 people like this post.

Create ZFS pool

31-Jan-11


server# zpool create tank raidz /dev/gpt/WD15EARS /dev/gpt/FANTOM1TB /dev/gpt/WD20EARS
invalid vdev specification
use '-f' to override the following errors:
raidz contains devices of different sizes
server# zpool create -f tank raidz /dev/gpt/WD15EARS /dev/gpt/FANTOM1TB /dev/gpt/WD20EARS

Now, I’ve got:

server# zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank 87.9K 1.78T 24.0K /tank
server# ls /tank
server# zpool status
pool: tank
state: ONLINE
scrub: none requested
config:

NAME STATE READ WRITE CKSUM
tank ONLINE 0 0 0
raidz1 ONLINE 0 0 0
gpt/WD15EARS ONLINE 0 0 0
gpt/FANTOM1TB ONLINE 0 0 0
gpt/WD20EARS ONLINE 0 0 0

errors: No known data errors
server# zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank 87.9K 1.78T 24.0K /tank

Next step: maybe move home directories to tank (change /home link?) and set up Samba for sharing.

Be the first to like.

Partitioning for ZFS

31-Jan-11

Have 3 drives: 1.5 TB WD15EARS, 1 TB Fantom Green (eSATA), 2 TB WD20EARS.
First, did a:

server# gpart add -b 2048 -s 2929865452 -t freebsd-zfs -l WD15EARS ada0
ada0p1 added
server# gpart add -b 2048 -s 1953113452 -t freebsd-zfs -l FANTOM1TB ada1
ada1p1 added
server# gpart add -b 2048 -s 3906617452 -t freebsd-zfs -l WD20EARS ada2
ada2p1 added

Now, I have:

server# gpart show ada0
=> 34 2930277101 ada0 GPT (1.4T)
34 2014 - free - (1.0M)
2048 2929865452 1 freebsd-zfs (1.4T)
2929867500 409635 - free - (200M)

server# gpart show ada1
=> 34 1953525101 ada1 GPT (932G)
34 2014 - free - (1.0M)
2048 1953113452 1 freebsd-zfs (931G)
1953115500 409635 - free - (200M)

server# gpart show ada2
=> 34 3907029101 ada2 GPT (1.8T)
34 2014 - free - (1.0M)
2048 3906617452 1 freebsd-zfs (1.8T)
3906619500 409635 - free - (200M)

You’ll note that I’m leaving 200M free in case I replace the drive with a slightly smaller drive.
Next step: set up ZFS pools.

Be the first to like.

More flash USB disk tests

27-Jan-11

Tested some more USB flash drives. Running from my Lenovo work laptop, USB 2.0 only:

Random 8G USB from a vendor

Super Talent Express Duo 8GB (capable of USB 3.0, but running in USB 2.0)

Super Talent Pico 16 GB

Be the first to like.

Flash disk cost and performance (USB, SSD, SDHC)

08-Jan-11

I’ve been reading up on using a USB flash drive as an L2ARC for ZFS. Some reason that since the bandwidth of USB is much lower than SATA. However, others reason that since the USB flash drive has no seek time, it will speed up non-sequential reads, which is what the L2ARC is there for. (ZFS is supposed to bypass the L2ARC for sequential workloads.)

I set out to test run-of-the-mill USB drives to see what sort of performance they give. Both magnetic and solid-state drives perform much better with sequential workloads than with random-access workloads. However, I concluded that SSD’s performance doesn’t suffer nearly as badly. More…

4 people like this post.

Fail on IronRuby 1.1: hacking the configuration (app.config or exe.config) file location

05-Jan-11

Summary: I can’t get IronRuby to over-ride where it gets its app.config file.

Because I’m glutton for punishment, I decided to try out IronRuby to do some dev work in .NET. I went with the latest IronRuby, which is in .NET 4.0–mostly because it integrates with Visual Studio 2010.

One of my first stumbling blocks is that by default, you can’t call .NET 2.0 assemblies from .NET 4.0. To enable such cross-calling, you need to have an app.config that looks like so:







That’s great, but where do I put this? I wouldn’t mind changing the global ir.exe.config file, but I can’t find that with IronRuby 1.1. I found a solution here: IronRuby and the Configuration (app.config or exe.config) « vaderpi’s random rants. The author warns that it is a hack and probably won’t work with newer .NET versions. That is the case. I can’t get it to work on .NET 4.0.

If I had it to do over again, I might’ve gone with IronPython–which have latest releases for .NET 2.0SP1 and .NET 4.0. I don’t know if either (or both) of these integrate with Visual Studio 2010.

Be the first to like.