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
“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.
: 10.5.3_Auto_NetInstall.nbi : NetInstall-Restore.nbi * : Tiger to 10.5.4 Upgrade.nbi : Tiger_to_10.5.3.nbi : 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.