Easily Change Your Server’s Default NetBoot Image from the Command Line

I have five different NetInstall/NetRestore images living on an Xserve that I use for deployment purposes. I find myself using Server Admin pretty often to change the default NetBoot image so I can boot computers to that image while holding down option-N. I was starting to find it pretty tedious to do this via the GUI. After launching the application, it takes seven clicks to change a default image in Server Admin (Tiger and Leopard). The times that I wasn’t at my computer and wanted to change the default image were starting to pile up, too.

So, what does any intrepid admin do at a time like this? That’s right. We take it to the command line and find a way to script it. My goal now was to create a script that I could run (from any computer) after ssh’ing into the server.

Reality strikes back

In reading the NetBoot section of the Command_Line_Admin_v10.5.pdf on Apple’s site, I found that the serveradmin tool provided access to the necessary settings, but using it wasn’t as straightforward as I had hoped. After bouncing the question off the macenterprise email list, I received a very helpful response telling me I had to dump the NetBoot settings into a file, make changes to the desired lines in the file, and then read the contents of the file back in to serveradmin.

“This isn’t going to be a two-liner,” I thought, with shoulders slumped.

Scripting trumps reality

Once my innate laziness wore off, I dove right into this scripting challenge, with bash as my weapon. After a long night and a morning of tweaks and bugfixes, I came up with netbootch, the default NetBoot image changer. The script is interactive and takes no arguments. When run, it lists all available NetBoot images — the current default is marked with an asterisk — and prompts you to select a new default.

      [0]: 10.5.3_Auto_NetInstall.nbi
      [1]: NetInstall-Restore.nbi
    * [2]: Tiger to 10.5.4 Upgrade.nbi
      [3]: Tiger_to_10.5.3.nbi
      [4]: Visitors iMacs.nbi
    Select a new default image [0-4]:

After you type a number and hit return, it makes the change, suppressing gobs of output and providing friendly feedback.

    Select a new default image [0-4]: 4
    Making 'Visitors iMacs.nbi' the default image. . . . .

The script needs to be run as root on a computer running OS X Server. (Yes, it does check for this.) I recommend placing it in /usr/local/bin on your server so you can call it as you would any other built-in command.

Grab your copy here.

UPDATE (8/12/08): This tool comes in very handy if you ever encounter the dreaded gray status light next to the NetBoot service in the Server Admin GUI. In my experience, only a reboot fixes that issue. If you only need to modify your default image, this tool will allow you to work around this annoying bug.


6 thoughts on “Easily Change Your Server’s Default NetBoot Image from the Command Line

  1. Cool. I also found this a particularly annoying task, and the cmd was not a quick walk in the park either. Cheers.

  2. Does option-N do something different from just holding down option or N on their own? I have never seen this before. Does it enable something special or did you actually mean just option or N as opposed to the combination?

  3. Andrew, Mike Bombich wrote about using Option-N during startup on his site. Go to this page and scroll down to the section titled Resetting NetBoot server caches. I use option-N so I can be sure the computer will use the most recently-selected NetBoot default.

  4. Thanks for this! I just started getting the netboot greyed out bug yesterday. Seems after this many years and a new major server release they would have fixed this. Oh well, after reading the os x server command line menu and not finding anything helpful I found your script. Now I don’t need the GUI!

Comments are closed.