Netbooting Ubuntu

A server I got my hands on had an OS (and possibly hard drive) breakdown, so I needed to install some operating system on it. I am familiar with Ubuntu, so that is what I decided on. However, the server was too old to boot from a USB stick and had no optical drive.

Netboot to the rescue! (The server BIOS supported PXE.) Getting this to work was not altogether straightforward though, as most online guides assume you can just install and use a DHCP server. I can’t. Or at least that appeared a bit too cumbersome, as my Time Capsule does the DHCP stuff and without it, there would be no network access, or at least that would have broken the Apple TV session my wife was having at the same time.

Fortunately, one CAN get this working with just TFTPd and bootpd. So I installed those two on another Ubuntu machine:

1
sudo apt-get install bootpd tftpd

Then you have to configure xinetd to accept requests to the two services. The following two files need to be placed in /etc/xinetd.d

tftp:

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo cat > /etc/xinetd.d/tftp
service tftp
{
protocol        = udp
port            = 69
socket_type     = dgram
wait            = yes
user            = nobody
server          = /usr/sbin/in.tftpd
server_args     = /tftpboot
disable         = no
}
^d

bootp:

1
2
3
4
5
6
7
8
9
10
11
12
sudo cat > /etc/xinetd.d/bootp
service bootps
{
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/bootpd
server_args = -i /etc/bootptab
}
^d

Then you need a file named /etc/bootptab that specifies which boot file to offer netbooting clients:

1
2
3
4
5
6
7
8
9
sudo cat > /etc/bootptab
client:\
  hd=/tftpboot:\
  bf=pxelinux.0:\
  ip=192.168.0.11:\
  sa=192.168.0.113:\
  sm=255.255.255.0:\
  ha=00E0812D11BB:
^d

ip is the IP address you want to give a the netbooting client. sa is the IP address of the netboot server (the one that the file bootptab resides on). sm is the network mask of the network both these machines are on.

ha is important: it is the MAC (hardware) address of the network interface used by the netbooting computer to reach the nentboot server. Fortunately for me, my server displayed this when trying to netboot, even when it failed to do so.

hd is the directory that tftpd will serve files from (created in the next step) and bf is the file netbooting clients will boot from (which is fetched shortly).

So now create the tftpd content directory and populate it. The Ubuntu wiki says that all that is needed is in a file named netboot.tar.gx. Get that file. (You may need to browse the Ubuntu website to find the one that is right for your architecture — my server is AMD64 based.)

1
2
3
4
sudo mkdir /tftpboot
cd /tftpboot
sudo wget http://archive.ubuntu.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/netboot.tar.gz
tar -zxf netboot.tar.gz

According to the Ubuntu Wiki, one would pretty much be done at this point, but I found that to be untrue as the tftp daemon does not follow symlinks when a client tries to download them. And the two most relevant files in the netboot archive unpack as symlinks into the tftpboot directory. Therefore:

1
2
3
sudo rm pxelinux*
sduo mv ubuntu-installer/amd64/* .
sudo rm -r ubuntu-installer

Now we just need to fix permissions and reload xinetd:

1
2
3
sudo chown -R nobody *
sudo chmod -R 777 *
sudo reload xinetd

After this, at least I could boot my server into the Ubuntu installer over the network.

Posted in Tech | Leave a comment

SCEvents: a Cocoa Wrapper for FSEvents

I need to use FSEvents but I really do not feel like using plain C if I can void it. Luckily for me, Stuart Connolly has written SCEvents. It was only missing one little thing for me: the ability to resume monitoring of a path from a specific event ID. I intend to patch it like this and use it: scevents.patch.

Posted in ObjC | Leave a comment

NSConnection, NSPorts and Registered Names

Apple’s documentation. Is it too hard to mention that NSConnection:registerName is not useful when using TCP? Or that you can use nil as a port in some cases? It is probably obvious to some, but not to everyone. Like me.

To set up an NSConnection as a server:

1
2
3
4
5
6
7
8
9
10
int serverPort = 4321;
NSObject *vendedObject = [[NSObject alloc] init];
NSSocketPort  *receivePort;
NS_DURING
receivePort = [[NSSocketPort alloc] initWithTCPPort : serverPort];
NS_HANDLER
NSLog(@"Failed to bind port.");
NS_ENDHANDLER
connection = [[NSConnection alloc] initWithReceivePort:receivePort sendPort:nil];
[connection setRootObject:vendedObject];

And the client:

1
2
3
4
5
6
7
8
int serverPort = 4321;
NSSocketPort *sendPort;
NS_DURING
sendPort = [[NSSocketPort alloc] initRemoteWithTCPPort:7894 host:@"localhost"];
NS_HANDLER
NSLog(@"Failed to init socket.");
NS_ENDHANDLER
connection = [[NSConnection alloc] initWithReceivePort:nil sendPort:sendPort];

There. Looks like I’m moving forward now, at least.

Posted in ObjC | Leave a comment

Home-brewn Frameworks and XCode 4

Apple seems to dislike updating their documentation. But they LOVE to update XCode.

After much searching and deciphering of XCode 3 guides (such as this and this), this is how to add your home-brewn framework to a sibling project. I am assuming you have both the framework project and the project that will use the framework in the same XCode Workspace.

First, change the install path for your debug and/or release build of the framework:

Next, ensure all relevant headers in the framework are public (use drag-and-drop from private or project as required):

Now for adding the framework to the using project. Drag the framework product to the Link Binary With Libraries section of the Build Phases for the using project, as shown below.

Accept creating folders in the sheet that pops up:

The framework now shows up in the navigator on the left. I’m a tidy person, so I drag-and-drop the framework into the Frameworks group, i.e. from

to

Finally, drag-and-drop the framework into the Copy Files Build Phase:

You can now reference the framework in code as if though it was a system framework. In my case:

1
#import <TBNetwork/MyHFile.>

I really wonder why this has to be so hard. Where’s the old “Add Existing Framework…” menu command, for example? Oh well…

Update: As per this forum post, @executable_path in the first step should probably be exchanged for @loader_path if one intends to use the framework in a PreferencePane, or any other Bundle. Myself, I did not have the patience in the end. And I have not finalized the design for bindings and/or callbacks and/or delegates to handle results from my NSNetService and related instances. So I just included links to my framework implementation files into my PreferencePane project.

Posted in Mac, ObjC, Programming | 1 Comment

XCode 4 and IB

It took a while to get used to the new way of working with NIBs in XCode 4. And preference panes were extra troublesome for me, since I sometimes came into a state where my prefpane was not accepted by the system (“cannot load because xxx does not run on Intel macs” and the alike). Random fiddling with build settings, clean, manually delete intermediate files and rebuild seems to make this error go away. There’s a beta UI for the synchronization system preference pane now though. I have tentatively named it SynX.

Posted in Mac, ObjC, Programming | Leave a comment

Bonjour Browsing

I found the dns-sd utility. Try

1
$ dns-sd -B _afpovertcp._tcp local

in a terminal.

Posted in Mac, Tech | Leave a comment

Back to the Mac

It has been a long time, both since I posted and since I developed anything more interesting than short snippets of PHP. Now, however, I am working on a file synchronization system for two or more Macs. The problem is that I have not found anything that will synchronize anything else than application data unless it is done in the foreground.

The goals of my system are:

  • launchd’d server and client
  • Bonjour discovery
  • Configuration UI (in a Preference Pane)
  • Automated file transfers

So far, I have the Bonjour stuff up and running with NSNetServices, looking hard at the code examples. The next step is to actually transfer files using NSSocketPort and NSFileHandle. Examples are available for this too.

My only real problem is graphics. (See this…)

I hope to get this project done fairly soon. Developing (is fun again|again is fun).

Posted in Mac, ObjC, Programming, Tech | Leave a comment

Parallels on Leopard

I do not start Windows often. Not even in Parallels. And now that I really need it, it turns out that theĀ 2.somethingĀ version of Parallels I own does not work on Leopard. And the upgrade to 3.0 is not free. Well, I’m not buying now, just in case 10.6 comes along later today and Parallels needs another update to work on that.

Posted in Mac, Tech, Windows | Leave a comment

Getting Perl to talk to MySQL on Leopard

Get the latest versions of DBD-mysql and DBI from http://www.cpan.org/modules/by-category/07_Database_Interfaces/DBD/.

Put the tar.gz files in /Library/Perl/ and

1
sudo tar -zxvf filename

for each of the two files.

Then cd into DBI-1.604 (the directory name will vary with your DBI module version, naturally) and

1
2
3
sudo perl Makefile.PL
sudo make
sudo make install

Do the equivalent for DBD-mysql. Code away!

Posted in Mac, Programming, Tech | Leave a comment

MySQL on Leopard

For some reason, MySQL has not updated their 5.0 distribution for MacOS X for Leopard. Hence if one wants to use the prefpane to start MySQL, one need to download and install this.

Also you need to

1
2
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

in order for everything to work properly.

Posted in Mac, Programming, Tech | Leave a comment