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*
    ...
    /dev/disk2s2
    
  4. Now let us find the file system type. In my case it is a MAC Hierarchical File System (HFS)
    # fstyp /dev/disk2s2
    hfs
    
  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\ Capitan.app/Contents/Resources/createinstallmedia) :
    $ sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/untitled --applicationpath /Applications/Install\ OS\ X\ Mavericks.app --nointeraction
    Erasing Disk: 0%... 10%... 20%... 30%...100%...
    Copying installer files to disk...
    Copy complete.
    Making disk bootable...
    Copying boot files...
    Copy complete.
    Done.
    

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.

22 comments:

NeoTribalist 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."

Aloha,

Miles

Nestor Urquiza said...

@Miles Thanks. Updated.

Unknown 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

Ken Crooker 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?

Thanks,

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

Tayler said...

Thanks so much for your help Nestor.

How long should it take to transfer after you've input 'cp -pr'? It doesn't seem to respond and when I then type 'reboot' or 'shutdown -h now' nothing happens.

Thanks again

Nestor Urquiza said...

@Tayler,

A copy can take a long time and there would be no feedback other than perhaps the light in the external USB drive indicating data transfer. Leave it there for as long as it takes. Try to copy smaller directories, for example:
cp -pr /Users/nestor/Documents/my\ directory\ number\ 1 /extdrive/
cp -pr /Users/nestor/Documents/my\ directory\ number\ 2 /extdrive/
cp -pr /Users/nestor/Documents/my\ directory\ number\ 3 /extdrive/
...

Note that you need to escape spaces.

You can try the below to restart instead (-r flag):
shutdown -r now

Best,
- Nestor

Unknown said...

hey Nestor! thanks for this very helpful post !
i decided to back up my entire user directory which has about 200go with your single user method
I'm at step 6 and it should be copying the content to the external drive, but:
how do i know when it's finished? as it doesn't display any details about the ongoing tasks?
thanks again !
Sofiane

Nestor Urquiza said...

@Sofiane, all I can say is be patient. It will eventually finish. Best and good luck! - Nestor

Anonymous said...

Wow, you saved my day!
Such simple commands ... I got sucked into a lot more complicated things I found online and none worked. Really grateful for this article! Thanks a million

Unknown said...

Amazing, great article thanks a lot sir, my system actually back up everything in one go.

Anonymous said...

thank you very much for this handy guide - helped a lot recovering most files after my SSD refused to boot anymore

José Flores said...

Hello. It seems its going to work, the files are copied but how can a external drive be mounted as read- write? Appears as read -only... thanks!!

Nestor Urquiza said...

@Jose if you mounted the right device it should be r/w. The command 'mount -t hfs /dev/disk2s2 /extdrive' should not be taken literally. You need to look at which device your external drives belongs to. Might be anything below /dev.

Alistairuk said...

Lifesaver - The graphics card in my 2011 iMac has just overheated and failed so I only have the basic integrated graphics and can't load OS X or any of the normal Recovery Tools... Thankfully single user mode works (albeit with 100s of vertical lines down the screen) using the integrated graphics so I've been able to copy my files onto an external USB before I attempt to rip this thing open to replace the graphics card!

Followers