Use delegate dataset for samba zone

This is a small but maybe helpful improvement to my blog post Setting up Samba on SmartOS. Thanks to wiedi who reviewed the blog post a bit. One of the many benefits using Samba in a SmartOS zones is that you have ZFS.

So you would like to use ZFS features like creating snapshots of your data, enable compression, etc. from inside of the zone? For that reason I use a delegate dataset for our samba share folder.

Creating a zone with delegate dataset

I add the option "delegate_dataset": true to the JSON information file.

# Create the zone
vmadm create << EOF
{
  "brand": "joyent",
  "image_uuid": "62f148f8-6e84-11e4-82c5-efca60348b9f",
  "autoboot": true,
  "alias": "samba.example.com",
  "hostname": "samba.example.com",
  "dns_domain": "example.com",
  "quota": 200,
  "delegate_dataset": true,
  "resolvers": [
    "8.8.8.8",
    "8.8.4.4"
  ],
  "max_physical_memory": 1024,
  "max_swap": 1024,
  "nics": [
    {
      "nic_tag": "admin",
      "ip": "dhcp",
      "primary": true
    }
  ]
}
EOF

Configure the delegate dataset

You need to login to the zone to configure the dataset.

# Use zlogin from the global zone
zlogin <uuid>

# Or use SSH :-)
ssh root@<hostname>

You are now able to see the delegate dataset by using the zfs list command.

NAME                                              USED  AVAIL  REFER  MOUNTPOINT
zones                                            4.91T  2.97T   735K  /zones
zones/26e55c0d-...       11.9M   200G   408M  /zones/26e55c0d-...
zones/26e55c0d-.../data  34.4K   200G  34.4K  /zones/26e55c0d-.../data

To be more flexible I recommend to create an extra zfs file system with a new name. For example share.

# Get the UUID and the delegate dataset folder
UUID=$(mdata-get sdc:uuid)
DDS=zones/${UUID}/data

# Create the zfs file system named share
zfs create ${DDS}/share

If you like to follow the Setting up Samba on SmartOS guide you need to mount the share to /share.

# Set mount point of share (be sure the DDS variable is set)
zfs set mountpoint=/share ${DDS}/share

Practical examples

There are many good reasons to use a delegate dataset. Most of those are not limited to samba and apply to other services as well.

Create snapshots manually

You would like to do a big change on your current data? Why not making a snapshot first for safty?

# Create the snapshot
zfs snapshot zones/26e55c0d-.../data/share@backup

# Show the current snapshot(s)
zfs list -t snapshot

NAME                                    USED  AVAIL  REFER  MOUNTPOINT
zones/26e55c0d-..../data/share@backup      0      -  34.4K  -

Enable compression

You store a lot of log files on your share? Enable compression to save disk space.

# Enable compression
zfs set compression=on zones/26e55c0d-.../data/share

Use znapzend for backups

Everybody should have backups! I can recommend the ZnapZend tool from Tobias Oetiker. It's easy to use and it scales from a small local backup environment to big ZFS pools.

# First you need to install it in your zone
pkgin install znapzend

I would like to have local snapshots of my data. The information after SRC can be a little bit confusing, so let me explain: A snapshot will be done every hour and saved for 7 days. Every day a snapshot is done and saved for 30 days, etc.

# Configure znapzendzetup
znapzendzetup create --recursive \
    --tsformat='%Y-%m-%d-%H%M%S' \
    --donotask \
    SRC '7day=>1hour,30day=>1day,1year=>1week,10year=>1month' \ 
    zones/26e55c0d-.../data/share

Be sure you also enable the service :-)

# Enable the service
svcadm enable svc:/pkgsrc/znapzend:default

For any additional tuning or configuration follow the documentation on the GitHub ZnapZend project.

Update to a new base image

You would like to update to a new samba version available in a new pkgsrc release or base image? Because you use a delegate dataset you don't need to copy your data around - easy reprovision to the new base image.

Caution! All your installed packages and configuration files will be gone! Be sure you backup the samba configuration, samba user information or any other configuration files you want to keep.

You might want to backup or copy the following files to your delegate dataset share:

  • Samba config folder (including sub-folders): /opt/local/etc/samba/
  • List of installed packages: pkgin list
  • If you have local users: /etc/passwd and /etc/shadow maybe /home

Run the following commands in the global zone to reprovision to the new base64 image:

# Check for the newest base64 image
imgadm avail | grep base64 | tail -n2
imgadm import <UUID>

# Reprovision your samba zone
echo '{ "image_uuid": "<NEW-BASE64-UUID>" }' |\
    vmadm reprovision <SAMBA-ZONE-UUID>

After this you can restore configuration files and install the new software packages with pkgin. Your data in the delegate dataset will be still there and untouched.

Posted

January 17, 2015, 6:03 pm

Tags

, , , ,

More

Permalink

Comments

Send your comment by mail.