Sunday, January 27, 2013

Sunday, January 20, 2013

Destroy all ZFS snapshots in a zpool

Test:
sudo zfs list -r -H -o name -t snapshot filesystem-name | xargs -n1 sudo zfs destroy -n -v
Destroy (remove -n option):
sudo zfs list -r -H -o name -t snapshot filesystem-name | xargs -n1 sudo zfs destroy -v

Friday, January 18, 2013

Find package that installs a certain file

The following command works on Debian derivatives (Ubuntu included):
jordi@topper:~$ dpkg -S /sbin/getty
util-linux: /sbin/getty

Wednesday, January 16, 2013

Easy Samba in my linux NAS

I would like to be able to read and write files via Samba or locally/ssh on the server without problems. Nothing is more frustrating than modifying a file via Samba and being unable to read it via ssh.
To achieve this I need working recursive permissions.
In the end, members of the group users will be able to read and write files under the samba share.
Let's do it!

1. Set a suitable smb.conf

[global]
workgroup = BUFON
server string = %h (Samba on Ubuntu Server)
guest ok = yes
security = user
local master = yes
os level = 255
preferred master = yes
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536
[template]
-valid=no
path = /mnt
write list = @usersforce 
group = users
create mask = 0775
force create mode = 0775
security mask = 0770
directory mask = 0775
force directory mode = 0775
vfs objects = recycle
recycle:repository = Recycle Bin
recycle:versions = Yes
recycle:keeptree = No
[tank]
path = /tank
write list = @users
force group = users
create mask = 0775
force create mode = 0775
security mask = 0770
directory mask = 0775
force directory mode = 0775
vfs objects = recycle
recycle:repository = Recycle Bin
recycle:versions = Yes
recycle:keeptree = No
[tank$]
copy=template
-valid=yes
path=/tank

2. Set permissions


From Linux Security HOWTO - 5. Files and File system Security comes this very useful bit of information:
SGID Attribute: (For directories)
If you set the SGID bit on a directory (with chmod g+s directory), files created in that directory will have their group set to the directory's group.
So we need to do a chmod +s on the folders under the samba share.
Run this script if you create a new samba share or if you mess up your permissions and want to start fresh again:

#!/bin/sh
#Usage: fix-permissions.sh /data/myfolder
FOLDER=$1
echo "Fixing permissions in $FOLDER"
echo "... chmod on folders"
find $FOLDER -type d -exec chmod g+rwxs {} \;
echo "... chmod on files"
find $FOLDER -exec chmod g+rwx {} \;
echo "... chown on folders"
find $FOLDER -type d -exec chown root.users {} \;
echo "... chown on files"
find $FOLDER -exec chown root.users {} \;

3. Add users to "users" group


sudo adduser jordi users
Do the same with other users that need access to the files on the samba share; e.g. www-data, debian-transmission, hts, mldonkey.

That's all.

ZFS and Advanced Format (4K) hard disks

zpool create -o ashift=12 tank ata-ST3000DM001-9YN166_S1F06KTG

Tuesday, January 15, 2013

Disable access time on ZFS

zfs set atime=off pool|filesystem

Disable ZFS auto snapshots

If you want to exclude a filesystem (e.g. the one that holds your VMs) from zfs-auto-snapshot, you can do that setting the following property.

# zfs set com.sun:auto-snapshot=false filesystem