Published in


Repairing a Partition Map on Hard Drive

If you are sick and tired of paying through the nose for hard drives then I have the solution for you.

I have been known, and I still am known, to repurpose hard drives from a piece of equipment most of us have in our homes. Yes, that’s right, most of us have a hard drive that we can use with our home PC’s sat right under our noses (don’t know why the obsession with noses but there you go).

Ever wondered what to do with that Sky, Virgin or Freeview box you have had lying around gathering dust after you cancelled your subscription and never sent the box back?

If you take the box apart you will find a fully functioning hard drive that you can (after a little formatting) use as part of your home network.

The title of this article is relevant and I will get to why in a moment.

If you format the hard drive, using Disk Utility on Mac or any other disk utility service you can reformat the disk into the correct format for your needs.

Now, I have done this on a number of occasions and I have used a couple of these hard drives for different tasks. This leads me nicely on to the subject at hand.

One such drive was used as local storage on my home network and I decided to partition the drive to Fat32 and exFat (2 different partitions). I did this as I was using a Raspberry Pi as the server and wanted the option of different formats.

I subsequently tried to use said drive and it wouldn’t work, it didn’t like the partition one bit. So, I thought I would use Disk Utility to format the drive into one single partition. I thought wrong.

Disk Utility would not pick up the HDD to enable me to format the drive to perform the first aid action to find the fault and repair the drive.

This left me with somewhat of a conundrum. So how did I resolve the issue? I turned to the terminal.

The terminal on the Mac is a wonderful thing, you can perform almost any task and it is much more robust than performing the same task on the GUI.

Firstly, I tried to find the HDD using the command

$ diskutil list

This command brings up a list of drives that are connected to the system. This command showed that the Hard Drive was in fact connected, it was just that the system could not read the partitions. Take a note of your disk location (You will need this shortly).

Next, I need to try and repair the drive seems as the first aid option in Disk Utility isn’t available. to do this I use the following command, replacing ‘diskx’ with your disk location found before.

$ diskutil repairDisk /dev/diskx

Now, at this point I came across a problem. The terminal was telling me that the partition map was corrupt. I can only surmise that this was something to do with the multiple times I formatted the drive prior to it’s current state. so what to do?

It seems that I needed somehow to erase the data on the drive. Formatting it using the ‘eraseDisk’ method wouldn’t work, neither would the ‘reformat’ command.

I decided that to try and fix this increasingly annoying problem I would need to rebuild the partition map. I used the following command. BE CAREFUL, THIS COMMAND WILL DESTROY DATA.

$ sudo dd if=/dev/zero of=/dev/diskx bs=512 count=1

This process will overwrite the beginning and end of the data on your hard drive, when I say above that this will destroy data, I mean it.

At this point it would be wise to verify the disk and unmount the disk by using the following code

$ sudo verifyDisk /dev/diskx

$ sudo repairDisk /dev/diskx

Ok, so now if you re-open Disk Utility your drive should be visible and the options to perform first aid and erase that were previously unavailable should now be selectable.

Needless to say, you can now re-format the disk to your preferred format and use as you see fit.

I personally have used the drive for local storage but you can use it for whatever you desire.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
The Savvy Web Developer

Proud Father | Ex Lawyer | Self-Taught Software Developer | Cyber Security Enthusiast | Techpreneur | Legend | General Nuisance.