Playing with ZFS – Forgot to turn on compression?
I’ve been playing with ZFS lately, and I’ve learned how to turn on compression if you forgot it when creating the filesystem. As you probably know turning on compression *after* you data has been written will not compress those files. It will only compress new data. This guide will tell you how to that. Warning: Your mounpoint will go offline.
Lets say you have created a ZFS filesystem for /usr/src – The data is already there, and compression is turned off.
Create a snapshot.
zfs snapshot tank/src@snap
Create a new temprary filesystem with compression.
zfs create -o compression=gzip tank/temp
Transfer data from tank/src@snap.
zfs send tank/src@snap | zfs receive tank/temp/src_comp
Ensure compression is on.
zfs get -r compression
Compression is inherited from the parent so have to turn on compression.
zfs set compression=gzip tank/temp/src_comp
Destroy old uncompressed filesystem.
zfs destroy -r tank/src
Rename the filesystem.
zfs rename tank/temp/src_comp tank/src
Destroy temporary filesystem, and the old snapshot.
zfs destroy tank/temp
zfs detroy tank/src@snap
List all zfs systems to ensure everything is okay.
zfs list
(Optionally)Set mountpoint for the new and compressed src.
zfs set mountpoint=/usr/src tank/src
Vóila!
Posted in Everything