ZFS

From Segfault
Jump to: navigation, search

Getting started

Create a pool[1]:

zpool create tank0 /dev/sdc /dev/sdd /dev/sde

Now we should have something like this:

$ zpool status tank0
  pool: tank0
 state: ONLINE
  scan: none requested
config:
       NAME        STATE     READ WRITE CKSUM
       tank0       ONLINE       0     0     0
         sdc       ONLINE       0     0     0
         sdd       ONLINE       0     0     0
         sde       ONLINE       0     0     0

Rename a pool:

zpool export tank0
zpool import tank0 tank2

Compression

# df -h /data/backup
Filesystem             size   used  avail capacity  Mounted on
tank0/backup           7.0G   5.1G   1.9G    73%    /data/backup

$ zfs get compression tank0/backup
NAME          PROPERTY     VALUE         SOURCE
tank0/backup  compression  on            local

$ dd if=/dev/zero of=/data/backup/null.img bs=1024k count=1k
$ ls -hl /data/backup/null.img 
-rw-r--r--   1 root     root        1.0G Dec 15 12:54 /data/backup/null.img

$ du -sh /data/backup/null.img 
   0K   /data/backup/null.img

$ df -h /data/backup
Filesystem             size   used  avail capacity  Mounted on
tank0/backup           7.0G   5.1G   1.9G    73%    /data/backup

Compressing filesystem contents afterwards:

  • Doesn't work for hardlinks
  • Can this be done with zfs magic?
$ df -h /data/test
Filesystem             size   used  avail capacity  Mounted on
tank0/test             2.0G   465M   1.5G    23%    /data/test

$ zfs set compression=on tank0/test
$ zfs get compression tank0/test
NAME        PROPERTY     VALUE       SOURCE
tank0/test  compression  on          local

$ df -h /data/test
Filesystem             size   used  avail capacity  Mounted on
tank0/test             2.0G   465M   1.5G    23%    /data/test

$ cd /data/test
$ du -sh share/
481M   share/

$ find . -type f -size +1024 | while read f; do
      echo "re-creating $f ..."
      cp "$f" "$f".$$ && rm "$f
      mv "$f".$$ "$f"
done

$ du -sh share/
 417M   share/

$ df -h /data/test/
Filesystem             size   used  avail capacity  Mounted on
tank0/test             2.0G   401M   1.6G    20%    /data/test

$ zfs get compressratio tank0/backup
NAME          PROPERTY       VALUE         SOURCE
tank0/backup  compressratio  1.00x         -

Using a ZFS Volume as a Swap or Dump Device

$ zfs create -V 1gb export/swap
$ swap -a /dev/zvol/dsk/export/swap

Links

References