The Cog

That Little Bit of Knowledge That Makes Everything Work

Romaco Radio EP1 – ZFS Intro

I was supposed to start a podcast long ago, and never got around to it. Thought I’d start off the new year by getting things rolling with a completely off the cuff impromptu intro to ZFS.

Future podcasts will most likely follow some sort of schedule, and will include guests and real audio production.

Romaco Radio EP1 – ZFS Intro [46:37]

Fix Volume Control Jitter in Ubuntu

A while ago when I switched from GNOME Shell to Unity, the first thing to bug me was the volume control in the top panel. When I would drag it side to side, it wouldn’t slide smoothly, instead it would jitter and jump back and forwards. This made it almost impossible to select the correct volume. I was convinced that this was an issue with Unity as I never had such an issue with GNOME or KDE.

As it turns out, by random prodding, that the volumes for each channel of audio were different by 3%. By installing pavucontrol and setting the levels equal in pulseaudio, the slider works correctly now. It seems that Unity is not equipped to handle unbalanced channels. The stranger thing is why they were unbalanced in the first place. This isn’t the first time I’ve had to set the balance on startup, but in all the other cases, the balance was usually something obvious like 95% to one side or the other. My audio card is a modified ASUS Xonar Essence STX on which Ubuntu uses the Virtuoso 100 driver by default. Driver bug? Maybe.

Install Steam Games to SMB Share on Linux

I use an SSD and can’t install all my Steam games onto my SSD. I don’t have a large HDD in my workstation as all my files are on my huge ZFS file server.
I simply wanted to install Steam games onto the share. Seems simple, right?

I used to bind (using mount) the steamapps directory to a folder on my server and Steam was none the wiser. However in an update Steam now uses the free space figure of the whole filesystem rather than the steamapps directory, so this option was out. In doing this, they also added the option to create new Steam libraries on other drives. Perfect! Well… No.

Steam complains that the filesystem is not mounted executable. However it in fact is – forced exec in /etc/fstab and chmodded correctly. I think SMB mounts just can’t have the flag Steam is looking for.
My solution was to create a loopback filesystem on the server.

I first created a file of the desired size on my server using dd if=/dev/zero of=/server/games-disk bs=1M count=50000. This creates a 50GB empty file on the server. From here I formatted that with /sbin/mkfs -t ext4 -q /server/games-disk. This creates an ext4 filesystem in the file. I then mounted that through my first available loopback device using sudo mount -o loop=/dev/loop1 /server/games-disk /media/games-disk. This mounts the file as a virtual loopback device at /media/games-disk. The mountpoint must exist already and can be created simply by sudo mkdir /media/games-disk. Make sure the make the image writable by more than just root on the server so you can mount it read/write.

Now all you need to do is make sure that this loopback device is mounted before starting Steam.

The Greatest Music Player of All: Clementine

I’ve used my fair share of media players and organisers in my life, on both Windows and Linux platforms. I thought I’d take you through my journey to discovering the best of them all.

Back when I was a young child, I can vaguely remember using Windows Media Player 6 casually, but as soon as I actually gave a shit about music and started my collection, I quickly looked for alternatives. Almost 10 years ago, back when I still used Windows, I settled on Foobar2000. It was fast, could handle large libraries, and supported FLAC, a huge deal with media players back then, and, sadly, still to this day. It was customizable to an extent and while not very visually appealing, it worked.

I was satisfied with Foobar2000 until I discovered and subsequently moved to GNU/Linux. Being Windows-only, I had to find an alternative. With a large selection to choose from, I settled on Amarok, KDE’s official music player, which was on version 1.4 at the time. I instantly fell in love; it had all the interface features of Foobar2000 that I wanted and brought with that a large number of new features that I found extremely useful such as moodbar support and visualizations (and a plugin for projectM). The interface wasn’t as customizable in the “large scale” way that Foobar2000’s was, but as it turns out Amarok was basically in the perfect layout already, so that didn’t bother me.

Amarok was not perfect however. The biggest issue was a bug in the database which caused the datastore to double in size every time you updated the library. This problem required me to delete the database and rebuild it very often, however it was a small price to pay. Amarok 1.4 remained my player of choice for several years until one day there was an upgrade available – Amarok 2.0.

Amarok 2.0 was rebuilt from the ground up and as excited as I was as the lines of apt scrolled by, my heart was shaken and quickly sunk by what was presented in front of me. Everything had changed. There wasn’t a single feature of the player that I fell in love with left. Every single feature that drew me to Amarok in the first place was gone. I tried – believe me, I did – but I could not bring myself to use this new version. Thanks to a few others with my same view, I was able to get 1.4 from a 3rd party PPA. But deep inside I knew that I needed a solution and using deprecated software was not a real option. The hunt began for a new music player.

The first place to look was obviously Rhythmbox – GNOME’s official player. This was already installed on my system so I thought I’d give it a shot. However, it left me with a similar situation to the new Amarok, it had none of the features that I was looking for and the feel was alien. Agreed it was definitely better than Amarok (at least stability-wise anyways), but definitely not what I was looking for.

I eventually came across a GTK player by the name of Exaile. The project’s intention was to build a Amarok 1.4 style interface and they did capture a good portion of the features. The library didn’t complain with what I estimate were about 6,000+ tracks at the time, it had moodbar support, and for quite a while, I though this was where it would end. I had tried a bunch more applications and Exaile was the closest I could find to what was looking for.

That was all until I found Clementine, when things changed forever. Clementine was a new application built on Qt and using a good portion of the old Amarok 1.4 code. Unlike Exaile, who’s goal was to imitate the layout of Amarok 1.4, Clementine set out to copy it outright and pump it full of new up-to-date features. Oh, and did I mention that Clementine is completely Linux/Windows/OSX cross platform? Ya. I first used Clementine a good time before version 1.0, but at the time of writing this, Clementine has just passed 1.2.1.

Clementine has the same analysers as Amarok and some new ones like the oh-so-epic “nyanalyser cat”. I have to hand it to the developers, they do have a taste for Internet culture. I can remember “all the things guy” in several development snapshots. Clementine also improves on Amarok’s visualizations by including projectM built-in. Clementine features global search functionality for not only your local library, but literally oodles of online services. It can transcode songs, edit tags, fetch covers, and even has it’s own Android WiFi remote.

Clementine is the product of developers who truly care and have great ideas. I recommend that if you haven’t already done so, check out Clementine’s official site and give it a go, regardless of what platform you’re using. The bottom line in my opinion: if you don’t have to be actively syncing an iPhone, use Clementine.

The Cubieboard2: The Most Under-hyped Credit Card Computer You Should Definitely Buy



When searching for a product in the likes of the Raspberry Pi and BeagleBone Black, I came across a much lesser known board known as the Cubieboard. The board is made by CubieTech, a company headed by a former employee of Allwinner technology, Tom Cubie. Recently a new model of the board went up for sale, known as the Cubieboard2.

The Cubieboard2 costs $59 and is well worth the extra money over the aforementioned products. The Cubieboard2 sports a dual core ARM Cortex A7 CPU at 1GHz (the Allwinner A20), a Mali 400MP2 GPU (more on this later), 1GB of DDR3 RAM, full-sized HDMI up to 1080p with audio, 100Mbps Ethernet, 4GB NAND flash onboard with a microSD card slot for up to 64GB cards, 2 full size USB ports, 1 USB OTG port (mini USB B), 1 SATA II port, 1 IR transceiver, analog audio in and out, 2 user configurable LEDs (green and blue), and 96 expansion pins plus a TTL serial port. The board can only power a 2.5″ HDD or SSD (as they only use 5V power) but a 3.5″ drive can be connected with external power. The device runs on 5V and can be powered from USB. It draws less than 500mA alone but with a drive and USB devices plugged in it can use up to 2A. The box contains a somewhat custom SATA cable with support for the power out on the board, a USB to DC power jack cable (but no actual power supply). You can buy a really nice 2A power supply from their store for $8, or just use a spare phone charger.

The first thing that makes this board stand out is the plethora of features. Unlike the Raspberry Pi which is built to a very strict cost, or the BeagleBone Black, which is sadly a failure in my eyes due to the numerous design fails, the Cubieboard2 does not skimp on connectivity or performance. The board is capable of decoding 4K UHD video at over 30FPS! It can also do Blu-ray and 3D 1080p decoding and has full OpenGL ES support. The CPU is exceptionally powerful too. It can easily do software rendering of HTML5 canvases in Chrome and can load web pages magnitudes faster than its competitors. It ships with Android 4.2 on the NAND flash but many other system images can be downloaded from their website including Ubuntu and even Raspbian.

The other great selling point of the Cubieboard2 is the support. The wiki contains a great deal of what developers like me want to see. It gives information on building custom kernels and Debian images, which is exactly what I need for the projects I’ll be using these for. I also find that building OS images is much more straightforward for this board than other credit card sized computers. I highly recommend this board and can’t wait to see what other people do with them.

You can find more on their official store pages at

Fix ZFS Array Appearing Corrupted When Adding A Hot Spare

Yesterday I assembled a new ZFS array. It’s a 7x 1TB SATA RAID-Z1 array. Having to replace a failed drive within the first hour of the array’s life, I decided adding a hot spare would be a good idea. After installing it in the server (hotplugging) I checked with dmesg that it was detected as drive /dev/sdi. After adding the drive with zpool add tank spare sdi and running zpool status tank, everything looked right as rain.

After rebooting the machine, I once again checked the output of zpool status tank and was told that the entire array was unavailable! One drive, /dev/sdb was unavailable, and the other 7 had “corrupt metadata”. I was shocked by what I was seeing but I was pretty sure of the cause. To test my hunch I shutdown the system, removed the spare from the machine, started it back up, and removed the spare from the pool by running zpool remove tank /dev/sdi. (You can’t use the shorthand zpool remove tank sdi here. Because /dev/sdi doesn’t actually exist, you have to be explicit in the drive to remove.) After removing the spare, everything worked as before and no data errors were generated.

The problem arose from the fact that the drive was being detected by the kernel before the others. This caused the new drive to be sdb, what used to be drive sdb to become sdc, and so on down the line. Since every drive was the wrong letter, all the metadata on each drive was technically incorrect. The question becomes, how do we fix this and avoid it in the future?

The answer is quite simple. Anyone familiar with Linux, UNIX, BSD or any other form of *NIX would know that there is a folder of symlinks in /dev/disk/ which are named using properties of the disks themselves. Of note is /dev/disk/by-id/ which uses the drive’s model and serial number. The trick to to specify those in the command when creating the array and adding spares. That doesn’t help my situation though. I already have an array that uses the standard /dev/sdX nomenclature. This is where the wonder of ZFS comes in.

ZFS has the ability to export and import storage pools so that they can be moved from server to server. One thing to note is that the drive names are not expected to remain the same during such a move. Aha! We just need to export the pool using zpool export tank and then reimport the pool using zpool import tank -d /dev/disk/by-id/. The -d flag is used to tell ZFS to look for drives in the specified directory instead of /dev/. This will rebuild the array using the new drive identifiers, which can be seen by running zpool status tank. Now no matter what order the drives are loaded in, those links never change. Try it yourself: unplug and rearrange all your SATA cables and nothing will break. Now to get back to installing my hot spare, I just ran zpool add tank spare /dev/disk/by-id/some-long-name-i-dont-remember. After that I just added the hdparm -S 150 /dev/disk/by-id/some-long-name-i-dont-remember rule to /etc/rc.local to spin down the disk and that was it.

Why I Hate Western Digital

It’s been a while since I’ve ranted about something, and my experiences a couple days ago triggered this post. First, a little bit of back story. Less than 3 years ago, I built a home server that would function as a file and web test server. The storage portion required me to purchase five 1TB SATA hard drives. Being in a redundant RAID array, they simply needed to be cheap. With all the online chatter about Western Digital being the highest quality drive manufacturer and all the drive prices being basically the same, I decided to purchase 5 WD drives. So with these new drives and an old Seagate that I grandfathered in from another machine, I assembled a 6 drive array.

Everything went well until after 3 months the first drive failed. It actually happened right in front of me. I was monitoring the server stats when the IOwait spiked when the server was apparently doing nothing. I checked the logs and found that the drive was refusing commands. Being somewhat annoyed at the infant mortality of the drive, I decided to buy a Seagate as the replacement. I can’t say exactly why, it might have been a bit cheaper but I don’t remember. About 6 months later, I decided to expand the array to 7 drives and purchased another Seagate of the same model as the one prior, seeing how it fared so well. Fast forward a year and I was met with another drive failure. This one became interesting. Lastly, just this week I was migrating all the data – in fact the entire array – into another server. This move also included a switch to ZFS from NTFS (no laughing, I needed Windows support). I had to copy the data to offline storage drives, destroy the array metadata, move the drives, assemble the new array, and copy the data back. Sounds easy. I got up to the copying data part without a hitch, but I quickly noticed the data transfer rate was very low – about 1/8th the speed it should have been. I also noticed that the operation was going through a sort of cycle: 30 seconds of transfer, 5 min of idle – however the disk usage light was lit the whole time. After doing some investigating, I found that one drive busy 100% of the time. I tried to get SMART on it using smartctl and the command took almost 10 seconds to return the data. I ripped the drive out and the throughput instantly went back to normal speeds. It was replaced with a Seagate as before.

All this may sound like ordinary drive happenings, and that may be the case, but I can’t help but notice that WD drives are among the only ones that have ever failed on me and that being said, I have owned drives from almost every company under the sun. It isn’t just these experiences that led me to my dislike towards the company. I find that their products are inferior to other manufacturers. They are larger, louder, produce significantly more heat (which leads to poor energy efficiency), and I have had a few that have had bearings go bad. My spite comes from the countless bad experiences I have had with the company’s products over the last 5 years. I have since switched to all Seagate drives and have never had a failure. I have one drive for example which has outlived 5 machines (servers and workstations) and is still chugging along. Why could I never get that reliability from WD? At my job I manage over 500 workstations with a good split of WD and Seagate drives. The ones I’m replacing 70% of the time are WDs. Something isn’t quite right.

Fix FLAC Files Not Playing on Android

A long time ago I bought an ASUS TF300T Android tablet and have been very happy with it. The only thing that it never did correctly was play FLAC audio files. According to Google, all versions of Android after 3.1 can natively play FLAC files, and since my device runs 4.1 it should be no problem, right? Wrong. Most of my library is in FLAC, and is very well organised with proper filesystem structure, tags and cover art. When I first got the device I dumped a chunk of my library on the device and was surprised to see that all but one album was unplayable. All the unplayable media was listed in the library with “unknown” tags and song lengths of 0:00. The strangest part was that just one album managed to be perfectly fine. It not only played and had the correct tags, but the embedded cover art also displayed flawlessly. I tried to compare the files to find a discrepancy as to why they were not playing, but all the files checked out exactly the same. This baffled me for the longest time until I eventually gave up and just scratched all my music to MP3 just for the device.

A few months later, I had some free time and thought I would take another crack at the problem. This time I thought I would take a more technical approach. Using my trusty FrHed hex editor, I opened a file that would play and a few files that would not so I could compare the files at the byte level. It didn’t take me long to find a single discrepancy that made me literally hit my head against my desk. The files that played had a FLAC tag at the beginning of the file followed by the data. The files that did not play started with an ID3 tag followed by a FLAC tag and then the data. My new theory was that the Android codec did not like ID3 tags in FLAC files. I tested this by removing the ID3 tags from a few other files and lo and behold they played just fine! I tag all of my library with both FLAC and ID3 tags because certain devices and media players liked the ID3 tags better. From now on I just strip the ID3 tags before I put files on my device and everything works fine.

Canadian ASUS TF300T Jelly Bean Update Now Available

The title says it all. Just a week after the USA got the Android 4.1 Jelly Bean update, now Canadians can join in on the fun. Start mashing that update button!

Romaco Canada TA-H1 Vacuum Tube Headphone Amp Done!

As you can see, my 12AU7 vacuum tube headphone amplifier/preamp based on a single ended class A design is finally finished! Since the last time I posted about this project, there have been a few changes and additions. I added a nice bright blue LED into the tube socket as a power indicator. I also removed the separate heater/main power switches and went with a single on and off switch. I did this mainly because there wasn’t enough room inside to accommodate the insanely large Cherry switches I bought. This was mainly because I had to redesign the power supply. I originally wanted to use a simple LM317 for the voltage regulation, but the device oscillated and the noise floor was way too high. I had to rip it out and used a zener diode with a darlington emitter follower. It wasn’t pretty because I didn’t have the right parts, but in the end it works and is silent. The only problem with it now is that during the warm-up phase there is intermittent crackling on the output. It goes away once nominal temperature is reached. I am pretty sure that it is because the socket has oxidized or is dirty. I don’t have DeoxIT, but I retensioned the socket and it seems to be better now, but not entirely fixed. It still retains the ability to use both an 18V DC input from a transformer or SMPS as well as a direct unregulated input for 12V SLA batteries. As for performance, I don’t really have a good enough scope to measure the accuracy as well as I need to calculate something like  THD or SNR. All I can say is that it beats my IC-based headphone amp that I have been using until now in both frequency response (especially low end) and output power. I can’t calculate the output power directly, but I assume it is somewhere in the range of 200-400mW. The amp can drive basically any impedance headphones from 8-600 ohms. My Shure SRH-440s with an impedance of 44ohms sound great!