Tuesday, May 08, 2012

VirtualBox DHCP Nameserver Configuration on OS X

I recently maxed out my desktop with all the memory it could theoretically take. € 100 poorer, and 16 GB richer, I thought the best way to make use of all this excess memory would be to run virtual machines on it, and maybe set up a virtual cluster, and install some cloud-savvy software on it, like ElasticSearch, and watch the fun.

So I set out to install Ubuntu on VirtualBox. I chose VirtualBox over VMWare because it is fully open source, and I have found open source software to be typically of higher quality than free, closed source solutions at these "low" levels of innovation (i.e., technologies that don't affect end-users all that much, like web servers, and programming languages).

The installation process is dead simple, and is documented numerous times on the internet. I wanted simple internet connectivity on my guest OS, just browsing the internet. Unfortunately, it didn't work "out of the box."

Problem: Internet doesn't work on a freshly installed Ubuntu guest on an OS X host.

Solution: As it turns out, VirtualBox will take its resolv.conf(5) from OS X's resolv.conf(5), if it finds one. I had toyed with mine when setting up my router, and so VirtualBox picked it up and shoved it into Ubuntu.

This is useless, since VirtualBox guest machines exist in a virtual network, inside a 10.0.xxx subnet, behind a virtual router set up by VirtualBox. So the imported resolv.conf from OS X means your guest OS pretends to be a real computer on your network, when it absolutely isn't.

That's fine, that can be fixed. Just fix interfaces(5) to contain the appropriate directives to manipulate the resolv.conf(5) (resolv.conf(5) is now a derived file, so changing the file directly is pointless, you have to change the upstream configuration files from which it derives, in this case interfaces(5)).

So the relevant part of your interfaces(5) will look something like:



iface eth0 inet dhcp
    nameserver 10.0.2.3
    gateway 10.0.2.2
    dns-nameservers 10.0.2.3
    dns-search 10.0.2.2


Now it's just:



$ sudo ifdown eth0 && sudo ifup eth0

And you should be in good order.

But now even though you're connected, you won't be able to resolve FQDNs:


$ ping google.com
ping: unknown host google.com

To achieve this, you need to turn on VirtualBox's built-in nameserver.


$ VBoxManage modifyvm "octavius-v" --natdnshostresolver1 on

Voila!

Discussion: For some reason, VirtualBox comes with this turned off. I'm sure it's a good reason, but I just don't know what that reason is. Finding this information, I found to be non-trivial. It's not in the user manual, and Google'ing for it yielded slim pickings, until I lucked out.

Another thing to note is that VBoxManage(1) doesn't come with an informative man page.

Also, the syntax for these switches that can be flipped is not explained. --parameter1 refers to the parameter for guest machine 1. So, apparently, --natdnshostresolver2 refers to your second guest machine, and so on and so forth.

Friday, October 07, 2011

Steve Jobs is dead. Long live Steve Jobs.

He was a polarizing figure; a lot of people loved him like a seer, a lot loathed his ability to make others love him like a seer. Most admired him from a safe distance.

Apparently, he was a mercurial, highly unsentimental man. One of his first acts as CEO was to empty out displays of old products on company premises. He never believed in looking back, he considered it baggage, an anathema to be shunned. He went to great lengths to say the great products of Apple were not made by him alone, but by an army of talented people, doing difficult work.

Despite the 300 or so patents to his name, anybody that has been involved in the making of anything non-trivial knows the many pairs of hands and eyes something has to go through, to make something great. The fact that none of his patents are solely under his own name, bears witness to this fact.

What will really live on is the story of his life. He was born a child out of wedlock, given up for adoption after his birth to relatively poor parents, who could not even finance his education. When success came, he was kicked out of his own company, betrayed. And the final setback that ultimately took his life, contracting a rare form of pancreatic cancer.

Despite all this, he oversaw some of the greatest successes of our time. We love turnaround stories, and Steve Jobs, and by extension, the company he founded, is one of the greatest turnaround stories of our time.

He achieved it not through luck, but through sheer determination of will, faith in himself, and the vision to realize that the times, they are-a changin'.

That will be his legacy. And it won't be just his legacy, but of many unassuming men and women before him, who overcame similar odds to achieve similarly lofty goals.

Mr. Jobs will live longer than most of his mourners. Some of them will rise to the occasion, and live the lessons he espoused. Most will fail, some will succeed. But all of them will be happier for it. And we will all be better off for it.

May he journey well, to whatever lies beyond.

Sunday, July 17, 2011

Awesome Tool to Justify Text: Par

I recently came across a problem: I wanted to format text in my favorite text editor (vim) in a very specific format. Lines should have a maximum of n number of characters on them, and it should justify properly, nice and pretty, and I shouldn't have to think about it. It should be automagic.

I came across a utility called par. It's a very powerful utility that can process a block of text into an organized format, and I think not enough is being said about it!

http://jmcpherson.org/par.html

It's an open-source project, and it adopts one of the core tenets of the Unix philosophy: do one thing, and do it well.

All I can say is when I use it, it does all the magic I need it to do, and in a sense, the technology 'disappears.' It's a funny thing to say that since it is a tool designed by a technical person, for technical people (very few non-techies use vim). But it's true, even at this relatively deep level of technology, the really good tools... simply disappear.

It's coming across gems like these that make me wonder why we put up day in and day out with all the poorly written, poorly designed software out there. From the cruft of Microsoft Word, to the sluggishness of Firefox, we have to put up with these things regularly.

A lot of it has to do with the fact that writing good software is actually quite hard. But most of it is really to do with our intransigence. We get used to a toolchain and refuse to be flexible and move around.

I think a bit more toolchain promiscuity would make us all a little happier.

Thursday, June 30, 2011

How to Make Simple White Rice

Rice is a staple crop in vast swathes of the world. It is said to have been domesticated on the flood plains of Iraq at the dawn of civilization, and is one of the cornerstone crops that allowed for agriculture, dense population structures, and the resultant technological, and economic development of modern civilization.

Rice is kind of a big deal. It gets a bad reputation nowadays, because carbohydrates have been demonized. I know better, though.

This is a simple recipe on how to cook white rice.

Ingredients:
  1. Rice
  2. Water
  3. Salt
Instructions:
  1. Put whatever amount of rice you want to eat into a pot (usually, it's about 1 cup for 1 person)
  2. Put your index finger on the surface of the rice, and fill it with water till the surface of the water reaches the first knuckle of that finger
  3. Add salt to taste
  4. Let it boil
  5. Take it off the cooker once the water has evaporated
You don't need to drain the starch from this recipe. The amount of water to put in is always one knuckle's distance, from the surface of the rice, to the surface of the water. It's an old standard used for white rice, no matter how much rice you have. This works best with long grain white rice, but should hold for all kinds of white rice.

Note that for health reasons, sometimes it's good to add water "in excess" (i.e., a lot more than you need), note when the rice is cooked, and then drain the rice. This reduces the amount of starch you ingest, which isn't so bad a thing. Choose your poison, if you'll pardon the phrase.

Whatever works for you. This is an easy recipe, and rice (white or brown) is an awesomely delicious thing to eat.

Wednesday, June 22, 2011

Amsterdam: First Glance, Part II

Public Transport

Public transport in Amsterdam is, on the whole, quite good. Arrival times are published on a per-station basis. In Singapore, they only publish bus frequencies, which are really rough guidelines. Sometimes the frequency metric is meaningful, often-times, it's complete bollocks.

Here, they have ETA's (estimated time of arrival) for each train throughout the day, published in a very nice format. This is extremely handy, and I much prefer it to Singapore's unwieldy, non-committal, and of-times plain inaccurate approach.

But public transport here is extremely heterogenous.

There are trains, there are metros (which are basically trains, but if you call them that you'll completely confuse people), and then there are trams, which run on metro tracks (and often have overlapping routes), and are, in essence, a subset of the metro, but with the exception that they ply downtown streets, which neither the metro nor the trains do.

Confused yet?

The word train is used to connote inter-city trains. So you don't take a train to Amstelveen (a satellite city of Amsterdam), you take a metro. You take a train to Utrecth (a neighbouring city), but you can also take a metro, because some metros actually go to neighbouring cities. They metro and trains run on the same gauge, they look similar, have overlapping routes, but are, at least in terms of nomenclature, completely different.

The trams ply city roads within Amsterdam-proper. They have tracks laid down major roads in the city, and they merrily roll by with a quiet electric hum.

The metro links far corners of the city, and basically link up the disparate parts of metropolitan Amsterdam. They also sometimes go to neighbouring cities, like in the example above. But they're not trains.

Confusing enough for you?

They try, though. There's a unified RFID prepaid payment mechanism called OV-chipkaart. You top it up with money, and spend it through your tram/train/metro rides. The only thing is, not all the stations are closed off. Some train stations won't allow you to exit if you don't tap. Some don't seem to care, with permanently open gantries. So you can forget to tap in, then be on your merry way out of one of the stations that are secured, and then get stuck.

It's just asking for people to take free rides, and I did that initially when I didn't know how to make sense of any of it, even though I was wielding a bona fide OV-chipkaart. Even when you have made sense of it, they have different sets of tapping machines, some for inter-city, some for metro, and tapping the wrong one can be very punitive in terms of the money they deduct from your card.

It's all over the place. Just remember, when in doubt, don't pay.

Sunday, June 19, 2011

Amsterdam: First Glance, Part I

I've been in Amsterdam for about 4 months now. I've had some time to settle in and soak up the atmosphere, the language, and local attitudes. In many ways, it's still too soon to form real opinions, so this isn't a definitive snapshot of life in Europe for a brown outsider. But I think it's a pretty close indicator.

Opening Hours

Everything closes at 6. If you need to fix your bicycle, you need to take time off work to get it done. Supermarkets open till 8pm, which is a small mercy. Thursdays are special, some shops (note: some, not all) are open till 8pm.

To an Asian, this is the weirdest thing ever. In Asia, even stationery stores are open till 9 or 10pm. The city doesn't even begin to sleep until about 11pm.

Over here, by 8pm, most stores are shuttered, and only food and beverage, and entertainment facilities are open.

Food

I'm a South Asian, and I've lived a goodly portion of my life in South-East Asia. I come from a heritage of North Indian, and Thai food, arguably some of the best food ever invented. I have high standards for food.

Unfortunately, the Dutch don't know how to eat.

It's a little disappointing because their southern neighbours the Italians have made an art-form of the thing, and their near neighbours the French have a good taste for the stuff.

Honestly, though, it's okay. Amsterdam is awesome in so many other ways, and is home to so many visible minorities that finding good food isn't hard at all. The only thing is, it won't be Dutch.

Banks

Tellers at banks don't take cash.

I needed to pay my deposit and first month's rent to move into my new apartment. I had applied for an account, got an account number, but I hadn't received my ATM card, which comes in the post. My putative landlord wanted a bank transfer, it's easier for tax purposes, he told me.

The tellers were behind the counter, serving customers. But they wouldn't take cash. I did a double-take when I heard it the first time. I politely asked the young lady from ABN AMRO to repeat herself. Yup. Those people there? Inside the bank? Behind the counter? Your money is no good with them.

I talked my landlord into accepting cash.

Wednesday, June 15, 2011

Bash Color Prompt Problems With Reverse-I-Search in Terminal.app

I recently colorized my bash prompt. It's a nice touch, and with a bit of taste, it's good design. Makes visual parsing very quick.

Gone are the days of souped up command-line prompts that look like they're about to lift off into orbit. For a trip down memory lane, check this out. I stumbled across it while Google'ing this problem. Good fun. :-)

No, my prompt is very Spartan:



shaque@marius is user@host (so you know what computer you're on), ~/git_tree/users is the present working directory, and ihaque/vim-tweaks is my git branch.

All of this is awesome. The colors are awesome too (Solarized), they're specially picked colors for a low contrast delta between the foreground and the background, while maintaining excellent readability over prolonged periods. Prevents tired eyes. Go to Ethan Schoonover's website I've linked to, and integrate it into your environment. Srsly.

The problem: once you have colors, and if you use bash's builtin reverse-i-search for previously typed commands, things get fudged. Terminal.app doesn't write the characters properly on-screen so if you reverse-i-search for a previous command, then scroll backward or forward to edit it, it doesn't display correctly.

I spent a lot of hours tinkering with my bash prompt to make this work. It was awful, because bash syntax is very un-pretty. Look at the code for my prompt:

export PS1="\[\e[0;36m\]\u@\h\[\e[m\] \[\e[0;34m\]\w\[\e[m\] \[\e[0;33m\]\$(parse_git_branch)\[\e[m\]\$ "

Uffffff.

The fix: use iTerm.app. Terminal.app doesn't render color properly, apparently. I don't have an explanation for this yet, but iTerm.app will gladly handle your colorized prompt and finicky interactive shell features with barely a sweat.

It's also an actively maintained open source project with a shorter release cycle (read: one that is not pinned to that of OS X's).

Bless the folks at Apple, I think they did a pretty good job with Terminal.app. It's miles and miles better than any stock CLI shell Microsoft ever shipped with their operating systems, and the anti-aliasing and opacity control is better than anything I've seen on Linux (though Terminal.app is not nearly as feature rich, or as responsive as anything on Linux).

Credit goes to Terminal.app, I stuck with it for a long time, but I'm switching to iTerm.app now. It's just better.

Labels

About Me

My photo
Singapore
I write essays in my spare time on things that are important to me. The ones that I feel are any good, or make any sense, I put them up here. :)