How do I use MacOS Terminal or other app to format an MBR FAT32 SD card as a 0x0C partition, rather that 0x0B?

apple.stackexchange https://apple.stackexchange.com/questions/415891

Pregunta

Apple's Disk Utility app can format an SD card as MBR FAT32; but in the Terminal, I confirmed the SD card's partition is in fact 0x0B:

> sudo gpt show /dev/disk3

 start      size  index  contents
     0         1         MBR
     1      2047         
  2048  62746624      1  MBR part 11

"MBR part 11" refers to 0x0B. I want the partition to be MBR part 12 (0x0C).

I then tried this in the Terminal:

> diskutil unmountDisk /dev/disk3
Unmount of all volumes on disk3 was successful

> sudo fdisk -ia dos /dev/disk3
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory

    -----------------------------------------------------
    ------ ATTENTION - UPDATING MASTER BOOT RECORD ------
    -----------------------------------------------------

Do you wish to write new MBR and partition table? [n] y

But if I click the "Initialize..." button, it merely opens the Disk Utility app, which I know will only format as MBR FAT32 0x0B.

How can I use MacOS Terminal or another Mac app (not Windows or Linux) to format the SD card as MBR FAT32 0x0C?

¿Fue útil?

Solución

If macOS defaults to type 0B and you wanted 0C, then you do not need a third party tool to make the change. Just use the command fdisk with the -e option to make the change. In your case, the commands would be as follows.

diskutil unmountdisk disk3
sudo fdisk -e /dev/disk3
s 1
c
q

Note: The diskutil unmountdisk disk3 unmounts of all volumes on disk3. The fdisk -e /dev/disk3 command needs to entered immediately afterwards or the volumes may automatically remount. (In this case, there should be only one volume.) Failure to do so may cause a fdisk tp attempt a shared lock. If successful, then a y (for yes) will need to be entered after entering the q command.

An example is given below.

Marlin-3:~ davidanderson$ diskutil unmountdisk disk3
Unmount of all volumes on disk3 was successful
Marlin-3:~ davidanderson$ sudo fdisk -e /dev/disk3
Password:
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Enter 'help' for information
fdisk: 1> s 1
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: 0B 1023 254  63 - 1023 254  63 [         2 -    1953186] Win95 FAT-32
Partition id ('0' to disable)  [0 - FF]: [B] (? for help) c
fdisk:*1> q
Writing current MBR to disk.
Marlin-3:~ davidanderson$ 

The rest of this answer is just background information. You can skip if you like.

The fdisk command with the -e option is interactive. The s command is short for setpid and the q command is short for quit. Below is a list of the interactive commands. This was taken from the output of man fdisk.

help    Display a list of commands that fdisk understands in the interac-
         tive edit mode.

 manual  Display this manual page.

 reinit  Initialize the currently selected, in-memory copy of the boot
         block.

 auto    Partition the disk with one of the automatic partition styles.

 disk    Display the current drive geometry that fdisk has probed.  You
         are given a chance to edit it if you wish.

 edit    Edit a given table entry in the memory copy of the current boot
         block.  You may edit either in BIOS geometry mode, or in sector
         offsets and sizes.

 setpid  Change the partition identifier of the given partition table
         entry.  This command is particularly useful for reassigning an
         existing partition to OpenBSD.

 flag    Make the given partition table entry bootable.  Only one entry
         can be marked bootable.  If you wish to boot from an extended
         partition, you will need to mark the partition table entry for
         the extended partition as bootable.

 update  Update the machine code in the memory copy of the currently
         selected boot block.  Note that this option will overwrite the NT
         disk signature, if present.

 select  Select and load into memory the boot block pointed to by the
         extended partition table entry in the current boot block.

 print   Print the currently selected in-memory copy of the boot block and
         its MBR table to the terminal.

 write   Write the in-memory copy of the boot block to disk.  You will be
         asked to confirm this operation.

 exit    Exit the current level of fdisk, either returning to the previ-
         ously selected in-memory copy of a boot block, or exiting the
         program if there is none.

 quit    Exit the current level of fdisk, either returning to the previ-
         ously selected in-memory copy of a boot block, or exiting the
         program if there is none.  Unlike exit it does write the modified
         block out.

 abort   Quit program without saving current changes.

Note: The warning message fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory is correct. The /usr/standalone/i386/boot0 file is not part of macOS. Instead of reading this file, fdisk substitutes zeros. This results in the update command erasing any existing machine code instead of updating with actual machine code.

 

Otros consejos

Your fdisk invocation should have already partitioned it as type 12. You can press the Ignore button and verify via Terminal that that's the case, then simply eject the disk from your computer and use it wherever you intend to use it.

If you intend to use this drive on your Mac, you will need to format and mount it after running fdisk:

sudo newfs_msdos /dev/disk3s1
sudo mkdir /Volumes/FLASH
sudo mount -t msdos /dev/disk3s1 /Volumes/FLASH

Here FLASH is an arbitrary volume name that I chose for sample purposes; feel free to choose your own.

As a clarifying point, the s1 portion of /dev/disk3s1 targets the first partition of disk3. If you were to specify just disk3 instead, the newfs_msdos command would overwrite the partition table.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a apple.stackexchange
scroll top