Getting the diskutil command to work in OSX Mavericks Single User mode
2014-07
I'm currently writing some single user mode maintenance scripts. My current goal is to be able to perform permission repairs and disk formatting using the diskutil command in Single User Mode. Performing this task in previous versions of OS X was a simple matter of mounting the root partition and launching the following launch daemons:
com.apple.diskmanagementd
com.apple.diskarbitrationd
After that, I only needed to run the following command to successfully repair permissions:
diskutil repairpermissions /
In Mavericks, however, this command no longer works and I can't figure out why. Running the diskutil command (even with no parameters) returns a simple and unhelpful message:
Killed: 9
I can't figure out what's going on here. In addition to the disk arbitration daemons that diskutil requires, my maintenance script also loads the following daemons:
com.apple.notifyd
com.apple.syslogd
com.apple.configd
com.apple.kuncd
com.apple.kextd
com.apple.KernelEventAgent
com.apple.distnoted.xpc.daemon
com.apple.aslmanager
com.apple.opendirectoryd
com.apple.coreservicesd
com.apple.securityd
com.apple.fseventsd
com.apple.cfprefsd.xpc.daemon
I get the same response whether I load all of the above daemons or just the two that were previously required for diskutil to operate. If I choose to boot from single user mode (by loading the entire contents of /System/Library/LaunchDaemons) I can use diskutil after the computer has finished its boot process.
Can someone more knowledgeable about the inner workings of the Mac OS possibly determine what's missing?
I'm not sure what's causing the problem, but it doesn't seem to be a missing daemon -- I tried loading everything in /System/Library/LaunchDaemons
except com.apple.WindowServer.plist
, and it still failed the same way. It even fails just running diskutil
, which normally just prints a usage summary. Also, "Killed: 9" suggests it isn't crashing itself, but something else (launchd
?) is killing it.
Anyway, there is a bit of good news: diskutil repairpermissions
is really just a front end for the repair_packages
program, and that seems to run fine in single-user mode (even with no daemons at all loaded):
/usr/libexec/repair_packages --repair --standard-pkgs
Formatting disks will probably be more difficult. You may have to look at using gpt
, newfs_hfs
, and the like.
I am using Mac OS X 10.6.4 and am struggling with the command:
diskutil
Whenever I type in diskutil the terminal says:
-bash: diskutil: command not found
Does anyone know what the problem might be? Can I install the diskutil script (probably by copying some *.sh to some destination and adding something to the bash.profile)?
diskutil
is a system administrator command. That's why it's not in the default search path for ordinary users.
The usual way to run it is to run sudo diskutil
. The sudo
command runs a command as the system administrator (root
). sudo
searches for the command in a different search path (it sets the PATH
environment variable to a diffent value before searching for the command name), which includes /usr/sbin
where system administrator commands such as diskutil
reside.
If you do want to run diskutil
as your ordinary user, specify the full path: /usr/sbin/diskutil
.
Use:
/usr/sbin/diskutil
instead of just:
diskutil
Check your PATH (echo $PATH). diskutil is in /usr/sbin. Add it to your path if it isn't already there. If it is, then yes, diskutil is missing. (/usr/sbin/diskutil is an executable itself, not a shell script.)