How to remotely run Disk Repair (fsck) on OS X
The first thing you should do is make sure your remote control program is running properly at startup. I’m using TeamViewer so I just added it to the main user’s startup items. If you’re using VNC on your mac you probably don’t have to do anything special once it’s enabled.
The problem with Disk Repair (fsck) is that it needs to be run in single user mode, but you won’t have a GUI to work with on the remote side so the system needs to reboot, run fsck automatically, then reboot back to your normal GUI.
Run terminal.app or SSH into the remote system
sudo su –
Enter your password, then issue these commands:
Add this block of text to the end of the file:
singleuser=`sysctl -n kern.singleuser`
if [[ $singleuser -eq 1 ]]; then
echo Not in single user mode
Save /etc/bashrc (:wq!), then
The remote system will reboot in single user mode, run fsck, then reboot back to normal mode. Run Disk Verify again on the running system, and it should be problem-free if the fsck did it’s job!
You should now go back and edit /etc/bashrc and remove the block we added, so that if you need to boot into single user mode for some other reason in the future it will give you a prompt and not just run fsck and reboot on you.
I ran into a situation that required me to run fsck remotely on a system running Mac OS 10.10, and unfortunately the neither the bashrc or profile are called as of Mac OS 10.10. In my case, system was not physically accessable, so I had not other choice but to get the code working. It seems that as of Mac OS 10.10 single user mode calls /bin/sh with options that disable the checking of bashrc/profile. I was able to get around the problem by downloading the bash source, and modifiying it such that /etc/profile is called no matter what arguments are specified when calling the shell. I then replaced /bin/sh on my system with the custom one I compiled. To modify the bash source you will need to work with the lines containing: maybe_execute_file (SYS_PROFILE, 1); in shell.c Once the custom /bin/sh is installed, then the above script works perfectly to run fsck remotely. I by no means recommend making these modifications to your own system.