Posts RSS Comments RSS 48 Posts and 155 Comments till now

Setting the startup disk using Terminal

While it’s quite easy to change which disk your machine starts up from using System Preferences there may be times when you need/want to do it either at the command line or within a script.

The command for setting the startup disk using Terminal is “bless“. To get the full story on “bless” open up Terminal and type “man bless” (no quotes).

To change the startup disk type the following in Terminal:

sudo bless -mount /Volumes/"name of your startup disk" -setBoot

So, if the desired disk was named “TestDisk” you would type this:

sudo bless -mount /Volumes/TestDisk -setBoot

If your disk name has spaces in it you’ll need to put quotes around the path to the disk, like this:

sudo bless -mount "/Volumes/My Disk" -setBoot

You can incorporate this into a UNIX shell script to reboot your machine to another disk at a certain time. Perhaps you want to reboot to another disk every Friday to run a disk utility on it, or to image it.


#!/bin/bash
bless -mount /Volumes/TestDisk -setBoot
shutdown -r now

Breaking down this script the first line sets the disk your Mac will boot from. The second line tells it to shutdown and restart immediately. If you have an Intel Mac you can add “–nextonly” at the end of the “bless” line. That will boot the machine to that volume first and then boot back to the original volume on subsequent reboots without having to reset the startup disk.

This command also comes in handy if you’re booting back and forth between volumes to test things. For example, you have a partition with 10.3 and another with 10.4 on it and you want to test some software in 10.3. You can wrap all of this up in an AppleScript and either save it on your desktop as an application or save it as a script and put it in your Script menu.

Paste this code in Script Editor and run it. Make sure you change the disk name to your disk. What for the AppleScript line breaks in the code. Any line that ends in “¬” means the line below is part of the same line. Pasting it in as it is on the web page will still work however.

[codesyntax lang=”applescript” lines=”no”]
do shell script “bless -mount \”/Volumes/Drive Name\” ¬
-setBoot with administrator privileges
do shell script “shutdown -r now” with administrator privileges
[/codesyntax]

Then simply click on the application or select if from the Script menu, enter your admin name and password and it will select the disk and reboot for you.

If you want to choose between several disks you can add in a dialog box to let you choose the correct disk.

[codesyntax lang=”applescript” lines=”no”]
display dialog “Select a startup disk” buttons ¬
{“name of disc 1”, “name of disc 2”]
set bootVol to the button returned of the result as text
do shell script “bless -mount \”/Volumes/” ¬
& bootVol & “\” -setBoot” with administrator privileges
do shell script “shutdown -r now” with administrator privileges
[/codesyntax]

One Response to “Setting the startup disk using Terminal”

  1. […] studying some stuff inside the Internet, I attempted these shell […]