Ruby Journal

Install Ubuntu With PXE via OSX

| Comments

In this tutorial, I’ll guide you through how to to setup OSX as PXE server to install Ubuntu on other hosts.

Introduction

The Preboot Execution Environment (PXE) is widely used in enterprise environment for mass deployment, however it is not well-known in home and office environment because it is always easier to install Ubuntu Linux using traditional CD/DVD or USB storage devices method.

If your box doesn’t have CD/DVD or USB storage devices, you can install Ubuntu using PXE. The concept is very simple, a computer that host TFTP server and the to-be-installed host support PXE.

I adapt the concept to OSX to show you that you could achieve the same result with Mac OSX. In this tutorial, I use OSX 10.8.2. However, it should also work with older versions.

Prerequisites

  • Netboot installer for Ubuntu
  • TFTP Server
  • A PC that is to be installed to supports PXE
  • Fast and reliable Internet connection
  • Time and patience

Download Ubuntu Netboot installer

We only need the netboot installer of Ubuntu, you don’t have to download a full ISO for the purpose. The file that we need to download is the netboot.tar.gz which can be found at http://cdimage.ubuntu.com/netboot/.

  1. Open your Terminal.app
  2. Use curl command to download the netboot installer:
1
2
$ cd /tmp
$ curl -O http://archive.ubuntu.com/ubuntu/dists/precise/main/installer-i386/current/images/netboot/netboot.tar.gz
  1. Extract netboot.tar.gz to suitable folder that we are going to use as TFTP root folder
1
2
$ mkdir ~/Downloads/tftp
$ tar -xvzf netboot.tar.gz -C ~/Downloads/tftp
  1. Fix folder permissions:
1
$ sudo chown -R nobody:nogroup ~/Downloads/tftp

Set up TFTP server

Easy setup with TFTP Server software

Though OSX comes with tftp command line, it still takes more steps to setup manually. Alternatively, you can download the TFTP Server. It provides a GUI to configure the built-in tftp server on OSX.

  1. Download the TFTP Server.
  2. Open the DMG file and drag the application into your Applications folder.
  3. Open the TftpServer.app.
  4. We will NOT use the default /private/tftpboot as root for TFTP server. From TftpServer.app’s screen, click on Change Path icon and select Downloads/tftp and you should see the path bar change to /Users/yourusername/Downloads/tftp.

  5. Fixing folder permission by click on Fix buttons of both Working path permission and Parentals folders permissions. You should see Attributes OK if all goes well.

  6. Start the server by clicking on Start TFTP. You should see Server Status change to Running.

Hard setup using built-in tftp server

For whom who want to set up the tftp manually via CLI.

  1. Configure the server by modify the tftp.plist into a suitable folder for modification:
1
$ cp /System/Library/LaunchDaemons/tftp.plist /tmp
  1. Edit the file /tmp/tftp.plist and change:
1
2
<key>Disabled</key>
<true/>

to

1
2
<key>Disabled</key>
<false/>

also modify your TFTP root folder into the <array> section:

1
2
3
4
5
<array>
  <string>/usr/libexec/tftpd</string>
  <string>-s</string>
  <string>/Users/yourusername/Downloads/tftp</string>
</array>
  1. Backup the existing configuration file:
1
$ sudo mv /System/Library/LaunchDaemons/tftp.plist /System/Library/LaunchDaemons/tftp.plist.backup
  1. Copy our configuration file into /System/Library/LaunchDaemons/:
1
$ sudo mv /tmp/tftp.plist /System/Library/LaunchDaemons
  1. Start the server with:
1
$ sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist

OR

1
$ sudo launchctl start com.apple.tftpd
  1. Once installation is finished, you could disable it with:
1
$ sudo launchctl unload -F /System/Library/LaunchDaemons/tftp.plist

OR

1
$ sudo launchctl stop com.apple.tftpd

Set up DHCP server

In concept, PXE-bootable device will look for DHCP service in order to receive available PXE boot server. If you don’t have a DHCP servive running locally in router or in your LAN, you have to set up a DHCP server.

With isc-dchpd

  1. Install isc-dhcpd with Homebrew:
1
$ brew install isc-dhcp
  1. Create configuration file at /usr/local/etc/dhcpd.conf:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
default-lease-time 600;
max-lease-time 7200;

subnet X.X.X.0 netmask Y.Y.Y.0 {
  range X.X.X.151 X.X.X.205;
}

option domain-name-servers 8.8.8.8;

host netbook {
  hardware ethernet ??:??:??:??:??:??;
  filename "pxelinux.0";
  next-server Z.Z.Z.Z; # the IP address of your TFTP server
  fixed-address X.X.X.202;
  option subnet-mask Y.Y.Y.0;
  option broadcast-address X.X.X.255;
  option routers X.X.X.1;
}

in which X.X.X is your network address, Y.Y.Y is your subnet mask, ??:??:??:??:??:?? is the MAC address of the box you want to install to and finally Z.Z.Z.Z is the address of TFTP server.

  1. Start the server with:
1
$ sudo /usr/local/sbin/dhcpd -f -d -cf /usr/local/etc/dhcpd.conf
  1. Once the installation finished, clean up with:
1
$ brew uninstall isc-dhcp

With built-in bootpd

OSX does come with a built-in BOOTP server called bootpd, which offer also offer DHCP service. This technology is known as NetBoot and used to install OSX on CD/DVD-less machines like MacBook Air or Mac Mini. I adapt instructions at Jacques Fortier’s blog for this tutorial.

  1. Create /etc/bootpd.plist with content:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>bootp_enabled</key>
    <false/>
    <key>detect_other_dhcp_server</key>
    <integer>1</integer>
    <key>dhcp_enabled</key>
    <array>
        <string>en0</string>
    </array>
    <key>reply_threshold_seconds</key>
    <integer>0</integer>
    <key>Subnets</key>
    <array>
        <dict>
            <key>allocate</key>
            <true/>
            <key>lease_max</key>
            <integer>86400</integer>
            <key>lease_min</key>
            <integer>86400</integer>
            <key>name</key>
            <string>192.168.1</string>
            <key>net_address</key>
            <string>192.168.1.0</string>
            <key>net_mask</key>
            <string>255.255.255.0</string>
            <key>net_range</key>
            <array>
                <string>192.168.1.101</string>
                <string>192.168.1.202</string>
            </array>
        </dict>
    </array>
</dict>
</plist>

The config file assume that the network address is 192.168.1.0 and the DHCP allocation pool is from .101 to .102.

  1. To assign static IP address to our to-be-installed host, we create file /etc/bootptab:
1
2
3
4
5
%%
# machine entries have the following format:
#
# hostname      hwtype  hwaddr              ipaddr          bootfile
client1         1       00:1f:16:08:61:96   192.168.1.105   pxelinux.0
  1. To start the server, run the following command:
1
$ sudo /bin/launchctl load -w /System/Library/LaunchDaemons/bootps.plist
  1. Once done, stop the server with command:
1
$ sudo /bin/launchctl unload -w /System/Library/LaunchDaemons/bootps.plist

Booting Ubuntu

To boot from TFTP, you need to configure your PC to boot from the network interface in the BIOS.

Once booting into the installer, you can install Ubuntu by having sources download for a mirror.

Comments