LessFS

Table of Contents

I've been using LessFS for storing KVM/libvirt images (/var/lib/libvirt/images) which has saved me quite alot of disk-space - seemingly without any performance loss for my use (e.g. light-weight).

I build it under /opt/lessfs and reference it from there - not using 'make install'. The data/meta-data is kept there as well.

I'm doing this on a fairly new and powerful CPU and using a SSD hard-drive.

Download

cd /opt
sudo mkdir lessfs
sudo chown $USER: lessfs -R
wget http://sourceforge.net/projects/lessfs/files/latest/download?source=files -O lessfs.tar.gz
tar -xzvf lessfs.tar.gz

Tools

On Ubuntu 14.10 you need the following packages to build LessFS.

sudo aptitude install libmhash-dev libsnappy-dev libdb-dev libfuse-dev libtokyocabinet-dev libssl-dev pkg-config make

Build

Configure takes 5-6 seconds.

cd lessfs
time ./configure --with-berkeleydb --with-snappy

Make takes 15-20 secons

time make

Folders

mkdir -p /opt/lessfs/libvirt-images/dta
mkdir -p /opt/lessfs/libvirt-images/mta
cp DB_CONFIG /opt/lessfs/libvirt-images/mta

Configuration

  • I'm using hard-drive encryption and therefore disable the built-in meta-/data encryption.
  • snappy compression.
  • using chunk_io for the disk-usage re-claiming.

/opt/lessfs/libvirt-images.cnf

DEBUG = 5
HASHNAME=MHASH_TIGER192
HASHLEN = 24
BLOCKDATA_IO_TYPE=chunk_io
BLOCKDATA_PATH=/opt/lessfs/libvirt-images/dta/
META_PATH=/opt/lessfs/libvirt-images/mta
META_BS=1048576
CACHESIZE=512
COMMIT_INTERVAL=10
LISTEN_IP=127.0.0.1
LISTEN_PORT=101
MAX_THREADS=16
DYNAMIC_DEFRAGMENTATION=on
COREDUMPSIZE=2560000000
SYNC_RELAX=0
WBACKGROUND_DELETE=on
# HDD encryption enabled - so not necessary on lessfs level.
ENCRYPT_DATA=off
#ENCRYPT_META=on
ENABLE_TRANSACTIONS=on
BLKSIZE=131072
COMPRESSION=snappy

Initializing

We have to use sudo since the BerkeleyDB option sets logging to /var/log/lessfs-bdb_err.txt and the LessFS process is listening on a port below 1024.

sudo /opt/lessfs/lessfs-1.7.0/mklessfs /opt/lessfs/libvirt-images.cnf ; echo $?

Startup Script

#!/bin/sh
#
# lessfs This script starts and stops the spamd daemon
#
# chkconfig: - 78 30
# processname: lessfs
# description: lessfs a deduplicating filesystem

# Source function library.
#. /etc/rc.d/init.d/functions

prog="lessfs"

# Source networking configuration.
#. /etc/sysconfig/network

# Check that networking is up.
#[ ${NETWORKING} = "no" ] && exit 0
[ -f /var/run/network/ifstate ] && [ $(cat /var/run/network/ifstate | wc -l ) -eq 0 ] && exit 0

PATH=$PATH:/opt/lessfs/lessfs
MKLESSFS=/opt/lessfs/lessfs/mklessfs
MOUNTPOINT=/var/lib/libvirt/images
LESSFS_CONF=/opt/lessfs/libvirt-images.cfg
LESSFS_OPTS="$LESSFS_CONF $MOUNTPOINT"
LESSFS=/opt/lessfs/lessfs/lessfs
LISTDB=/opt/lessfs/lessfs/listdb

# By default it's all good
RETVAL=0
export DEBUG=0

# See how we were called.
case "$1" in
  start)
# Start daemon.
echo -n $"Starting $prog: "
/sbin/modprobe fuse
        $LESSFS $LESSFS_OPTS
RETVAL=$?
        echo
if [ $RETVAL = 0 ]; then
touch /var/lock/lessfs
fi
        ;;
  stats)
echo -n "Running lessfs processes: "
ps aux | grep lessfs | wc -l
#if mount|grep $MOUNTPOINT; then
if grep -qs $MOUNTPOINT /proc/mounts; then
echo "Cant check stats if is mounted"
else
echo "Lessfs statistics:"
$LISTDB $LESSFS_CONF 2>&1 |grep '      ->inode '|awk '{print $5, " ", $8}'| awk 'BEGIN{s=0;p=0}{s=s+$1;p=p+$2}END{print "\n stored data: " int(s/1048576) "MB (" int(s/1073741824) "GB)\n", "deduplicated data: " int(p/1048576) "MB (" int(p/1073741824) "GB)\n", "space saved: " int((1-p/s)*1000)/10 "%\n" }'
fi
;;
  status)
echo "Todo status check"
;;
  stop)
        # Stop daemons.
        echo -n $"Stopping $prog: "
        umount $MOUNTPOINT
        RETVAL=$?
        echo
if [ $RETVAL = 0 ]; then
rm -f /var/lock/lessfs
rm -f $SPAMD_PID
fi
        ;;
  restart)
        $0 stop
sleep 3
        $0 start
        ;;
  *)
echo "Usage: $0 {start|stop|restart|stats|status}"
RETVAL=1
;;
esac

exit $RETVAL 
### EOF ###

Author: Rói á Torkilsheyggi

Created: 2015-12-16 Wed 01:39

Emacs 24.5.1 (Org mode 8.2.10)

Validate