Friday, August 28, 2015

The one with more OSes

I recently came into ownership of a 2008 unibody MacBook. One of the first aluminum ones. It's been serving me well, and I recently replaced the unused DVD-ROM drive with a drive caddy containing a second SSD I had lying around.

I didn't really have a use for the space so I thought I would challenge myself to get Ubuntu Linux installed on the second drive.

I'm going to detail my experiences here while trying to be as general about the installation and EFI boot process as possible.

First I downloaded an Ubuntu ISO image and use hdiutl to convert it to a DMG:

hdiutil convert -format UDRW -o ubuntu.img Downloads/ubuntu-15.04-desktop-amd64.iso

This will actually generate a file named ubuntu.img.dmg, but we're just going to write the contents to a USB flash drive, so the name doesn't matter.

I then plugged in a USB flash drive and used diskutil list to determine the device path - /dev/disk4 in my case.

Using diskutil again, I prepared the flash drive to accept the installer image:

diskutil partitionDisk /dev/disk4 1 "Free Space" "unused" "100%"

Be sure to replace /dev/disk4 with the device path you determined in the previous step.

Finally I copied the installer to the flash drive:

sudo dd if=ubuntu.img.dmg of=/dev/disk4 bs=1m

Again, be sure to replace /dev/disk4 with the correct path.

Eject the flash disk (replacing /dev/disk4):

diskutil eject /dev/disk4

Now it's time to boot the target Mac. Plug the USB drive into the Mac and hold Option while it boots.

You should eventually see at least two boot selections. One will be a yellow USB drive icon with the label "EFI Boot". Use the cursor keys to select it and press enter.

Now you can install Ubuntu normally. Ensure you have free, unpartitioned space. I was using an entirely separate drive from my OS X drive, but you need to ensure you don't overwrite your OS X install. Also, create a small 128MB partition during the install (or from Mac OS X prior to the install) - this will hold the EFI loader.

Once Ubuntu is installed you need to create an EFI boot loader so the Mac's firmware can boot the OS.

You need to have GRUB2 installed to accomplish this. Here's the command:

grub-mkstandalone -o boot.efi -d usr/lib/grub/x86_64-efi -O x86_64-efi --compress=xz /boot/grub/grub.cfg

This will generate the file boot.efi in the current directory. You need to get this to the Mac side of the computer. Either copy it to another USB stick, or over the network to another system.

Now reboot back to Mac OS X.

Make sure the 128MB partition is formatted as OS X Extended Journaled.

Open a Terminal window and navigate to the EFI partition you created, possibly something like:

cd /Volumes/Ubuntu_EFI

Create the required directory structure:

mkdir System mach_kernel
cd System
mkdir -p Library/CoreServices
cd Library/CoreServices

Copy the boot.efi we generated into this folder (CoreServices).

Open a new text file in your favourite text editor (I prefer vim) named SystemVersion.plist with the following contents:

<xml version="1.0" encoding="utf-8"?> <plist version="1.0"> <dict> <key>ProductBuildVersion</key> <string></string> <key>ProductName</key> <string>Linux</string> <key>ProductVersion</key> <string>Ubuntu</string> </dict> </plist> If you have an icon file in .icns format, you can copy that into the root of the volume (i.e. /Volumes/Ubuntu_EFI)

Finally, we need to "bless" the volume

sudo bless --mount /Volumes/Ubuntu_EFI

Also, to set a boot label other than "EFI Boot" we need to use the bless command again:

sudo bless --folder /Volumes/Ubuntu_EFI -label "Ubuntu"
sudo bless --folder /Volumes/Ubuntu_EFI/System/Library/CoreServices -label "Ubuntu"

Substitute your own desired label for "Ubuntu". Why do I run it twice? It takes a full reboot cycle to see if trying to set the label was successful or not. I just ran both of those together between reboots - so I have no idea which one was the one that set it. Sorry.

So hopefully this will get you on track to getting Linux set up on your Mac if that's you goal.

Thursday, October 11, 2012

The one with better byte

This is just a small update relating to Bell/Aliant FibreOp service in Canada.

I've had FibreOp service since May of this year and I've been thoroughly pleased with it for the most part. The only real issue I've had is lack of support for standard features in the provided router like DHCP reservations and some other things. I also found the wireless would occasionally drop some of my portable devices.

Normally I would just replace it with my trusty Airport Extreme, however the way FibreOp is set up, you need a device that can tag the WAN connection as VLAN 35 and pass untagged frames to the LAN. Like most personal routers, the Airport Extreme isn't capable of this. The Aliant ActionTec router does offer an RFC 1483 Transparent Bridge mode which essentially turns it into a "dumb modem" type device, just untagging the incoming traffic and passing it inside the LAN otherwise untouched. This allows your router of choice to get the external IP and act as a proper router.

I had tried using this mode early on when I first got the service, but was unable to get it to work and just discounted it as a feature of the router that wasn't fully available or functional. However after some further reading and experimentation I've gotten it to work. The key is to release the DHCP lease from within the ActionTec before enabling the Transparent Bridge mode. Otherwise you have to wait out the 2 hours for the lease to expire automatically. I didn't know either of those things last time, and my personal router wouldn't pick up an IP.

Now everything is working fine.

Friday, August 24, 2012

The one about the electricity...

So we bought a new home in July. Shortly after moving in, I noticed a few peculiarities in the electricals of the house: a string of electrical outlets downstairs had no ground. Two circuits on the panel could not be enabled simultaneously and after installing a 3-way capable dimmer in a 3-way lighting circuit, I could only turn it on and off from one side, not both.

Issue the first - no ground: a friend of mine is an aspiring electrician and has been studying and will soon take courses. He came over for an hour or so when he was in the area and tackled this first issue. What we discovered is that whoever wired the outlets neglected to attach the ground from the panel to the box or the outlet, and in addition, the unattached ground cable was coming in contact with the neutral contact on the socket. Bad mojo. Fixed this situation and all the outlets on that string now function perfectly.

Issue the second - mutually exclusive circuits: the same friend pondered over this for a bit and after having checked the house for outlets or lights that were not functioning when both breakers were off and coming up empty handed, we inferred that they were unused circuits and someone had foolishly tied them together in a junction box somewhere. We left it at that for the time being with both breakers off. My dad came to visit not long ago and I mentioned this issue to him and he said it sounded as if they might be going to a split outlet that didn't have the split tab removed. So we searched again and found nothing when I decided to check behind a dresser that came with the house - voila - an outlet with no power. I opened up the cover and sure enough, there were two separate 'hot' leads coming attached to the top and bottom socket, and the the split tab was still present. I wiggled it off with my pliers and as you might guess, both circuits could now be activated at the same time and the outlet works.

Issue the third - 3-way dimmer: The same friend pondered this one as well but not being well versed with 3-way circuits yet, he vowed to research it and get back to me. In the meanwhile, I found myself with a few spare hours one evening. So I looked up proper functioning of a 3-way circuit complete with diagrams. I removed both switches from the circuit and probed for current. I identified the incoming 'hot' lead and connected that to the odd coloured terminal of the 3-way dimmer, thus identifying the other two leads as the 'travellers' which I connected to the like-coloured terminals of the dimmer. From there I was able to determine which two wires were the travellers at the other switch location and connected those to the like-colored terminals of the standard 3-way switch leaving the lead to the lights to be connected to the odd coloured terminal of the standard switch. I powered the circuit back on and everything works as expected. Sometimes it helps to just start from scratch.

My hope is that if anyone else is struggling with strange power situations they might stumble upon this entry in their searching and it might be of help.

Of course, the usual warnings and caveats apply: this is for educational purposes only, I am not a professional (nor is my budding electrician friend yet), you attempt anything described here at your own risk, always turn off a circuit at the breaker and confirm it is off at the location before attempting any work.

Good luck!

Friday, May 25, 2012

C# is (C++)++

As a follow-up to the previous entry where I wrote about trying to maintain a c++ application for work, I've begun a complete rewrite using C#. And not even a rewrite so much as a reimplementation. I've only been working at it for a few weeks now and already I'm pretty much at feature parity with the old version. I closed 4 bug and feature requests today including handling of caps lock and num lock, resetting window positions and allowing only one running instance using a mutex. Need to figure out how to do a splash/loading screen while waiting for a reply on a socket.

Friday, March 25, 2011

So I decided to order a new router on Wednesday. Yesterday (one day later) it arrived at my door! It's the Asus RT-N16 SuperRouterN. What makes it super? It has 32MB of flash and 128MB of RAM. This is about 4-8 times more than most standard routers. It opens the door for a lot of additional functionality especially if you, like me, install the opensource replacement firmware DD-WRT.

DD-WRT essentially turns your router into a mini Linux computer. My first project was to build modules for my webcam and set it up to let me see what's going on in the livingroom when I'm downstairs in my office.

I have some other ideas for projects to use this for, so perhaps further updates will be warranted.

Friday, March 4, 2011

18 Quintillion Addresses and they're all MINE!

So I signed up with Hurricane Electric's tunnel service to get myself on the IPv6 bandwagon before Eastlink is able to. For the uninitiated, IPv6 is a new version of Internet addressing to replace the current IPv4 address scheme (, etc) which is only 32 bits with a 128 bit address scheme. 32 bits only provides for around 4 billion unique IPs. Where as 128 bits provides an astronomical 2^128 addresses. In a typical setup, every individual IPv6 subscriber is given their own 64-bit subnet. This allows each user to have 18 quintillion IPs at their disposal. It's not intended that anyone will actually USE anywhere near that allotment, but it will make network segregation and organization a lot easier with all that breathing room.

In other news, I've been giving some thought to replacing my standalone programmable thermostat with one run from my server. This would allow for network access and the ability to adjust the settings and temperature from the Internet. I'm still weighing out the pros and cons to this, so a future update may be in the works.

Friday, March 12, 2010

Strings and ints and bools, Oh My!

I've been spending the better part of the day wrangling with MS Visual Studio 9 as I try to become the maintainer for the client application written in C++ used by my company. Let me tell you, if that doesn't sound like much fun, it's even less.

Generally things are working relatively well, but occasionally VS gets a bug up its ass where every compile generates hoards of warnings for no apparent reason making me search the net and my code looking for what might be causing this.

So far as new maintainer, I've synchronized all the different places the previous maintainers had set varying version numbers for the app by making one central include file that is managed by a clever little Perl script I wrote to update a build number each time the project is built in release mode. I've created a 'Setup' sub-project within the solution to generate .msi install files and an optional setup.exe as well.

I come from a UNIX build environment. I used make and gcc and vi. Some of the conventions in MSVS are very foreign and they're giving me headaches at times - especially precompiled headers. Do I use them? Do I want them? Why can't my project find "stdafx.h"??