Re-Formatting a USB Drive with GTP Data (Mac) in Ubuntu

I ran into a problem the other day when I decided to create a bootable USB drive for upgrading my fiancée’s Mac to OSX Yosemite.

After creating the drive with the bootable upgrade data, I decided to reformat the USB drive back for my typical use. This particular USB drive is one that I’ve used primarily for installing OS’s, so I regularly wipe it and use it to boot as a live USB for various Linux distros whenever I want to test something or (re)install it. However, I found that I couldn’t format this drive and use it to boot an OS as I had done before. GParted would perform the formatting action and partition the drive, but I could not get it to mirror the same Partition Type of W95 FAT32 (LBA) as the other drives I had. Whatever the problem was, it also caused Ubuntu’s Startup Disk Creator to be unable to perform the Erase Disk function on the drive without giving a long error that ended with the explanation of an invalid UUID. Searching for this error came up with nothing. So, snooping around, I decided to try formatting the drive via terminal, and that’s when fdisk gave me an error stating the the drive had GPT data, which is’t supported by fdisk.

A little more snooping online led me to this page, where an explanation of removing GPT data (used by Mac) was given. Following the steps outlined on that page using gdisk, and then following up with formatting via terminal with fdisk to reformat the drive as W95 FAT32 (LBA) type, the problem was finally resolved.

I’ll outline the steps, from beginning to end, for removing the GTP data and formatting back to FAT32, which I assume is how most USB flash drives are formatted by default.

First, issue the following command:

sudo fdisk -l

Note that you must issue the command with sudo, or else it will output nothing. Find your drive in the list of devices and it should have a line similar to:

   Device Boot      Start         End      Blocks   Id  System
/dev/sdX1               1  4294967295  2147483647+  ee  GPT

The values for Device, Start, End and Blocks will vary, but the value for Id and System will be ee and GTP as shown. Make note of the device’s designation, as it is important that you perform the next tasks on the correct device to avoid data loss or compromising your PC. Also be aware that some external hard drives are formatted this way (the above output that I used is of an external drive that I have that happened to be formatted to fit the example), so make sure you don’t mistake the wrong device for the one you’re meaning to format.

Now that we know the device we need to reformat, we have to use gdisk to remove the GPT data for us. fdisk does not support GPT data types.

gdisk /dev/sdX

I decided to call my device for the example sdX, where X would be the letter assigned to your device. In most cases, unless you’re performing this on the drive that your PC boots from, you’ll likely not be using sda or sdb. Otherwise, you may want to refer to Rod Smith’s steps that explain how to backup the drive’s MBR data. Since this post is meant to cover an external USB flash drive (per my personal situation), I won’t include those steps.

The above command will output something similar to:

GPT fdisk (gdisk) version 0.7.2

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: present

Found valid MBR and GPT. Which do you want to use?
 1 - MBR
 2 - GPT
 3 - Create blank GPT

Your answer:

In my case, I wasn’t asked which partition table to use, because MBR was restricted – causing GPT to be the only one available. However, it doesn’t matter which one you choose, if asked, since we’re wiping the GPT data and not looking to convert or salvage data.

You’ll be presented with a command prompt:

Command (? for help):

The remainder of the command prompts should be issued as:

Command (? for help): x

Expert command (? for help): z
About to wipe out GPT on /dev/sdX. Proceed? (Y/N): y
Blank out MBR? (Y/N): n

Make sure you answer n when asked if you want to blank out the MBR. This may not be as crucial for a USB flash drive, but wiping the MBR on a drive that you use to boot from would be disastrous (especially if you didn’t back it up beforehand).

The next steps are actually formatting the drive using fdisk. Substituting in sdX for your drive’s device, enter the following commands when prompted in the order shown to perform the format of the drive. Note: output has been omitted. Where no response is shown for command prompt, simply hit enter.

sudo fdisk /dev/sdX
Command (m for help): p
Command (m for help): d
Command (m for help): p
Command (m for help): w
sudo fdisk /dev/sdX
Command (m for help): n
Command (m for help): p
Partition number (1-4): 1
First cylinder (1-1020, default 1):
Last cylinder, +cylinders or +size{K,M,G} (?-????, default ????):
Command (m for help): t
Hex code (type L to list codes): L

At this point, you’ll be presented with a list of all device types you can format the drive to using fdisk. In this case, I wanted W95 FAT32 (LBA), so I chose b

Hex code (type L to list codes): b
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Command (m for help): w

Finally, we can format the drive:

sudo mkdosfs -F 32 /dev/sdX1

The last command could technically be handled via Disk manager or GParted, if you wanted a user interface instead of terminal, but it would make sense to just issue the command in terminal since we’re already working in terminal for the rest of the steps.