Repair / Fix Mac HFS+ partition using Ubuntu CD

This post will tell you how to repair / fix Mac HFS+ partition using Ubuntu CD (Live CD or Install CD).

What do you need to do this?
Ubuntu CD (I used Ubuntu 8.10 Desktop Edition Install/Live CD)
Mac
Internet Connection (Wired)

Few days back I had installed Debian 5.0 lenny on my MacBook. Because, I don’t have much hard disk capacity (only 80 GB), I had to delete the Linux partition (waiting for Ubuntu 9.04).  I used BootCamp Utility (in Mac) to delete the Linux partition. It wipes off all the linux data & restores Mac partition (ex: I had 60GB Mac + 20GB Linux, After restore 80GB* Mac).
I was happy that it was restored. But, the partition had errors after restores. I was not able to copy/store the any data if it exceeds 60GB on Mac, it says the Mac startup disk is full. Then I realized that the Mac file system (i.e., HFS+) had errors. Yes, the Ubuntu CD is there to rescue me. Enough story… follow this to proceed…

1. Disable journaling on Mac parition before booting into Ubuntu CD
Use this command on your Mac terminal

  • sudo diskutil disableJournal /dev/disk0s2

where disk0s2 is your Mac partition (use ‘df’ command to find out the root disk name, it should be mounted on ‘/’)

2. Boot from Ubuntu CD
Insert the Ubuntu CD, press ‘C’ on startup to boot from CD.

3. Connect to Internet & Install HFSprogs
After Boot connect to Internet, Yeah! I know the wireless won’t work now. I suggest you to connect from Wired.
I assume that you are connected to Internet now.
Then enable Universe packages using ‘Software Sources’.
Then, Install hfsprogs package

  • sudo apt-get install hfsprogs

    This will enable you to check & repair the HFS+ paritions.

    4. Check & Repair

    You need to do fsck check on your Mac partition. Use fdisk command to find the Mac device.

    abhinay@ubuntu:~$ fdisk -l
    WARNING: GPT (GUID Partition Table) detected on ‘/dev/sda’! The util fdisk doesn’t support GPT. Use GNU Parted.

    Disk /dev/sda: 80.0 GB, 80026361856 bytes
    255 heads, 63 sectors/track, 9729 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x00000000
    Device Boot Start End Blocks Id System
    /dev/sda1 1 9730 78150743+ ee GPT

    using fdisk didn’t show the Main Partition of mac, It shows only one partition. The above partition sda1 is the EFI partition (boot partition).
    That means, /dev/sda2 is your Mac partition.

    Perform fsck on sda2

    abhinay@ubuntu:~$ sudo fsck.hfsplus /dev/sda2
    ** /dev/sda2
    ** Checking HFS Plus volume.
    ** Checking Extents Overflow file.
    ** Checking Catalog file.
    ** Checking multi-linked files.
    ** Checking Catalog hierarchy.
    ** Checking Extended Attributes file.
    ** Checking volume bitmap.
    Volume Bit Map needs minor repair
    ** Checking volume information.
    ** Repairing volume.
    ** Rechecking volume.
    ** Checking HFS Plus volume.
    ** Checking Extents Overflow file.
    ** Checking Catalog file.
    ** Checking multi-linked files.
    ** Checking Catalog hierarchy.
    ** Checking Extended Attributes file.
    ** Checking volume bitmap.
    ** Checking volume information.
    ** The volume Macintosh HD was repaired successfully.

    Hurray! It is repaired now…!

    One more last thing you ‘ll have to do.

    5. Enable the journaling on Mac Partition
    use this command on Mac to enable the journal back.

    sudo diskutil enableJournal /dev/disk0s2

    You are done! 🙂

    **This worked for me!

    Comment me if you have any troubles or suggestions. Thanks for reading my blog!

    Posted on Apr 12, 2009
    Written byAbhinay Omkar
    • Mike

      Awesome! Worked for me as well. Was missing about 20GB from a power outage during partitioning and this did the job and brought the free space back! Thanks!

      • Nice to know that it worked for you!

        Thanks!

    • logi

      Hi Abhinay,
      I want to format the hard drive having Linux partition. My niece got the mini with the Linux. She want xp on it.
      Now the linux installer is not running after one point.

      How to use your method to format the linux partition to FAT32 or ntfs.

      Your help will be great. I have spend lots of time but no help.

      At work and home I am using Fedora 10.

      Thank you in advance.

      Best regards Logi

      • I’m unsure if I understood your problem.

        If she is having only one Linux partition, I would suggest to boot using Ubuntu Live CD and use gparted to edit the paritions. Backup any important data and delete the Linux partition and then create a new partition for FAT32/NTFS. I would suggest her to use latest Ubuntu Version: http://www.ubuntu.com/getubuntu

        Thanks!

    • Shiv

      I have a crashed HDD on a mac. How can I get the data back to an external HDD after booting from ubuntu. I have done it with windows but how do I get Ubuntu automount my HFS partition?

      • Try to recover your Mac Harddisk using above process. If you are still not able to recover, I would suggest to contact Apple Customer Service to protect your data. If you are able to mount the Mac partition from Ubuntu then you can backup your data to your External HDD.

        This should help: https://help.ubuntu.com/community/AutomaticallyMountPartitions

        Thanks!

    • KSPC

      mkdir /mnt/sda2
      modprobe hfsplus
      mount -t hfsplus /dev/sda2 /mnt/sda2

      I used the above running puppy linux cd to mount the mac drive. This will allow you to read and copy from your hard drive to usb or what have you.

      Hope this helps

    • Anonymous

      if you cannot deactive the journaling and received this error.

      yourcomputer:~ youruser$ sudo diskutil disableJournal /Volumes/Janice
      Password:
      An error occured journaling the filesystem: The underlying task reported failure on exit (-9972)

      Let’s try. Unmount your drive — “Eject” in the Leopard finder. Then form a slightly different command by inserting the term ‘force’ after the disableJournal command, and by replacing the mounted volume name with the partition identifyer that you use before

      yourcomputer:~ youruser$ sudo diskutil disableJournal force /dev/disk1s10
      Password:
      Journaling has been disabled for volume Janice on disk1s10

    • pedro

      nothing says my disks are clean and A-ok – although i could not dejournalise them before doing the fsck procedure (i did use the -f attribute (force) and got the same result). i reboot and just get the spinning wheel of death .. for hours (5 or so now to be exact) … i di a check of the disk using macdrive under my bootcamp partition as well and it says the drive is unreadable due to structural corruption -> i think i’m f*ked

    • Vince

      Doesn’t work for me. I’m still getting the same error as running fsck straight in OSX.

      ubuntu@ubuntu:~$ sudo fsck.hfsplus /dev/sda2
      ** /dev/sda2
      ** Checking HFS Plus volume.
      ** Checking Extents Overflow file.
      ** Checking Catalog file.
      Keys out of order
      (4, 1084)
      ** Rebuilding Catalog B-tree.
      ** The volume Macintosh HD could not be repaired.
      ubuntu@ubuntu:~$

    • I’m so grateful, thanks a lot!

    • One of my partition of external HDD isn’t recognized by Mac. It appears on disk utility but won’t mount. I try to repair disk using disk utility function, but it took long time. It looks like my Mac having hard time for doing the work. In the middle of the process, it ejected itself.
      So I want to try your option, using Ubuntu for repair the partition. But one of your step including disable journaling on that partition. Yes, I’m aware from some forum, Ubuntu is capable read and write HFS+ but not with journaling enabled.

      Before I try this method I want to ask this question. Is it still possible to disable journaling when my partition didn’t mount? I’ve already check on disk utility it only appear as gray. Via terminal, it reads as disk0s2 or something.
      How fast this disable journaling is? Is it less than a minute? I will assume if it tooks longer than 5 minutes, then my Mac truly cannot access that partition thus unable to disable journaling.

      Actually my problem is more severe than one partition not able to mount, but at least I want one of my partition able to mount again.

      Thanks in advance.

      PS: my actual problem is you could read it at apple discussion board, page 15 and 16 ( http://goo.gl/NhvUd ), username omega8719.

      • Anonymous

        @Psycho Yes, you can enable/disable Journal device whether the volume is mounted or not.

        from man page of diskutil:

        enableJournal device
        Enable journaling on an HFS+ volume. This works whether or not the volume is currently mounted (the volume is temporarily mounted if necessary). Ownership of the
        affected disk is required.

        This shouldn’t take much time, it’s like setting a flag on/off. Should be done in seconds.

        • No good. Just as I feared, OS X didn’t respond to this partition. I wonder what is wrong.
          http://i.min.us/ilIGwo.png

          Enable/disable journaling is fast. I’ve tried it on other partition. But for this problematic partition it return nothing. I’m waiting for about 2 minutes…… no response.

          I also try this TestDisk to analyze.
          http://i.min.us/ilIm64.png
          Could you help me what is this mean? I don’t understand technical thing like CHS and LBA. Reading wiki didn’t help when my head still worrying the data inside my disk.

          Is it still repairable when using Ubuntu?

          This is all started just because a mere random eject. Apple discussion board still not found plausible solution for me. Sigh~.

          • Anonymous

            @Psycho Sorry, I didn’t find any useful stuff for you. I can only suggest you to take your hard drive to data recovery specialist. Let me know if you find any solution.

    • Marta

      hello, any idea why I cannot disable the journaling?

      Marta$ sudo diskutil disableJournal /dev/disk1s1
      An error occurred journaling the file system: Couldn’t mount disk (-69842)

      otherwise, the fsck fails, I guess its not a good sign?

      ubuntu@ubuntu:~$ sudo fsck.hfsplus -d /dev/sdc1
      ** /dev/sdc1
      Using cacheBlockSize=32K cacheTotalBlock=1024 cacheSize=32768K.

      ** Checking HFS Plus volume.
      ** Checking Extents Overflow file.

      ** Checking Catalog file.
      ** Volume check failed.

      volume check failed with error 5
      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

      alternate VHB is at block 5860464638 0x15d4f97fe
      sector size = 512 0x200
      VolumeObject flags = 0x07
      total sectors for volume = 5860464640 0x15d4f9800
      total sectors for embedded volume = 0 0x00

      ubuntu@ubuntu:~$

      any help appreciated!

      Marta

    • thumb

      But what if you are creating a Disk with many partitions and want to re-enable HFS+ journaling when in linux.

      sudo mkfs.hfs /dev/sda[x] -J 64M

      should enable journaling on an already created hfs+ partition.

      Journaling can be up to 512M refer :
      http://manpages.ubuntu.com/manpages/natty/man8/mkfs.hfsplus.8.html

    • almasofia

      In this situation when your partition is corrupted or formatted.
      you need to relevant [recovery software to restore your data and repair
      partition error. There are some reason
      partition corruptions.
      http://hfspartitionrecovery.org

      – Wrong way to
      formatted your system

      – Virus attack

      – Improper way to
      shut down your MAC PC

      – Physical Unwanted
      movement

      – Also any Technical
      cause of partition corruption
      http://www.macdatarecovery.info/hfspartitionrecovery.aspx
      There is no matter what is reason of data partition .Here is
      MAC OS X Lion Leopard and Snow Leopard
      partition Recover software to resolved your problem in few clicks
      http://hfspartitionrecovery.org/
      – Recover
      Your lost Mac files after HFS or HFs+ Partition formatted