Do you wear a watch?

Sitting in a bus, or a train, or even walking about the streets is always a good opportunity to take a look at other people and to see if they are wearing a wrist watch. Ok, I don’t actually do that often, but it is always an interesting experiment to perform. I’ve recently heard arguments that [wrist] watches are no longer needed, that they are a thing of the past. People will now take a look at their phones to see what time it is, or glance at a clock on the wall. However, I think watches are still relevant in these modern days. Here’s why.

My watch!

Sitting in a bus, or a train, or even walking about the streets is always a good opportunity to take a look at other people and to see if they are wearing a wrist watch. Ok, I don’t actually do that often, but it is always an interesting experiment to perform.

I’ve recently heard arguments that [wrist] watches are no longer needed, that they are a thing of the past. People will now take a look at their phones to see what time it is, or glance at a clock on the wall. Granted, those are both reasonable ways to get the time, but to me, they compliment wearing a watch, rather than replacing it.

I myself have gone through various phases – I remember that I would wear my watch compulsively as a child, and set it every day to the radio. I would then know exactly to the second when the school bell would go off. Perhaps this was to know when I would be done with a boring class, or be free to go home, and in a way, it was pretty fun! In my teens, though, I stopped wearing a watch, although I can’t remember the reason. Perhaps it was because I lost my watch.

However, at some point or other, one will always need to know the time. When I went traveling for 2 months in 2008, I decided to start wearing a watch again. At first, it was actually annoying to wear it, and I always couldn’t wait to take it off. However, I decided to keep wearing it. After a while, I got used to it and since then, always wear one.

In the Fall 2010 semester, I decided to take a class on Celestial Navigation, and it was here that I really realized the advantage of using a wrist watch. I decided to make a list of why one should wear a wrist watch (My points generally refer to a digital wrist watch, but analog wristwatches still have uses), and here it is:

  • A watch is a simple device which won’t fail easily. If you kept up with the news, you may have heard about various glitches in the iPhone which caused its alarms to go haywire during the DST change and the New Year. Now, there are basic watches and fancy watches, but the vast majority of them are simple devices which perform a few tasks, and perform them well.
  • A watch will last a long time. How often do you change your computer, or your phone? Probably a lot more often than you’ll change your watch (as long as you don’t lose it). A watch will continue to do its task 10 years from now the same as it does it right now. That’s real value!
  • A watch is durable. Even the cheapest of watches can last a long time, and most of them can survive being dunked in water, taken for a swim, or a fall to the ground. You can’t say the same of most phones.
  • A watch has a long battery life. Ever gotten frustrated because your phone ran out of juice? While phone battery life is generally measured in hours or rarely, days, a watch has its battery life generally measured in years! For example, my cheap watch is supposed to last 10 years.
  • A watch is convenient to look at. You don’t have to take something out of your pocket, but you just glance at your arm. There are situations when the usage of phones is frowned upon, since people may not know you’re just checking the time. Further more, you don’t have to press a button to turn on / light up the screen to see the time (unless it is dark, of course)
  • A watch has a known accuracy. If you use your watch often, you will eventually know whether it’s fast or slow. For example, I know my watch gets fasts by one second every week, but anyway, I set it every week. Meanwhile, if you rely on some clock on the wall, you don’t know if it’s accurate! (Of course, most phones are able to synchronize themselves, which can be an advantage or disadvantage) There are cases where you need to know the time very accurately, especially if you are using it for navigation. (A watch which is 4 seconds off can result in your navigation being a mile off!)
  • A watch immediately tells you the seconds. Most phones won’t tell you the seconds, unless you launch a dedicated application to show it.
  • Cheap watches function arguably just as well as more expensive ones

Given the cheapness of watches these days, personally, I feel that there’s no reason not to wear one. Perhaps some people think it’s ugly, and I can’t say anything about that, but I know that there are a lot of fancy “fashion” watches around. Others feel that it’s uncomfortable, and that’s fair enough – it can be weird having something around your wrist all the time, but I say – try it for at least 2 weeks and only then if it’s still uncomfortable, take it off.

I don’t know, maybe there are valid reasons for not wearing a watch. Please feel free to let me know if you have one!

Network File Server using FreeNAS (Part 1)

Juggling around files can be a nightmare when you have multiple computers, especially when you use multiple operating systems. Trying to back up files can easily turn into a mess once you have multiple copies of files here and there, and you may constantly worry about hard drive failure.

By building a NAS yourself, you can solve these issues and save a lot of money compared to buying a commercial NAS product!

Juggling around files can be a nightmare when you have multiple computers, especially when you use multiple operating systems. Trying to back up files can easily turn into a mess once you have multiple copies of files here and there, and you may constantly worry about hard drive failure.

These are some of the reason which drove me to set up a NAS (Network Attached Storage) server to serve my files across my network. My requirements were the following:

  • At least 2TB of storage
  • Able to serve Windows, Mac OS, and Linux (SMB, AFP, NFS) at gigabit speeds
  • Low power consumption for 24×7 usage
  • Protected against hard drive failure
  • Protected against accidental file deletion
  • As cheap as possible

There are various companies which provide NAS solutions – for example, Synology and QNAP, as well as regular hard drive / network device manufacturers like Western Digital and Buffalo. However, as I looked through their products, I realized that while they looked very nice, they tended to be expensive and limited (depending on how deep your pockets are). For example, the Synology DS411J and QNAP TS-410 (both 4-bays) both cost around USD360, and once you’ve got them, they don’t tend to be that flexible.

So, I decided to DIY a server. Firstly, I looked at OS solutions, and settled on FreeNAS 8 (Using something like Solaris/FreeBSD would be even more flexible, but for simplicity, I went for FreeNAS which is small and has a decent web interface). The main attraction I was looking for was ZFS, a file system built to ensure data integrity. It can be thought as a marriage between hardware & software RAID, which is very beneficial because it avoids many of the write hole problems with a RAID system, and can self-heal your data. I won’t go into the details of ZFS, which can be found elsewhere, but it is clearly a very capable file system.

ZFS would provide me the following:

  • RAID-Z1: By using one of the drives in a pool for parity, I would be safe from a single hard drive failure.
  • Dataset quotas: Ability to limit datasets (or to effect, the shares) to a certain size.
  • Snapshots: You can think of this like Time Machine for Mac OS, although, to me, even better, because snapshots are instantaneous, and provide me safety against accidental file deletion, etc. They don’t take up any extra space, and allow me to roll back my file server to a particular state. Here’s how to use snapshots with Windows & Mac OS [Coming soon]
  • On-the-fly compression: Using fast compression algorithms (You can actually choose from a range – Gzip/LZJB), data can be compressed when written to the hard drive, saving space and in some cases, enabling even faster speeds on the hard drive. This is because most reading/writing is limited by hard drive speed and not CPU compression speed (At least with a modern CPU).

And having a DIY NAS server would give me the following:

  • A fast CPU for on-the-fly compression/transcoding – which I can upgrade in the future if needed
  • Flexible amount of RAM
  • Up to 6x SATA HDDs, plus with PCI-E expansion, I could easily put up to 15 Hard drives in total, for a LOT less cost than a commercial NAS
  • Ability to upgrade to 2x1Gbps network interfaces (or more), to double my network bandwidth
  • USB3.0 support

Of course, a DIY solution would tend to consume a bit more power than a NAS solution, given that it has a lot more CPU/RAM, and a lot depends on the power supply efficiency.

Parts & Build

In the end, I decided to go with the following:

  • Intel G620 2.6GHz Processor: The cheapest Socket 1155 CPU I could find at the time. It’s already a lot faster than needed, although if you do use on-the-fly encryption or compression, you can saturate it
  • Intel DH67BL-B3 microATX Motherboard: One of the cheapest boards I could find with at least 5x SATA ports. I decided to go with this because it had an Intel network controller, and according to some reviews I read, the lowest power consumption. It also gives me USB3.0 support which could be useful in the future.
  • 2x4GB Kingston DDR3-1333MHz RAM: Since RAM is cheap, and ZFS benefits from higher levels of RAM, 8GB made sense. The motherboard, supporting up to 32GB of RAM, can be easily upgraded in the future
  • 3x2TB Western Digital WD20EARX “EcoGreen” Hard drives: Not nearly the fastest drives around, but from tests (at least of the earlier generation WD20EARS), they appear to have the lowest power consumption
  • Corsair 4GB Flash Voyager USB flashdrive: One I had lying around to install FreeNAS on

All this added up to a grand total of USD422, hard drives included (USD196 without). I didn’t have a free case lying around at the time, so I just built it open:

After updating the BIOS, adjusting fan speeds, etc., I installed FreeNAS 8.0.1-RC1 onto my flash drive and booted up. Everything was detected without problems and the web interface was accessible. I created a RAIDZ1 array using the 3 drives, resulting in 3.56TB of usable space.

(Note: I had to use the wdidle3 tool to ensure my drives wouldn’t load/unload their heads so often, which could lead to premature failure)

Performance

Using the linux dd tool, I did a quick benchmark of the hard drives, which gave 217.7MB/s writing and 226.1MB/s reading. More than fast enough for me, given that gigabit LAN maxes out well before that anyway.

Next, I tested the network performance using iperf, and with 2 clients connected, the interface managed to push 950Mbps (119MB/s). All was looking well, so I quickly set up a CIFS/SMB (Windows) share and copied a file over. Both ways, I was getting 112MB/s. I also set up an AFP (Apple) share which got me the same 112MB/s.

Conclusion

I managed to get a file server which has great data integrity features, and can serve all my network clients. In addition to the regular network shares, I also use it as a “Time Capsule” of sorts for the two Mac OS machines on my network. In particular, for much less than what it would cost to buy an equivalent NAS or Time Capsule!

FreeNAS is still a work in progress, and isn’t perfect right now (still waiting for them to add VPN and torrent support), but it’s definitely on its way.

Further

FreeNAS: Simultaneous AFP/CIFS shares done neatly

Home network setup

Recently, I made the change to fiber optic for internet, boosting my download/upload speeds to 5Mbps/5Mbps. At the same time, I decided that it was time to do some upgrades to the network in my house, in particular a gigabit network and having all computers on a domain. In terms of complexity, of course this is a very small network setup compared to those you get in large companies and campuses, but for a home network, it’s probably more than an average user may have.

Recently, I made the change to fiber optic for internet, boosting my download/upload speeds to 5Mbps/5Mbps. At the same time, I decided that it was time to do some upgrades to the network in my house, in particular a gigabit network and having all computers on a domain. In terms of complexity, of course this is a very small network setup compared to those you get in large companies and campuses, but for a home network, it’s probably more than an average user may have.

Unifi, the service I’m using, provides a combination of Internet, VOIP (Phone), and IPTV in one package. This is achieved through VLAN tagging, in which various services are assigned a VLAN Tag ID so that the packets coming in can be differentiated from one another.

The fiber modem is provided with the service. This is then connected to a provided D-Link DIR615 router. Initially, the router is setup to handle all routing and connections, but since I prefer DD-WRT, I decided to use it solely as a VLAN Bridge (i.e. it removes the VLAN tags from incoming packets, and sends internet packets to Port 3, and IPTV packets to Port 4). In addition, I changed its IP/Subnet to the same subnet as the rest of my network and disabled its DHCP server, so that I can manage it from any computers on my network.

All routing is handled by my main router (a WRT54GL 1.1 running DD-WRT, overclocked to 250MHz with a heatsink mod), and is setup on a 10.0.0.0/255.0.0.0 (Class A) subnet. I made this decision after my previous Class C (255.255.255.0) network became a mess. Now, all IP addresses are nicely organized into the following pools:

10.0.0.1-10.0.0.100: Routers and bridges
10.0.0.100-10.0.0.150: DHCP clients
10.1.0.1-10.1.0.255: Static LAN clients
10.1.1.1-10.1.1.255: Static WLAN clients
10.1.2.1-10.1.2.255: Static clients with Virtual/Other Interfaces
10.2.0.1-10.2.0.255: VPN clients

Thus, for a computer which has both LAN & WLAN, the last digit [octet] of the IP address is the same. It’s LAN address would be 10.1.0.34 while its WLAN address would be 10.1.1.34. If it had a 3rd interface, it would be 10.1.2.34, etc. This makes it much neater. Of course, not wanting to memorize all the IP addresses, I decided to use DNSMasq for DNS services, with the following settings:

strict-order
domain=lan
local=/lan/
expand-hosts
address=/router.lan/10.0.0.1
address=/vpn.lan/10.0.0.2
address=/vlan615.lan/10.0.0.3

This allows me to access other machines by simply adding their hostnames to DNSMasq. This helps a lot for my machines running Web interfaces, so I can just go to http://router.lan/, etc. Provided that all clients use the router for DNS queries, it all works. Also, strict-order was required because I use Google DNS for my other DNS queries but also keep an ISP DNS server as backup – and this ensures that it uses DNS servers in the order I specified, rather than randomly (?) selecting one or the other.

A 2nd WRT54g router (running DD-WRT) adds OpenVPN support in my network, allowing me to access my network from all over the world. Ideally, my main router would run this VPN service, but as the WRT54g is an old router, it doesn’t have enough RAM (only 16MB) and processing power to achieve all this. In the future, I hope to offload this to my NAS Server.

Finally, my wired ethernet devices are mostly plugged into the last device – an 8 port gigabit switch (HP Procurve 1410-8g). This required the most work, including climbing in the attic to lay Cat-5e cable to various parts of the house (upstairs), as well as plastic channels carrying Cat-5e downstairs. Originally, I was going to get a managed switch (HP Procurve 1810-8g) so that my NAS (File) server would use an aggregated link for 2Gbps of bandwidth, but due to the extra price, I decided to just go with the unmanaged switch.

Having gigabit makes a world of difference – transferring data between various computers is much faster, a feature especially useful when I built my NAS/File server.

Some may say that my routers (WRT54g) are fairly old, and yes, that’s very true. However, in all my internet usage, I haven’t encountered any issues with them, or any internet slowdowns. I was thinking of upgrading to wireless-N, but since most of my devices are already on the wired gigabit network and most clients are only G-capable, I decided that for now, it’s not worth it.

For those wanting to setup unifi, do check out rizvanrp’s Unifi handbook.

Here’s a basic network map of my setup:

Facelift

I’ve been tired of the look of my site for a long time now – so it’s time to welcome a new look, even though the content is still very old.

I probably still won’t be posting to this blog as much as I used to back in the old days, but hopefully for anyone visiting, it won’t be as much of an eyesore as it used to be!

Enjoy!

I’ve been tired of the look of my site for a long time now – so it’s time to welcome a new look, even though the content is still very old.

I probably still won’t be posting to this blog as much as I used to back in the old days, but hopefully for anyone visiting, it won’t be as much of an eyesore as it used to be!

Enjoy!

Mac OSX Lion not sleeping

While using a brand new 2011 iMac (21″), I noticed that putting it to sleep (Apple Menu > Sleep) would not work – the screen would turn off, but the computer itself would still remain on.

Here’s the solution – including an application which you can use!

While using a brand new 2011 iMac (21″), I noticed that putting it to sleep (Apple Menu > Sleep) would not work – the screen would turn off, but the computer itself would still remain on.

I decided to do a bit of research and found that running the command pmset -g assertions from the terminal would list any conditions currently active which are preventing the OS from sleeping. In my case, it was file sharing as well as remote TTY sessions (via SSH), which were solved by issuing the command sudo pmset -a ttyskeepawake 0.

Now, Apple should really be informing users if there are any issues preventing a computer from sleeping. It makes it even more annoying since the iMac has no status LEDs, so it’s almost impossible to tell if it’s gone to sleep, except by listening very carefully for the fans/HDD spinning down.

I decided to write a very quick application, which, when launched, tries to sleep the computer, and if there are any conditions preventing it from doing so, it will list them out.

You can download it here along with the source code (which is messy and perhaps buggy, since I did it very fast). For me, it works perfectly. I can’t claim any responsibility for running it, although I don’t see how it could cause any issues.

(I also found another application here which seems like a better/longer term solution, although I have not tried it out myself and so claim no responsibility. You may want to try it instead, if you’re interested!)

Sleep Checker.dmg, 98KB
(SOURCE CODE)
Requires OSX 10.7 Lion and Python 2.7 (Already installed by default on Lion)

Screenshots

If there are conditions preventing sleep:

Once it’s ready to sleep:

Apple, please fix this by letting users know if there are conditions preventing system sleep, and providing a “force sleep” option, perhaps?

Interpreting pmset

If you’re interested in what’s actually causing the problem, here’s a quick rundown on the output of pmset -g assertions:

$ pmset -g assertions
9/30/11 2:48:44 PM GMT+ 
Assertion status system-wide:
   ChargeInhibit                           0
   PreventUserIdleDisplaySleep             0
   PreventUserIdleSystemSleep              1
   NoRealPowerSources_debug                0
   CPUBoundAssertion                       0
   EnableIdleSleep                         1
   PreventSystemSleep                      1
   DisableInflow                           0
   DisableLowPowerBatteryWarnings          0
   ExternalMedia                           0

Listed by owning process:
  pid 42096: [0x0000012c0000a470] PreventSystemSleep named: "com.apple.AppleFileServer" 
  pid 19: [0x0000012c00000013] PreventUserIdleSystemSleep named: "com.apple.powermanagement.ttyassertion" 
        Details: /dev/ttys000
        Localized=A remote user is connected. That prevents system sleep.

...

You can see that there are 2 conditions which are preventing sleep in this case (PreventSystemSleep and PreventUserIdleSystemSleep). One of them is a process (basically, like a program/application) which has the ID 42096 and is called “com.apple.AppleFileServer”. This happens to be file sharing. The other process (PID19) happens to be a condition which is asserted when remote users are connected via SSH.

You have to manually terminate these processes or remove their assertions, but do be careful when doing so because not all processes can be killed neatly – you may end up crashing your system if you’re not careful!

For more information on pmset, you can issue the command “man pmset” to get help on how to use it.