Thursday September 14, 2006 Using ZFS to save space on laptop
I recently reinstalled Solaris on a laptop and started to use ZFS there. Initially I thought that there are no any real benefits, but it turned out to be really useful. I could achieve some of the purposes by using loopback mounts, but it allows me to save a lot of disk space.
I keep several Solaris workspaces around. A "workspace" is a snapshot of the whole Solaris source tree potentially with some local modification. Its typical size is around 2Gb. The source tree is called gate and it has be-weekly snapshots which are numbered builds. Usually I start a new workspace for a project based on specific build. Here is how I do it with zfs.
# zfs create tank/ws # zfs create tank/ws/onnv-clone
# zfs set mountpoint=/export/ws tank/ws # chown akolb:staff /export/ws/onnv-clone
$ bringover -p /net/onnv/export/snapshot/onnv_42 -w /export/ws/onnv-clone usr
# zfs snapshot tank/ws/onnv-clone@onnv_42
# zfs clone tank/ws/onnv-clone@onnv_42 tank/ws/onnv_42This step may be done later when I need an explicit copy of the original snapshot e.g. when I need to generate diffs against the original code.
NAME USED AVAIL REFER MOUNTPOINT tank 4.80G 16.9G 26.5K /tank tank/export/ws 2.19G 16.9G 30.5K /export/ws tank/export/ws/onnv-snapshot 878M 16.9G 697M /export/ws/onnv-snapshot tank/export/ws/onnv-snapshot@snv_42 52.0M - 649M - tank/export/ws/onnv_42 0 16.9G 652M /export/ws/onnv-cloneNow I can create my private project workspace:
# zfs clone tank/ws/onnv-clone@onnv_42 tank/ws/cpu-capsThis took almost no time and now I have an exact copy of Solaris build 42. I can start modifying files or I may sync with my primary workspace which holds all my changes:
$ bringover -w /export/ws/cpu-caps -p /ws/rm-gate/cpu-capsNow I want to snapshot the result to know where I started.
# zfs snapshot tank/ws/cpu-caps@`date +"%m-%d-%y"`Now I have all the diffs from the original build 42 in my new workspace. If I want to build Solaris out of it I may either run a build right there or I may get fancy and create a special build workspace so that I would not pollute the original with all the build by-products:
# zfs clone snapshot tank/ws/cpu-caps@`date +"%m-%d-%y"` tank/ws/cpu-caps-buildWhen I am done with these builds I may quickly remove the scratch build workspace:
# zfs destroy tank/ws/cpu-caps-buildSome time later build 43 shows up and I want to keep it locally as well - no problem!
$ bringover -w /export/ws/onnv-clone -p /net/onnv/export/snapshot/onnv_43 # zfs snapshot tank/ws/onnv-clone@onnv_43 # zfs clone tank/ws/onnv-clone@onnv_43 tank/ws/onnv_43As you see, I only keep a single big workspace and everything else are diffs from that and these diffs are usually much smaller. In addition to that I enable zfs compression and put /opt and /usr/local on zfs as well. Here is a real list from my laptop:
$ zfs list -o name,used,compressratio,mountpoint NAME USED RATIO MOUNTPOINT tank 4.80G 1.89x /tank tank/SUNWspro 2.26G 1.98x /opt/SUNWspro tank/csw 244M 1.92x /opt/csw tank/export 2.21G 1.80x /export tank/export/home 20.3M 1.80x /export/home tank/export/home/akolb 20.2M 1.80x /export/home/akolb tank/export/ws 2.19G 1.80x /export/ws tank/export/ws/caps-build 1.12G 1.80x /export/ws/caps-build tank/export/ws/cpu-caps 157M 1.73x /export/ws/cpu-caps tank/export/ws/cpu-caps@09_07 32.2M 1.89x - tank/export/ws/onnv-snapshot 878M 1.84x /export/ws/onnv-snapshot tank/export/ws/onnv-snapshot@snv_45 52.0M 1.89x - tank/export/ws/onnv-snapshot@snv_46 57.2M 1.89x - tank/export/ws/onnv-snapshot@snv_47 30.3M 1.88x - tank/export/ws/pg-clone 59.0M 1.21x /export/ws/pg-clone tank/export/ws/pg-clone@09-13 24.4M 1.89x - tank/export/ws/pg-mdb 431K 1.96x /export/ws/pg-mdb tank/local 73.8M 1.75x /usr/local tank/onbld 3.73M 4.73x /opt/onbld
This technique allows me to have lots of large workspaces on a modest disk and manipulate them very easily. I love zfs!