Tuesday, December 23, 2008

OS X - Repair disk errors like invalid node structure

If you're an OS X user you may have run into a problem like this before. When you power on the machine it just sits on the Apple logo screen but won't get any further. Other boot up problems may be fixed by this as well. If you try to boot from the install CD and run disk utility to repair permissions or repair the disk, you may get an error such as invalid node structure or something similar that will cause the repair to fail. One solution to this is to reformat the hard drive, reinstall the OS, and then reinstall all the programs. This is time consuming, and you'll lose all of your data if it hasn't been backed up. Instead, there's something else to try that could solve the problem and you won't have to worry about reinstalling anything. You can manually run the Apple file system consistency check (fsck) and have it repair errors it finds. To do this you'll need an OS X install disk, which you should have gotten with the computer.

1. Put the install disk in the computers CD/DVD drive
2. Restart the computer
3. When it comes back on, hold down the C key on the keyboard to force it to boot from the CD
4. Once it gets to the point where the Apple logo is on the screen and the progress spinner has appeared and is moving underneath the logo, you can release the C key.
5. It will ask you which language you want to use, so select your language choice and continue
6. Don't continue with the installation from this point on. Instead, on the menu at the top I believe there is an entry for "Utilities" (or something like that). Click on it and go to Disk Utility. If that's not where it is, check the other menu options until you can find it
7. When Disk Utility opens, click on the hard drive partition that has the operating system installed, then click on Unmount at the top
8. Close Disk Utility
9. Go back into the "Utilities" menu (or wherever you had found Disk Utility) and open up the Terminal application
10. Enter the command diskutil list and press Enter. This will list all the partitions on the computer. You're looking for the name of the partition that contains the operating system files, which will most likely be disk0s2 or disk0s3. I think the defaults may be disk0s2 for Intel Macs, and disk0s3 for PPC Macs, but I'm not sure if that's correct which is why you should use the diskutil program to find it
11. Once you know the partition name, enter the command /sbin/fsck_hfs -yprd /dev/partitionName where you substitute the partition name that you found in step 10 for partitionName. This will run the HFS+ version of the file system consistency check on the partition you specified, and will repair and "normal" errors it finds while outputting what it's doing. You could use -ypr instead if you don't want to know what it's doing, but if you're like me you'll be curious to see what it finds. This step may take a while to run
12. After the fsck_hfs command is done running, you can close Terminal
13. Go back into Disk Utility
14. Click on the hard drive partition you unmounted in step 7, then click on Mount at the top
15. Now you could try running the Repair Permissions and Repair Disk within Disk Utility to see if you have any better luck
16. Close Disk Utility and restart the computer.

At this point your problem should be gone and the system should act normally. If not, then there is probably something much deeper wrong with the disk/partition and you may want to turn to professional help. There is always DiskWarrior too if you'd rather try another utility, but since that's not a free tool I'll leave it up to you. The only other thing I can think of is going into Startup Disk before restarting in step 16 and making sure that the computer is set to startup from the partition that you just fixed. Hopefully you'll never need this, but I actually used it this afternoon on a OS X 10.4 machine that Disk Utility wouldn't fix, and afterwards everything was fine. If you want to see the original article where I found this, click here. It's down in the comments because the original poster has something about cloning drives which you can hopefully avoid with this other solution. Good luck!

UPDATE: 6/30/14

It's been over 5 1/2 years since I published this article, and it still is the most popular for comments. I'm glad it has helped so many people and hope it continues to.

A lot has changed in that time though, and it would be even better to avoid the problem by having backups of your data. It is usually such a pain to keep up with backups. Plugging in a USB drive, waiting for the backup to finish, blah blah blah. I have problems with it on my personal machines because it ends up taking too much time and is a hassle. When you run into an issue like this though you realize just how important it is to have those backups.

The reason I'm adding this to the article is because I've started using an application called CrashPlan for offsite backups for business and am very happy with it. So much so that I may just bite the bullet and start using it for my personal machines too. I'm not affiliated with them in any way and am just a happy customer willing to promote their product of my own accord because I have this article and web traffic. There are other similar paid services out there (Mozy, Carbonite, etc), and some free options with a set amount of storage (e.g. Dropbox). If you're reading this article it's most likely because you've experienced some sort of failure with data loss and are probably in a mild panic if you didn't have a backup. These cloud-based services are good options that run all the time without the typical hassle, and will help you avoid that feeling of panic thinking you lost all your photos, work, or whatever else it was on your hard drive. Definitely do your own due diligence on them to find the right one for you.

The much wider adoption of cloud-based services over the past 5+ years and a severe reduction in the cost to utilize those services make them a very viable option for you and I to protect our ever important data.


Anonymous said...

can this be done from a separate mac in targetdisk mode? im a musician on the road and have no access to install disk or a apple store. i do have access to another macbook and a firewire cable tho.

rslygh said...

That's a good question but I wasn't sure, so I just finished running a test with two Power Mac G5 desktops. It worked, however, your results may not be the same if the disk you're trying to fix is severely damaged. If you can get the second Mac to recognize your problematic drive using target disk mode, then you'll be in pretty good shape to start off. You could even try using the Repair Disk option in Disk Utility first from the working Mac before jumping into a Terminal session.

Make sure you unmount the drive first using Disk Utility or else the fsck_hfs command will fail. After unmounting, use the fsck_hfs command on your particular drive. In my test the "problem" drive showed up as /dev/disk1s3, so my Terminal command would be "fsck_hfs -yprd /dev/disk1s3". I would guess you'll end up with either /dev/disk1s2 or /dev/disk1s3, depening on the type of Mac you use. I hope it works out for you, and good luck!

djlopro said...

thanks for the quick reply. it really helps cuz im in a bit of a jam. i'll try this and report back

(somehow i posted anonymous earlier)

djlopro said...

update: just tried. it immediately got "Journal replay returned error = 22" blahblahblah "volume could not be repaired" (i can give you the entire text if u want) so i am going to go ahead and try diskwarrior.

hopefully im not too severely damaged. the drive IS recognized thru target disk mode but not repairable in disk utility.

thanks much for the help though. here goes...

Miguel Antonio said...

What a pain in the neck to get Invalid Node Structure on Christmas Eve have tried to mount the faulty volume via T and linking to another drive - no joy have read that I need to be patient for the drive to mount on my bootable mac - e en purchased DiskWarrior but it's not a bootable version!!! (have to wait for the disc to arrive!!!) Drive Genius didn't work & I have a friend with TechTool Pro and I'll see if that works.... I'm going to give your code a try in terminal and I hope it works, as I'm such a berk! Guess who hasn't backed up his work!!!! A whole year of design work that I can't afford to loose!!!

Thanks for this post though and Merry Christmas - invalid node structure! Bah humbug! First thing I am buying im buying Lacie 2GB and doing weekly if not daily back ups!!!

rslygh said...

Hi Miguel,

I agree. What a Christmas "present" to get. Thanks for the comment though and I wish you luck. Please post an update letting us know the outcome.

Miguel Antonio said...

Well I followed all the steps an typed in the code in terminal app bit the HDD is bad - so have purchased Disk Warrior and cobbled together a start up disk DVD which has allowed me to preview my faulty Drive - which is in a bad way according to the diagnosticn report. Have to ass TechTool Pro was useless (I mean reall crap!!) Drive Genius couldn't do the Volume Rebuild Either (I do like DG but in this instance it was out of it's depth) Disk Warrior though with it's preview drive function has aced it - and as I speak I copying all my files to my FW iomega drive - I've learned that I am going to back up in 2011 on a daily basis. Thanks though - Miguel

O n T Schrock said...


I just spent 8hrs trying to salvage my files from my hard drive by booting my mac from an external and copying files meticulously.

Just as I was about to zero out my hard drive and clean-install, I read this article and it fixed the problem perfectly!

Thank you so much!

rslygh said...

Happy to hear it!

jcwhobe said...

Hey I just tried ur method of sbin/fsck and it's saying (no such file or directory) plz get back to me cuz I have to Dj for my friend's birthday party at dis big club here in DC!

rslygh said...

What are you getting in step #10 for your hard drive partition? If you have an Intel Mac with the default partition settings the full command will likely be: /sbin/fsck_hfs -yprd /dev/disk0s2

jcwhobe said...

That what I put into the terminal but said the same thing! Also I tried to to just erase the partition name Macitosh HD and it didn't erase and then changed the name to disk0s2, so I said forget it and tried to erase the whole hard drive and it still didn't work! OMG! Why now!?!? I need my Mac by Friday! I mean my next step is to just buy a torx kit from radioshack, open it up and replace the whole hard drive with one of the HDs I have lying around!
FYI: I have and external HD that I use for my XBOX 360, becuz my Hd that came with it became corrupted, which is 1 tb! Also I just recently updated my Mac from tiger to snow leopard the beginning of this year and it was fine 4 a while! But I think all my computer electronics in my apartment got surged out and screwed wit da HD except 4 the one in my 2nd bedroom!

Anonymous said...


Even though the terminal came up with some wierd errors, saying it didn't work... I tried running the "repare disk" in the disk utilities afterwards, it showed some new errors, repaired them, and then I was able to boot my OSX. Thank you so much!

phonicpimp said...

What are you getting in step #10 for your hard drive partition? If you have an Intel Mac with the default partition settings the full command will likely be: /sbin/fsck_hfs -yprd /dev/disk0s2

I also have the same issue as above.
The HD partition is definitely disk0s2, however it simply says "No such file or directory.
I have also tried to run that laptop via remote firewire 800 transfer to my working mac, however it only reads the windows partition.
Please help.
P.S you are a bloody genius! Keep up the good work. :)

scarlettw said...

OH MY GOD. I'm a graduate student and cannot breathe without my laptop, it is that vital to my existence right now. Back in august my harddrive went bad and I had to get a new one and pay for data recovery (yep, never backed anything up like the smarty pants I am!). So anyways, I've been terrified of anything else happening. Last night my MacBook (4 years old) was running very slow....took about 4 minutes to save changes on a word document. I restarted the laptop and never got past the boot up screen with the spinning gear. Tried everything, safe mode, disk utility/repair..etc. Nothing. I was about ready to break down crying and commit myself to a mental hospital, because I'm in my final week of classes, and I have been writing lengthy essays on my trusted laptop. I had my school files backed up but still...to lose my laptop and be stuck with a desktop PC...ugh. I came across your post and tried it out and IT WORKED! I can't believe it. I would never have posted comments if I wasn't eternally thankful and so happy to have found something easy to do that worked. You are my HERO. Thank you so much.

Anonymous said...

HI, my issue isn't on of these. I have an external LaCie HD, that just started failing, and now repair won't work, nothing works, I'm a producer of music and I need to get these files. does this method work on external IDE drives or only the Macintosh HD internal?

rslygh said...

scarlettw, I'm glad it worked for your laptop and thanks for the comment.

It should allow you to run it on an external drive, but your likelihood of success is probably higher on bare drives. The reason I say this is because problems with an external drive may be in the drive, or they may be in one of the components in the external enclosure. You can get a IDE/SATA to USB adapter for ~$15. I personally own the one in the link and like it, but you could find one from whatever source you like. If you remove the drive from the external enclosure, you can connect it to the computer using an adapter like this, or it's even better if you can connect it directly to the computer.

Anonymous said...

I am just stumbling upon this...and I think it is all for not, anyway.

I ran this once, but I think I typed it in several times, incorrectly. After a series of whatever, nothing was responding. I was back at my install screen that you see when you first come start up with the disc. When I got on to the Disk Utility, again...my HD was gone. Completely unrecognizable.

So, going off of memory, and knowing that when I went in the previous time that it was already unmounted, I followed through the exact steps and this is what I see:

/dev /rdisk1s2: starting
/dev /rdisk1s2: NO WRITE ACCESS

I have no idea what that means. This was my last step. Before I take the drive out and try and access it externally. If nothing comes of that, it is basically trash, I suppose. I cannot even get it recognized to reinstall the OS. My problem began as a kernel panic on startup, not ever getting off the gray Apple screen. After unsuccessfully attempting to start in Single User, Safe Boot, Target Disk Mode via my MacBook and with the Start Up manager (the start up manager recognizes the disc, but will not open it).

I am not sure if you have any further suggestions, but I am about out. A week ago, I knew absolutely nothing about computers except I can turn them on and run lots of programs. Today, I know more than I want to, and it isn't nearly enough to hold up a conversation with a real techie...and I am hardly staying afloat. I have a new HD coming to swap it out.

rslygh said...

Sorry ordinaryairforcelife, but I think your conclusion that the drive is dead is correct. You can try pulling it out and accessing it from another computer, and can even try running the commands in the blog post while it's in the other computer (if you can get it to show up), but you'll have to be lucky for that to work. The last thought would be to try to swap the PCB (primary circuit board) on the hard drive, but most of the manufacturers have started making this near impossible now by embedding certain information in the chips on the PCB specific to your hard drive. It's worth a shot though. Normally it's just a few screws and then Google the part number on the board and try to match up as much info as you can. Replacement PCBs typically cost anywhere from $40-$200 dollars, and some places will do the swap for you for relatively little too. If there is important information on the drive and none of that will work I'm sure you could send it in and have everything, or most of it, recovered, but you'll likely be looking at a $1,000-$2,000 bill. Good luck!

Diego said...

Hi! I am having the same issue as most here. Tried to reboot my MacBook Air and couldn't get further than the spinning wheel before shutting down. I tried rebooting from my Installation Disc and run Disk Repair. It didn't work and gave me same errors, Invalid node structure, MBAir volume coul dnot be repaired, etc.

Tried the steps on your post but it won't even let me unmount. It asked me to first repair my disk before trying to mount or unmount.

Finally I did a hardware test and everything seems to be OK. "No trouble found".

Is there anything else I could do? (Luckily, I backed up everything before this happened). Thank you in advance!!

Anonymous said...

Ok people.... This sorted me in osx lion, where you have disk0s2 change this to rdisk0s2 and the command runs.

Anonymous said...

Hi, i was having the same problem with the "no such file or directory", but then I typed EXACTLY what rslygh said above (with ALL the spaces). I say this in caps, not because others are dumb, but it's what I did... I am not a tech wizz, but fingers crossed this fixes the issue!!

dotty said...

My drive doesn't show in disk untility, however If i hold OPTION the "Macintosh HD" shows there. Any ideas?

Anonymous said...

Thank you so much. This saved my a$$.

Anonymous said...

Thank you sooooo very much. This totally worked. I was getting the "no such file or directory too" saw the comment about including the spaces in the command. There is a space after hfs and a space after -yprd. So happy - thank you again!

Antonio Carvalho said...

Thank you for this tip, it saved my bacon! I tried all other possibilities and was about to resort to diskwarrior but yor fsck command did the trick and fixed the bad nodes and everything else that was wrong with the partition.

Unknown said...

Thank you! You just got me out of major trouble.

Anonymous said...

Thanks a lot, this method worked wonders for me!

Anonymous said...

Perfect solution! Thanks for taking to time to post it. I only thought is why does the repair feature in Disk Utilities not implement that routine when it's normal procedure(s) break down?

rslygh said...

You're all welcome, and I'm glad it's helped. I've used it many times since posting this and it has still worked more times than not.

As to why it's not part of Disk Repair, your guess is as good as mine.

Unknown said...

i tried your command, but it just says "invalid volume header" and "the volume Macintosh HD could not be repaired" along with a lot of other stuff. any help. i cant seem to mount my Macintosh HD. its greyed out in disk utility.

rslygh said...

Unfortunately that's not a good sign. You could attempt using Target Disk mode to access the contents of your drive if you have another working Mac and both have firewire ports. To do that you connect the two with firewire, then boot the device you're trying to access while holding down the T key. Then it shows up on the working Mac as an external drive. However, this likely won't work since the drive structure seems to be corrupt. Your best bet is to try a 3rd-party recovery tool, such as Disk Warrior, to see if you can recover the contents of the drive. Or if the contents aren't that important, perform a clean install of OS X.

Brie said...

Thank you for this post! I was able to run the fsck_hfs command and it has been going for about two hours. It is obviously doing something but the messages being returned are things like "invalid record count" and "invalid node structure". Is this to be expected or should I assume at this point that it's not accomplishing anything? Any assistance you can provide is very much appreciated! Thank you in advance!

rslygh said...

Hi Brie,

Two hours seems pretty long, but I can't remember how long my longest attempt went. My suggestion would be to leave it be, but you could also try restarting it. There's a chance it's caught up and that restarting the process will help it get past the issue. There's also the chance that when you kill the job that you unknowingly were only a few minutes away from it completing. Unfortunately the latter seems to be the case for me most of the time because I lose patience when I can't see the job status. It's up to you, but as long as you are seeing those messages continuing to pop up occassionally, I'd leave it be until it says it's done.

Anonymous said...

Hi, after completing the steps 11, the issue was not resolved. So as per step 13 went back to disk utility and tried to mount the internal harddrive and it did not allow stating harddrive cannot me mounted. i am on 10.6.8. How do i mount now.

GeoPa58 said...

This worked for me -- many thanks!

MBP (2009) would not boot, even in safe mode.
Disk Utility could not repair the disk.
fsck_hfs followed by Disk Utility did the trick.
(At least I was able to get key backed up. Probably should back everything up and reinstall system software...)

Thanks again.

Anonymous said...

Just wanted to thank you very much. Your how-to course really saved my a** that night. It worked pretty good on MacOS 10.7.5. Everything worked out like expected. Thanks.

Dirty Swift said...

Thanks man!!!!! You saved my life! Tried so many things and it was not working!

Alon said...

Hi, I dropped my MacBook and understandably haven't been able to start up since. I keep trying to do what you wrote but after one long run in which it said that it couldn't be repaired, now it says "No write access/unexpected inconsistency; run fsck_hfs manually". Any advice? Thanks in advance.

Alon said...

Just got it to run again and got:

The volume MacBook HD could not be repaired.
Volume type is pure HFS+
Primary MDB is at block 0 0x00
Alternate MDB is at block 0 0x00
Primary VHB is at block 2 0x02
AlternateVHB is at block 976101342 0x3a2e1fe
Sector size = 512 0x200
VolumeObject flags = 0x07
Total sectors for volume 976101344 0x3a2e1fe0
Total sectors for embedded volume = 0 0x00

Thanks for any help you can give me.

HJ said...

Thank you. This saved me a lot of time and headache.

rslygh said...

Sorry Alon, but if you dropped it and are having trouble it's probably a safe guess that the hard drive has physical damage. In that case you'd have to send it off for professional recovery (big $$$) or if you don't have a backup of the files consider it a loss and get a new hard drive.

Unknown said...

Thank you so much! This totally worked on my i& imac running 10.6.8. I had to boot from cd and alternate running your terminal command and disk utility. IT took about 3 hours of cycling through and allowing the terminal to hang for 15 minutes, but finally spit out a string of fixes and said repairs were successful.

You saved my machine! Just completed an 8 hour time machine backup, next steo is a bootable drive.

Thanks again!

Lolessia said...

hi ! i have this problem in my powerbook with tiger
i try your method with mac os install dvd ,terminal says invalid node structure and mac os can not be repaired
i have disk warrior dvd but computer doesn’t take this dvd (can’t read ) i tried disk warrior in target mode but host computer doesn’t see target computer >>>
and pre story - i had this invalid sibling link first than invalid node structure on my ibook and than i wanted to repair it with my power book in target mode , and after that connection my powerbook got same problem and now i have two computers with same problem that i can not solve))) crazy) my powerbook has a new hdd so i am sure it is fine but i can’t boot it again )and i can’t erase and install new mac os cause its says there is no volume ) on another ibook i tried with disk warrior it worked only from third time.it was rebuild but after restart it is doesn’t work again ) i put there os install dvd again check disk and it is say its fine but not booting after restart ) i can forget this ibook ^ but powerbook with new hdd i would like to be alive and good as before
sorry if the story is too long ^ but definitely there are some mistakes that can not be fixed even if the hdd is good ( after target mode connection it started some new sound from hdd )
don’t know if you have any recommendation for me ( can i try disk warior with usb hdd ?)

rslygh said...

If you were able to get the affected hard drive into target disk mode and have it show up on a second Mac, I hope you backed up your files? Once that's done my next suggestion would be to reinstall OS X and start fresh. It sounds like the corruption is too much for this command to fix, or that the hard drive is faulty. Your best bet now would be to try getting whatever data off the drive that you can, either through target disk mode or through some type of recovery application that will work on HFS+ volumes.

Nic lee said...

After numerous fails, attempts, persistence, it worked. Thanks so much, life saver (on snow leopard).

Maya said...

Hey there--

I've been googling and reading and googling and reading and trying fixes and failing all day. Out of all the websites I've read though, it seems like you might be the best help in troubleshooting my problem.

Yesterday my mac froze and since it wasn't responding to any commands, I manually shut it down. After a couple failed attempts booting it up again, I inserted the Mac OS X installation CD and tried verifying and fixing the HD resulting in invalid node structure and volume not verifiable.

Multiple attempts later [copying the HD image to another computer, an external harddrive, inserting Ubuntu live CD, Ubuntu fsck commands, nautilus, etc.], I've had no luck transferring any of my data off the HD.

Now, after trying your solution [/sbin/fsck_hfs -yprd /dev/disk0s2], I get this message:

Journal replay returned error = 22
hfs_swap_HFSPlusBTInternalNode: extents key #54037 offset too big (0x0000)
Invalid node structure
(3, 0)
The volume could not be verified completely.
volume check failed with error 7
[followed by a series of notes/parameters]

At this point, I'm assuming the worst, but I'm not sure what next steps I should take. Is there anything else I can do with terminal or disk utility? Is there anything I can do with ubuntu? Do I need to start over with a new hard drive? Thanks for your expertise.


rslygh said...

Sorry to hear that Maya. Unfortunately, if this trick doesn't fix the invalid node issue then I think your best bet is going to be a 3rd party recovery tool like Diskwarrior, or professional recovery services. I'm not promoting Diskwarrior in particular as I've never used it, but it seems to be a popular one.

Now, if you definitely have a good image of the hard drive, this is a thought I just had that you're welcome to try. You should be able to do an upgrade reinstall of the OS using the OS install disk, and as long as you don't have to format the drive first, it just may repair the OS enough for you to boot and get the data off the drive. However, writing any data to the drive risks overwriting files you want to recover, so use this at your own risk.

Good luck with your recovery!

sin said...

Just want to share what I did yesterday. I did all the stuffs mentioned in your blog and retry it again and again, but the error still persisted, and I began to wonder if I could still save my data at all.

But, I realized that for some reason, Disk Utility could still mount my drive when I boot from the Install CD. So what I did was to connect my backup hard disk, enter the terminal, and copy my important files to the backup harddisk through command line, something like this:

copy -R src dest

And, all seems to be well, although I still have to reinstall my os.

Anyway, just want to share. I wish other people could also manage to at least backup their data.

rslygh said...

Thanks for sharing sin, and yes, if the drive mounts then you should be able to plug in an external drive and copy files over. You may not be able to get all of them without hitting some corruption, but it's still much better than having a complete loss of data

Anonymous said...

OMG! This actually worked!!! You saved me!!! I am eternally grateful! Thank you so much.

Anonymous said...

Thank you! The only thing that worked!

Nick Lakin said...

After spending hours trying to fix this (tried upgrading to Yosemite from Snow Leopard) and going round and round on the Internet and having MANY people tell me the hard drive is bad and needs replaced, I finally found this and after running fsck twice, to my surprise said repaired successfully! THANK YOU very much for your help. REALLY appreciate it!!

Anonymous said...

Hi, I see Mac has this problrm over years. I also go this msg
when I try your command with DISK1S2 it shows the following:



Anonymous said...

Thank you so much for this post. It helped to get damaged El Capitan copy running in no time. I'm a music composer and had a month's work of compositions that wasn't backed up. If I had to redo all of it, it would have been a nightmare. One hitch was the Spotlight Search icon gone forever.