Fixing a broken FileVault image on OSX
It all begins when i became somewhat frustrated when my Mac Book Pro became increasingly unstable.
If it was not alt-tabbing or trivial operations including opening new applications, everything and anything seemed to lock up my machine, almost as if MS Windows had somehow taken over Unix in an evil way.
I persevered with this poor standard of working/coping for just over 3 days, when the final straw came, i could no longer use my Instant Message client Adium or read my RSS feeds in Vienna. Time for me to go on a hunt to track down the culprit to the nagging issues.
My first thoughts were that something was going amiss with the application preferences; as Vienna no longer knew what feeds i was once subscribed to and it was as if Adium had some form of Amnesia, prompting me to set up an IM connection for the `first time`.
Time to investigate
ls -las ~/Library
This is a problem, but an odd one. I had no results from my previous
ls. How could this be? Well i consulted with a fellow system engineer and colleague, Giles Rapkin, whom advised me to do a disk checkup. Great idea, so i went off, firstly restoring permissions (just in case), no joy there, so disk check it was.
The disk check returned no conclusive results. So came the thought, could it be a problem with FileVault?
I logged out of my account, and logged in as root on my machine. I then dragged my FileVault image from /Users/$$USER$$ to Disk Utility and did a disk check. This returned my problem; i had a corrupt FileVault image. This was most likely caused by doing a hard reset whilst my machine was still doing stuff when the image was mounted.
Sorting out the problem
Problem diagnosed, time to move on and deal with the matter of getting my machine up and running in a stable fashion again.
Note, my solution will suspend the use of Filevault, see a guide on Encrypt your homedir on your mac without FileVault by Stuart Colville
Steps taken to fix my broken machine:
- Ensure you are logged in as root (Enabling and using the “root” user in Mac OS X)
- Mount the FileVault image from the account directory
- Copy all the files to a backup location:
sudo cp -r /Volumes/$$USER$$ /Users/$$USER_backup$$
- Check the backup worked:
ls -las /Users/$$USER_backup$$
- Delete the user in question in from the Accounts preference pane
- Create the same user again, still in the Accounts preference pane
- Copy all the backup files over to the newly created user:
sudo cp -r /Users/$$USER_backup$$ /Users/$$USER$$
- Change permissions on the moved files:
sudo chown -R $$USER$$ /Users/$$USER$$
- Logout of root and log back in to $$USER$$
This seemed to fix the problem and luckily everything is up and running again, smoothly, and this time without FileVault.