Wednesday, March 19, 2014

MAC OSX not booting? Make a backup from single user mode first

Even when you keep daily backups your MAC might freeze at a time when the last important file has not been backed up. You should not reinstall the OS before making sure you have a backup. How to proceed? The easiest way (for the geek ?) would be:
  1. Restart in single mode (turn off, turn on and press "Command+S").
  2. When the prompt appears connect the external USB drive.
  3. Look for available disk drives. Most likely it will be the last one listed. In my case I had the internal drive, a USB stick and an external USB hard drive:
    # ls -l /dev/disk*
  4. Now let us find the file system type. In my case it is a MAC Hierarchical File System (HFS)
    # fstyp /dev/disk2s2
  5. To mount the drive we need write permissions. That is why we run the first command below. Needless to say you need to be careful from now on ...
    # mount -uw /
    # mkdir /extdrive
    # mount -t hfs /dev/disk2s2 /extdrive
  6. Backup what you need. For examplehere are some directories I backed up today:
    # cp -pr /Users/nestor/Downloads /extdrive/
    # cp -pr /Users/nestor/Documents /extdrive/
    # cp -pr /Users/nestor/Pictures /extdrive/
    # cp -pr /Users/nestor/Movies /extdrive/
    # cp -pr /Users/nestor/Desktop /extdrive/
    # cp -pr /Users/nestor/Library/Mail /extdrive/
  7. Unmount and shutdown (or restart):
    # umount /extdrive/
    # shutdown -h now

Bootable OSX USB Drive

If you do not have an OSX bootable USB drive you will need to make one from a healthy MAC:
  1. From the App Store search and download OS X. When you get to the below screen do not interact with it, that way the installer remains in the Applications directory. Just move on to the next step.
  2. Format a USB drive from "Disk Utility" using option "MAC OSX Extended (Journaled)" which will format the drive using HFS. Do not bother changing the name as it will be changed anyway as part of the below step.
  3. Run the below from Terminal (assuming the USB was formatted using the default 'untitled' name. Note that the command below corresponds to Mavericks. You probably will have to deal with a different version like El Capitan (/Applications/Install\ OS\ X\ El\ :
    $ sudo /Applications/Install\ OS\ X\ --volume /Volumes/untitled --applicationpath /Applications/Install\ OS\ X\ --nointeraction
    Erasing Disk: 0%... 10%... 20%... 30%...100%...
    Copying installer files to disk...
    Copy complete.
    Making disk bootable...
    Copying boot files...
    Copy complete.

Reinstall OS X

  1. Turn off the target MAC, insert the Bootable OSX USB Drive, turn on keeping the Option key pressed to be able to select from where to boot. BTW click here for more OSX startup options.
  2. From the options choose Disk Utility and select the "Macintouch HD". Click on Verify and if needed click on Repair Disk after. This is a crucial step. Errors like "this disk is lock" will be avoided later on. If the disk is damaged there is no need to keep trying as a replacement most likely will be needed.
  3. WARNING: This step erase the whole disk so I assume you have a backup or this is a blank disk. Just click on Erase and select as format "MAC OS Extended (Case-sensitive, journaled)". You might want to pick the "MAC OS Extended (Case-sensitive, journaled, Encrypted)" option. Conform you want to "Erase"
  4. NOw that the disk is formatted go to the menu and close the Disk Utility. Click on Install OSX, select the disk and continue with the installation. After some minutes your new OSX will be ready.


Greg Lowe said...

I tried this and everything worked nicely until I got to my Downloads directory. I forgot the exact line but it was something about running out of room. Perhaps some of my download files were too big? Why do you backup downloads when most things can be re-downloaded later.

Side note: I have the grey/white screen of death (27 inch iMac circa January 2012). After the Apple logo and spinner appears, I get the white screen. I tried all the options I read about online (Command R and also the method to go wireless) and nothing works. But hard drive seems fine as I have been able to access everything so far.

Nestor Urquiza said...

Hi Greg, some people like me just download and work directly on the Downloads directory which means I also clean it up frequently. But you are right that most of the time it is not necessary to backup that directory so go ahead and skip it. After you have your backup then just wipe out the OS from the bootable USB and reinstall the OS.

Miles Wolbe said...

Hi Nestor,

You may want to include the -p option in your cp command. It "preserve(s) the following attributes of each source file in the copy: modification time, access time, file flags, file mode, user ID, and group ID, as allowed by permissions. Access Control Lists (ACLs) and Extended Attributes (EAs), including resource forks, will also be preserved."



Nestor Urquiza said...

@Miles Thanks. Updated.

Thomas Tang Holbek said...

Hi Nestor.

What if a username contains space between, ie. first name last name?

How does the # cp -pr /User/John Doe Johnson/Pictures /extdrive/ work with space in-between the first middle and last name?

Nestor Urquiza said...

Hi Thomas, Just use quotes:

# cp -pr "/User/John Doe Johnson/Pictures" /extdrive/

Alex said...

Good sir this article has saved my bacon and then some
Thank you

Nestor Urquiza said...

Hi Alex, glad that it helped.
- Nestor

ArgonKen said...

Hi Nestor! You deserve a Nobel Prize for this post. I used to have Time Machine backing up my computer, but my external HD died and I never replaced it. And setting up a cloud backup never made it past my "I'll Get to It" list. Looks like my video card is going bad (or just doesn't like Mavericks), and after about 45 minutes of running, the computer reboots itself and it enters an endless boot loop. I bought a new external drive, but it's kind of hard to back up files in 45-minute increments (separated by several hours of cool-down time). Single User Mode bypasses the GPU, so the computer can run all night on it without initiating the boot loop. I followed your directions and safely got all our photos and other important documents backed up. You've saved me a lot of pain and anguish. Thank you so much for posting this!!!

Nestor Urquiza said...

@ArgonKen my pleasure. I am si glad to hear this helped you. Cheers! - Nestor

Andrej said...

Hi Nestor,

I have a Mac OS X El Captain and it won't boot after inputing the user password it stops the progress at nearly the end and doesn't allow me to enter the OS and save my files.
I have entered single user mode and tried to copy the files to an external hdd but i get that the disk is encrypted. My question is how to get the drive un encrypted throw single user mode?


Nestor Urquiza said...

@Andrej, I recommend that you post your question in stack overflow. Backing up encrypted drives from single user mode is a completely different monster that I have not had the chance to play with yet. Good luck! - Nestor