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. . . . .
Done.
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.
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.
Follow me on twitter
August 5, 2008 at 1:31 pm
Cool. I also found this a particularly annoying task, and the cmd was not a quick walk in the park either. Cheers.
August 18, 2008 at 5:54 am
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?
August 18, 2008 at 11:21 am
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.
June 25, 2009 at 3:52 am
Thank you for sharing this!
July 2, 2009 at 6:12 pm
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!
September 29, 2009 at 11:47 am
There’s good info here. I did a search on the topic and found most people will agree with your blog. Keep up the good work mate!