Transferring FreeNAS 8 to a different USB drive

As part of my FreeNAS 8 build, I purchased a Transcend 2GB USB drive which fits onto a standard motherboard 10-pin USB header to avoid having a USB thumb drive sticking out of the back of the case.

Unfortunately this took a while to arrive as had to order it in specially, so my initial FreeNAS install was onto a temporary USB thumb drive.

Once the internal USB drive had arrived, I needed to transfer my install onto the new drive. Although it probably would have been possible to use FreeNAS’s backup/restore to move my settings onto a fresh install, I wanted to try a low-level copy from the temporary thumb drive to the internal drive if possible.

The transfer can be made quite easily using dd, however first it is necessary to identify which physical disk maps to which USB device, which is made slightly more difficult by the fact that the drive partitions are labelled with glabel rather than using the underlying drive partition names.

The following procedure worked for me:

  1. Boot FreeNAS into single-user mode (Select “4. Boot FreeNAS in single user mode at the boot menu”
  2. Type “mount” to identify which glabel the old USB drive is mounted on – e.g.
    $ mount
    /dev/ufs/FreeNASs1a on / (ufs, local, read-only, soft-updates)
  3. Run “glabel list | grep <label> -B 2″ (replacing “FreeNASs1a” with the label displayed in the previous step). The “Geom name” provides the underlying drive partition name, in this case da0s1a:
    $ glabel list | grep FreeNASs1a -B 2
    Geom name: da0s1a
    1. Name: ufs/FreeNASs1a
  4. Take the first three letters of the partition name from the previous step to get the device name (da0 in the example above).
  5. Run “grep da. /var/log/messages”:
    $ grep da. /var/log/messages
    May 25 09:12:55 freenas kernel: da0: Removable Direct Access SCSI-0 device
    May 25 09:12:55 freenas kernel: da1: Fixed Direct Access SCSI-0 device
  6. From the output above, one of the device names should match that of the Freenas label, check that the disk type matches that expected. The other should match your new USB stick.
  7. Triple-check the above as the following command will destroy your FreeNAS disk if run incorrectly!
  8. Run “dd if=/dev/<old device> of=/dev/<new device> bs=16k” to perform the copy, e.g.
    $ dd if=/dev/da0 of=/dev/da1 bs=16k

Update: The ‘camcontrol’ command also allows devices to be listed:

# camcontrol devlist
at scbus1 target 0 lun 0 (pass0,ada0)
at scbus2 target 0 lun 0 (pass1,ada1)
at scbus4 target 0 lun 0 (pass2,ada2)
at scbus7 target 0 lun 0 (pass3,da0)

Guide to cryptographic hashes for content-based addressing

Just came across an interesting article on the use of cryptographic hashes in content-based addressing (e.g. Git, Rsync, Bittorrent) whilst doing some reading around ZFS deduplication in ZFS v21 which is coming soon (with v26) in FreeBSD (and hence hopefully soon in FreeNAS!)

FreeNAS i3 setup

Just finished building some new hardware to run FreeNAS 8.0. As there’s not a huge deal of info kicking around the internet about working hardware configurations I thought i’d post my experiences.

Last time I built a PC I almost built a NAS box at the same, but looking at the increase in cost of building a separate network attached PC and the decrease in performance from accessing storage via a LAN I decided to put a RAID array inside my PC instead. The RAID array (on-board Intel Matrix RAID from my motherboard) has served me well and seen me through 2 drive failures in the past 5 years without issue – fortunately the Western Digital Caviar RAID Edition drives I purchased come with a 5 year guarantee with Advance Replacement (Western Digital will ship the replacement drive within 3-5 days, without receiving the faulty one first as long as you provide credit card details). Luckily my Samsung Spinpoint boot disk has not failed thus far!

I recently upgraded my network to gigabit ethernet, so network attached storage now seems more viable, plus I have filled up the RAID storage on my PC (which is probably close to wearing out anyway and I don’t fancy having to find a compatible motherboard to get my data back out again)… ZFS seems to be all the rage these days, and so it seems like hardware RAID is redundant. Some forum research seemed to indicate that ZFS needs a reasonably powerful CPU and plenty of memory, which ruled out my hopes of building a low-power fanless Intel Atom system. Therefore I decided to go with an i3, and the Zotac H55 Mini-ITX motherboard as it has 6 SATA ports.

As for a case, I looked at a few options including the Fractal Design Array R2, the CFI A7979 and the Lian-Li PC-Q08, but in the end decided to go with the Chenbro ES34169.

I also managed to find a Transcend 2GB USB drive intended for industrial use which fits onto a standard motherboard 10-pin USB header to avoid having a USB thumb drive sticking out of the back of the case.

A review appeared to confirm that the ES34169 would work nicely with the Zotac motherboard and an i3. When all the parts finally arrived and I built the system, unfortunately it would not boot. Some swapping of PSUs eventually confirmed that the Chenbro PSU was fine (it would boot a lower wattage system) as was the Zotac board, CPU and RAM (it would boot on another PSU), so the only conclusion was that 120W was not enough for the system.

Fortunately, Kustom PCs were very understanding and shipped me a 180W ES34069 (which has an external power brick) whilst I shipped the 120W ES34069 (which has an internal open-frame PSU, and is not available in a 180W version) back to them.

I had already purchased a low-height CPU cooler after reading the ES34169 review, and this fitted without issue. The only issue I did have building the case was that the SATA cables on the ES34069 were shorter than the ES34169 and two were not able to reach the SATA ports on the motherboard, so I had to replace these with some longer cables. After building the system, initially two of the HDDs did not register with the BIOS. These were the two bays I had switched cables for so I assumed there was an issue with the cables, however after ejecting and re-inserting the HDD caddies the drives appeared.

The ES34069 looks good, the translucent front allows the blinkenlights inside to be visible, which include a power and activity light on each individual disk caddy, somehow magically driven through the backplane (I had always assumed these would need a proprietary connection to a RAID controller).

On booting FreeNAS from a USB stick I initially had an issue with the system hanging whilst trying to load the network card driver, which seems to be a problem with the i386 BSD driver, however it works fine with the amd64 build (which is required for 64 bit support anyway).

So, I can confirm without further ado that the following setup works with FreeNAS 8:

The Transcend USB drive actually took a little while longer to arrive (as had to order it in specially), so I initially installed FreeNAS onto a USB thumb drive and later transferred it to the Transcend USB drive with dd.

FreeNAS seems pretty easy to use so far. FreeNAS 8.0 is a complete rewrite so unfortunately it only supports basic storage/sharing at the moment, however many more features are on the way in 8.1. Now to copy my data on and start using FreeNAS!

Tungsten FSM: A lightweight Java finite state machine library

I recently came across Tungsten FSM whilst looking for an off the shelf FSM implementation. Ideally I was looking for something which was a lightweight and no-frills but robust FSM implementation, and Tungsten FSM seemed to exactly fit the bill. All configuration is done in code, so no messing around with XML files, and the implementation itself is only a handful of classes with only one dependency (log4j).

All in all worked out very well, and it seems to do exactly what it promises. The support for sub-states is useful to cut down on config bloat by defining common transitions on a parent state.

If I were to nitpick it would have been nice to see generics used to avoid needing to cast the entities/events, however this would arguably bloat the Tungsten source somewhat. It would have also been nice to be able to specify an “ignore” type transition which could be specified on a parent state to ignore an event rather than having to define transitions on all sub states of the parent state for an event in order to ignore it and stay in the same state.

A-Team London Insight Exchange

Myself and a colleague were offered some tickets for the A-Team Insight Exchange (High Performance Technologies for Trading and Risk) in London yesterday, and were able to get away from our desk long enough to attend the first half of the day!

Overall a lot of the things discussed were things that we were already aware of as a team, and although it was disappointing not to have any huge takeaways from the day it was heartening to know that our team is at pace with the current state of the art (although clearly the state of the art as presented predominately by vendors at such a conference does not necessarily equal the true state of the art in in-house technologies developed by banks/funds).

A few interesting themes from the day:

  • Integration/Standards – A lot of interest in making proprietary components e.g. for risk/algorithmic execution use industry standards (e.g. FIXatdl for algo trading) to speed up integration and facilitate reuse of off the shelf components.
  • Build vs buy – Many of the panel discussions focused around this with the vendors obviously arguing the buy case for time to market, less developers required etc.
  • Interest in low-latency/HFT increasingly spreading to FX/options – According to the vendors, a lot of the technologies previously used almost exclusively by equities such as InfiniBand/10 GigE and colocation are now being taken up by increasing numbers of customers for FX/options.
  • The need for education – One of the panel members made an interesting point that a lot of customers have infrastructure teams who have no idea what the High Frequency Trading teams in their bank are doing, this can be counter-productive as the HFT teams build/support everything themselves as they don’t feel they can trust the infrastructure teams to understand/implement their requirements correctly. If infrastructure teams were better educated about HFT/low-latency this would be less of an issue.
  • Different types of latency – Darshan Chandarana from Oracle address touched on realtime JVMs a bit and re-iterated the fact that it is generally not possible to have both the lowest latency and maximum determinism – realtime technologies generally decrease variance at the expense of increasing  the mean. The only counterexample given to this was InfiniBand, which apparently is indeed a magic bullet!

A few interesting vendors:

  • Panopticon – Partners of Sybase’s CEP offering (Aleri), they demoed alongside Sybase. Some interesting visualisations on top of the risk system (e.g. their treemap).
  • Sumerian – Came up with a nice sound byte in one of the panel discussions: “Latency is a distribution, not a number”. This piqued my interest as this was a view that our team hold which some of the other latency monitoring vendors we have previously met didn’t implement. Also, unlike some of the other vendors we have previously met, Sumerian’s approach is not a real-time dashboard – instead data is shipped to them and they analyse it to produce a one-off report which identifies which areas of the system are most latent and therefore benefit from development investment. Obviously there are pros and cons to this approach vs a real-time monitoring dashboard.
  • Oracle – Thanks to the merger with Sun, they are now producing hybrid appliances using Sun hardware, e.g. they believe they have built one of the fastest database servers available (and they had brought this in an impressive display rack to their stand). Will be interesting to see if they come up with any challenges to Azul in the JVM appliance space.

Garbage Collection Tuning

I recently stumbled across a useful presentation: “GC Tuning In the HotSpot JVM” from FISL 10, which provides a good overview of how to tune the ParNew, Paralell and CMS collectors…

Also quite useful is this blog entry which explains how to understand CMS GC logs.

Performance techniques used in the Hotspot JVM

Little gem from the Hotspot Internals wiki helping to solve puzzles such as is “X.class.isAssignableFrom(obj)” slower than “obj instanceof X“!

Performance techniques used in the Hotspot JVM.

Calculating floating point epsilon/precision in Java

Floating point arithmetic/rounding can be somewhat painful, made worse by the fact that the epsilon (error) in the machine representation of floating point varies depending on the exponent (i.e. how large/small the number being represented is):

Normalized numbers when Base = 2, Precision = 3, Exponents = -1 to 2 [Goldberg91]

A very comprehensive paper (from which the above image is taken) is available here. In previous teams we have implemented our own functions to derive an approximation of the epsilon from the number to be represented, however I discovered recently to my surprise that such a function was added to Java in 1.5: Math.ulp!

JMM Synopsis

Useful synopsis of the Java Memory Model from Doug Lea – in particular the clearest explanation I have found so far of the meaning of “happens-before”, and some useful definitions which helped to get a concrete idea of the semantics around safe-publication of variables through Thread.start()…

Server upgrade to Intel Atom Mini-ITX

My home linux server (formerly my desktop PC), which has been sitting in the corner of my lounge for a few years (with all fans other than the CPU fan unplugged in order to keep the noise down), finally blew up a few weeks ago. The motherboard was loading the BIOS but failing to recognise the HDDs or boot from a CD despite the fact the HDD/CD seemed fine in another PC, so I presumed that the Southbridge had failed due to overheating.

I decided to switch to a low-power Mini-ITX based design rather than replacing the broken motherboard with a comparable one, and after a quick bit of research decided upon an Intel D945GCLF2 motherboard – which is based around the Atom 330 (dual core 1.6 GHz) processor, 2 Gb of RAM and a Morex Venux 668 case from ITX Warehouse. A complete PC (excepting disks) with change to spare from £150 – pretty impressive!

The parts arrived two days later (I ordered after the 5pm cutoff), and within a few hours everything was installed in the new case and ready to go. I was amazed as Debian booted off of the old disk without any issues (try changing the motherboard architecture on Windows without reinstalling from scratch!). After some slight issues with the network I eventually realised the new network card was coming up as eth1 rather than eth0. A quick check of google revealed that the old network card needed to be removed from /etc/udev/rules.d/70-persistent-net.rules. Following this everything was up and running as before.

The fan on the D945GCLF2 is apparently notorious for becoming very noisy after a few weeks, and the fans in the case are of a similar diameter, so I am expecting my next project will be to replace these with either low-noise fans or passive cooling.