Troubleshooting code is one of my favorite things. No, really! I find great pleasure in taking something broken and making it work again. I am challenged to employ my personality traits of dog-headed persistance, logical analysis and puzzle-solving ability. Of course, with any worthy endeavor, there are frustrations. But, the exhilaration of finding that missing tag, or misspelled word, or rewriting a function with fewer lines of code, is satisfying. But the main reason I enjoy troubleshooting is that it causes me to learn more.
When I begin to learn a new language, one of the first things I want to understand are the tools to troubleshoot my programming. Throughout my schooling, the most frustrating language I learned was ASP .NET. Having recently picked it back up again, I realized why I struggled. The textbook we used placed troubleshooting at least two-thirds of the way through the text. We covered the text chronologically, so for many, many weeks, if I encountered a problem with my code, I was limited in what I could do to resolve it. More than once, I simply scrapped the page (which is also not easy to do in Visual Studio) and started again. I felt that I was being robbed of the learning that results from identifying and resolving an error, no matter how insignificant that error might have been.
Recently, I have had the pleasure of encountering a variety of problems to troubleshoot. A long-time client finally had a failure of an elderly WordPress plugin that hadn't been maintained in four years. While devising a new work around to solve the problem in the quickest and least expensive way possible, I also discovered the server was still running an ancient version of PHP. Note to self: when doing website maintenance updates, also check PHP version. I'm not sure if the plugin would run with the updated PHP, but access to this particular website is critical at this time, as the organization has an impending conference. We are still working out little kinks, but we are mostly back in business.
The other issue was an HTML/CSS bug in a website I regularly follow. I was able to help interpret what was going on technically to other users, and offer some workarounds until the site owner was able to repair the problem. While I didn't implement any coding myself, the exercise in interpretting technical issues for a non-technically literate audience was worthwhile. As a freelancer, I cannot take my users level of knowledge for granted, and am always challenging myself to explain things in as simple a manner as possible without insulting people's intelligence.
I'm not going to go into the technical aspects of trouble-shooting in this post (hint, Google is your friend!), but rather offer encouragement that finding your own solutions is rewarding beyond having a functioning website, function or script again. When people ask me how to get better at coding, my basic answer is to break stuff. Making mistakes is inevitable. Being able to fix them shows you are well on the path of mastering the skill.
So, you're in the middle of converting video into a format that Adobe likes to work with, and .....
Exactly. Nothing. Complete freeze up. You force quit and restart. And all you get is the white Apple screen and endless circling wheel.
Now it's your heart that's stopped.
So went my weekend. My husband's year and a half old Macbook Pro needed immediate resuscitation. But more troubling was all the data that hadn't been backed-up yet.
Enter good old friend Google.
Diagnosing the Problem
The first step to a solution is identifying the problem. Without a specific known error, you're swinging with your eyes shut hoping to make contact. First step is to start up in an alternate mode--verbose mode. Verbose mode removes the loading graphic, the Apple screen, and prints the start up processes onscreen. When the boot up hangs, you'll get a text error with which you can plug a search string into Google and hopefully find repair tips.
To enter verbose mode, simply press and hold the Command+V keys while starting up. So, shutdown the mac by holding the power button or Command+Control+power. Hold Command + V and hit the power to start. You will see a black screen with white print. At some point the start up text will display errors. Note what the error says so you can do an internet search for a solution.
With my husbands laptop, he was getting a disk0s2 I/O error, which indicates a harddrive failure.
My immediate concern was rescuing the several hours worth of video footage that he had been working on, and the family photos which had not yet been backed up. I could not even start the OS in Safe Mode (Shift + Command + V) or Single User Mode (Command + S). I could boot to the recovery partition--holding Command + R on boot.
In recovery mode, I ran Disk Utility to verify the disk. Frustratingly it said it was okay, nothing to fix. I needed to reinstall the OS, but I didn't want to potentially lose important data.
Here and there I found tutorials on using Firewire or other direct networking to transfer files. I didn't have a firewire and couldn't boot to the modes which would allow peer-to-peer networking. I do have an external hard drive and a USB flash drive. And I discovered that you can access terminal in recovery mode. Also, you can still mount removable drives, like an external hard drive or USB drive.
In recovery mode, the menu bar includes a Tools drop down, which offers a few more tools than the pop up screen shows. You'll find terminal in there.
Commands to Use
Even if you are a complete Terminal novice, and this stuff seems way over your head, you can do this. If you are reading this, likely your system is already in jeopardy. And nothing we are going to do in Terminal is at all even the slightest bit destructive. Our goal is simply to make a copy of your files onto a removable media device so that you can recover them. Two important tips to remember are to type each command accurately, carefully noting spaces and cases. If a file or directory name is two words, use quotation marks around the name. Hit enter to activate the command.
The mount command will display the mount path of your external device.
The ls command will display everything within the directory (i.e. folder) you are in.
The cd to move into different directories.
The rsync command to copy the data to a removable device through USB.
On each of the screenshots, what you type is highlighted in yellow or written after # in the caption. The output is highlighted in blue.
Step 1: Use mount to display the path to your removable device. Look for the text starting /Volumes/... My device has two partitions, so it displays as both /Volumes/MEDIA and /Volumes/DATA. I'll be using the /Volumes/MEDIA partition. Write down your path for future reference.
Step 2: Use ls to locate the directories that need to be recovered. I believe that Terminal in Recovery Mode drops you into the root directory, so that's what I'll show you. See the directory named Users? That's where we're going next.
Step 3: Use cd to change directories and navigate around your directory tree. If you know where you are going, you can do this all in one line, but if this is your first time we'll do this in stages. Because we are in terminal as the root user, there is no visual queue that we changed directory, so I also immediately repeated the ls command.
Step 4: We're almost to our home directory. As you can see in the screenshot, my username is max, but yours is likely different. Make sure you use your username and not mine in this next step. It's just a repeat of the previous step, only cd to your username.
Step 5: Now you should be seeing a list of folders you are familiar with. If you are a typical user, you likely have data on your desktop, in your documents folder, and in your pictures folder. Maybe you also have music and movies. You can copy as much as you have space for on your removable device. I'll show how to copy the entire directories, for simplicity. I'll be using the Pictures directory.
Use the rsync command, followed by the -rv options. The r (recursive) instructs the computer to move the named directory, plus all its contents. The v (verbose) is just the same as we used before when diagnosing the error; it displays all the files names so you can see what is being moved. It will work without the v, but will appear to be doing nothing.
Next, we add the path to the directory we want to copy. Remember to change max to your own username. Finally, type the path to your removable device that you noted earlier. If you forgot, you should be able to scroll up and locate the path if you haven't closed the Terminal. Note: if you have an existing folder with the same name, your files will be copied into that folder. If you want to keep it separate, add backup to the end of the command: /Volumes/MEDIA/backup.
Then you simply repeat the same process changing the word Pictures to whatever other directory name you wish to move next.
Step 6: This step is optional. If you used the verbose option, you can see the files as they are transferred. But you can also confirm their arrival by cd-ing to the drive. Use the cd command and type the same path to which you have been copying all the files. And there it is among the already existing directories.
After you've recovered your data, you can take whatever steps necessary to fix the problem without worries of data loss. Note that this applies only to actual files and data stored in your file system. Saved passwords and bookmarks are beyond the scope of this post, but if you can locate where they are stored via an internet search (probably in an application library), copying them over would be a repetition of the steps above.
In our case, after I recovered what was vital to us, I chose the option to install the OS from the popup menu. In fact, this did not erase personal data, only rewrote actual operating system files. Had this step not worked, I would have had to wipe the hard drive and then install the OS again, which would have resulted in the loss of all personal data.