Can I boot to a different Mac OS X partition from the command line?

5

I need to test some software (nightly) on 3 Mac OS X versions: 10.4, 10.5, 10.6 -- the software interfaces with the hardware, so non-native solutions (like virtualisation) are not ideal.

So I figured the best way to test the software (which is automatic by the way) is to have a partition for each version of the OS. This way I can boot to a specific version to test the software.

This needs to be done on a timed schedule, so I was hoping I could run a command like this in a crontab:

reboot --to "Mac OS X 10.5"

Is something like this possible, or do I need to write my own software to do this?

Nick Bolton

Posted 2010-10-21T18:50:35.743

Reputation: 2 941

Answers

7

I am not aware of any application that can do this, but doing some research there is 2 suggestions.

Firstly use AppleScript to select the startup disk. The basic idea is using the following you can select the boot partition and then reboot.

do shell script "bless -mount \"/Volumes/Name of the drive\" -setBoot" with administrator privileges do shell script "shutdown -r now" with administrator privileges.

You can then use osascript to execute the above AppleScript from your crontab.

Alternatively you can install rEFIt which allows you to select an OS at boot, and potentially modify the startup files using a bash command which can change the default OS to boot. I have no way to confirm this can be done but it is an option.

The above is shown as an AppleScript, and since the source article refers to it I am keeping it in the original format, however as was pointed out in the comments, the two commands can be run in the shell directly without needing AppleScript

BinaryMisfit

Posted 2010-10-21T18:50:35.743

Reputation: 19 955

5There's no reason to (and good reasons not to) use a shell script to run AppleScript to run a shell script... This is especially likely to fail when run from crontab. Instead, just put bless -mount "/Volumes/Name of the drive" -setBoot && shutdown -r now directly in a shell script, and run that via crontab. – Gordon Davisson – 2010-10-21T21:28:11.483

@Gordon Davisson This should be an answer; I would have accepted it. I will accept Diago's instead. – Nick Bolton – 2010-12-04T15:04:36.863

I found one caveat; you'll need to run it as the root user. – Nick Bolton – 2010-12-04T15:05:09.983

1

The nvram command will allow you to modify the NVRAM parameter that specifies which partition to boot from.

Ignacio Vazquez-Abrams

Posted 2010-10-21T18:50:35.743

Reputation: 100 516

2Although it looks like bless as given in Diago's answer will do a better job of it. – Ignacio Vazquez-Abrams – 2010-10-21T19:03:17.067