Weblog

All | CMT | General | NUMA | OpenSolaris | Perl | Photo | Programmers Desk | STREAMS
« CPU Caps update | Main | Caps revised »
20060914 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.

  1. Pick some initial build to start with. Let's say it is Solaris Nevada, build 42.
  2. Create zfs filesystem for the build:
    # zfs create tank/ws
    # zfs create tank/ws/onnv-clone
    
  3. Place the new filesystem in /export/ws/onnv-clone:
    # zfs set mountpoint=/export/ws tank/ws
    # chown akolb:staff /export/ws/onnv-clone
    
  4. Get a copy of build 42:
    $ bringover -p /net/onnv/export/snapshot/onnv_42 -w /export/ws/onnv-clone usr
    
  5. Make ZFS snapshot of it:
    # zfs snapshot tank/ws/onnv-clone@onnv_42
    
  6. Make named clone of it (optional - if I ever need one):
    # zfs clone tank/ws/onnv-clone@onnv_42 tank/ws/onnv_42
    
    This 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.

So far we just copied everything from /net/onnv/export/snapshot/onnv_42 to /export/ws/onnv-clone and made another exact copy at /export/ws/onnv_42. We could as well do this without zfs. The filesystems we now have are:
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-clone
Now I can create my private project workspace:
# zfs clone tank/ws/onnv-clone@onnv_42 tank/ws/cpu-caps
This 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-caps
Now 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-build
When I am done with these builds I may quickly remove the scratch build workspace:
# zfs destroy tank/ws/cpu-caps-build
Some 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_43
As 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!


Technorati Tag:
Technorati Tag:

( Sep 14 2006, 06:41:11 PM PDT ) Permalink

Comments:

Post a Comment:

Comments are closed for this entry.

Calendar

RSS Feeds

Search

Links

Navigation

Referers