I am trying to format my SD card on a mac (macOS Mojave 10.14.6)

I am using a card reader hooked up to the computer and the SD card adapter is on the unlocked position. My SD card is a samsung evo 32GB.

This is what the terminal looks like, its a modified archlinux script:

Deannes-MBP:~ dena$ SD_CARD=/dev/disk2s1
Deannes-MBP:~ dena$ echo "o p n p 1 +100M t c n p 2 w"| fdisk $SD_CARD
fdisk: /dev/disk2s1: Permission denied

I also tried this to have a look:

ls -l /dev/disk2s1
brw-r----- 1 root operator 1, 9 1 Mar 16:14 /dev/disk2s1

Not sure if it helps.

I am totally new to this and have little computer knowledge (especially coding). I have looked at other posts/problems online, and I have tried to blow into the card reader (someone said that it helped). But it didn't do anything.

When I look at sharing and permissions for the SD card it says you have custom access.

So if anyone has any ideas about how I can format this, it would be great.

  • Let me ask some stupid questions :) Some SD cards have a write protection switch. Is that disabled? Any reason you are using Terminal rather than Disk Utility? Are you running the command with elevated privileges? Mar 1, 2020 at 23:13
  • The white button that unlocks the sd card is in the unlock position. I am using terminal because I need to install a custom os onto the sd card based on the archlinux system. I don’t know if this help. Thanks
    – Dena
    Mar 2, 2020 at 4:13
  • Got it. You shouldn't need to use terminal to format the card, Disk Utility will probably work. That said, are you using elevated privileges to run the command? Such as sudo or logging in as root? Mar 2, 2020 at 5:20
  • I am not sure, the instructions I am following says to do as root, not as sudo. So it doesn't look like I need any extra permissions. The instructions say "essentially we want to install a custom archlinux, but replace the latest archlinux with a custom OS snapshot avaliable inside a zip archive" (which I have to download via wget).
    – Dena
    Mar 2, 2020 at 5:44
  • If the guide say to run as root that means elevated privileges. sudo elevates the command you are running to root privileges. 'Permission denied' means the current user doesn't have sufficient privileges to run the command. sudo is one way to elevate privileges. You can run sudo !! as a handy shortcut, to run the previous command again with sudo. See for further reading: linuxacademy.com/blog/linux/linux-commands-for-beginners-sudo Mar 2, 2020 at 5:50

2 Answers 2


Below itemizes some of the problems with procedure posted in your question.

  • As others have posted in the comments and answers, you need to precede the fdisk command with sudo.
  • Other users have suggested that the security setting need to be modified. The version of macOS used for verifying this answer was Catalina version 10.15.3. Below is the System Preferences setting in the Security & Privacy pane. Under Full Disk Access, the Terminal application is not checked off, as shown below. Under Files and Folders, the following was checked off for Terminal.
  • The fdisk command in your question is not being applied to a drive. The identifier disk2s1 could represent a partition, container, session or volume. While the fdisk command can allow for this, there is no logical reason for doing so. The device should be of the form /dev/diskN where N is a positive integer. Care should be taken to confirm you are actually referring to the SD card.
  • The fdisk can be an interactive command. This means the command can require text read from standard input. This text is often referred to a input commands. Under Linux, fdisk defaults to interactive. However under macOS, fdisk does not. To make fdisk interactive under macOS, the ‑e option must be included. In your question, this option was omitted.
  • You tried to pipe the input commands to fdisk. Each individual command was separated by a space (). However, each command should have been separated by a newline (\n). Basically a newline is the same as entering a return from the keyboard. Also the string should have be enclosed by the characters $'' instead of "".
  • The input commands to fdisk presented in your questions would be valid if the operating system was Arch Linux. The equivalent commands which would be correct under macOS are given below.

    edit 1
    edit 2

The correcting for the above errors would lead to the command shown below. Here, the input commands have be abbreviated.

    echo $'er\np\ne 1\nc\nn\n2048\n204800\ne 2\n83\nn\n\n\nq\ny'|sudo fdisk -e /dev/disk2

Note: In the above command disk2 was used to identify the SD Card. You may need to use a different identifier.

Below is the output that should appear when executing the above command for your SD card.

fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Enter 'help' for information
fdisk: 1> fdisk:*1> Disk: /dev/disk2    geometry: 3891/255/63 [62521344 sectors]
Offset: 0   Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
 1: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
fdisk:*1>          Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
 1: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
Partition id ('0' to disable)  [0 - FF]: [0] (? for help) Do you wish to edit in CHS mode? [n] Partition offset [0 - 62521344]: [63] Partition size [1 - 62519296]: [62519296] fdisk:*1>          Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
Partition id ('0' to disable)  [0 - FF]: [0] (? for help) Do you wish to edit in CHS mode? [n] Partition offset [0 - 62521344]: [206848] Partition size [1 - 62314496]: [62314496] fdisk:*1> Writing current MBR to disk.

The first input command was erase, therefore the output above contains mostly zeroes. To see the results, you would need enter the command given below.

fdisk /dev/disk2

After entering the above command, you should see the output shown below.

Disk: /dev/disk2    geometry: 3891/255/63 [62521344 sectors]
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
 1: 0C 1023 254  63 - 1023 254  63 [      2048 -     204800] Win95 FAT32L
 2: 83 1023 254  63 - 1023 254  63 [    206848 -   62314496] Linux files*
 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused      

This raspberrypi.org website offers advice when certain error messages appear. I have repeated some of this advice below. You will need to replace diskN with the correct identifier.

  • If the command reports Resource busy, you need to unmount the drive first using the command given below.

    sudo diskutil unmountDisk /dev/diskN
  • If the command reports Operation not permitted you need to disable SIP before continuing.

    Note: I would strongly recommend disabling SIP as a last resort.

  • If the command reports Permission denied, the partition table of the SD card is being protected against being overwritten by macOS. Erase the SD card's partition table using this command:

    sudo diskutil partitionDisk /dev/diskN 1 MBR "Free Space" "%noformat%" 100%

    That command will also set the permissions on the device to allow writing.

IMO, I believe you should attempt to use Arch Linux instead of macOS. I tried installing the latest Arch Linux in a VirtualBox virtual machine. (VirtualBox is a a free product). However, I could not get the virtual machine to work with the builtin SD card reader on my iMac (21.5-inch, Late 2013). I had no better luck with an external USB SD card reader. Maybe I did not have the correct settings or maybe different hardware would make the difference. Also, I did not try using the sudo vboxmanage internalcommands createrawvmdk ... commands to expose the SD card to the virtual machine.

Instead of a virtual machine, I opted to try a live version of Arch Linux. Here, Arch Linux was able to access the external SD card reader, but not the internal reader. Live means you create a Arch Linux bootable USB flash drive. Once you boot from the flash drive, you can enter the commands to install Arch Linux on the SD card. The Arch Linux ISO file was name archlinux-2020.03.01-x86_64.iso and came from this website, although other mirrors can be found here.

The instructions for using macOS to create the bootable flash drive can be found here. An image taken from this website is shown below.

Note: My iMac has a wireless keyboard. Arch Linux failed to work with this keyboard. I had to resort to a wired keyboard.

I did hypothesize that your question came from a website such as this one. An image of the installation instructions is shown below.

In testing, I modified the above instructions so the downloaded file would be stored on the SD card. After installing this file can be deleted. To stored the file on the SD card, replace the commands given in step 5 with the commands shown below

cd root
wget http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-4-latest.tar.gz
cd ..
bsdtar -xpf root/ArchLinuxARM-rpi-4-latest.tar.gz -C root


  • I tried your advice and you were right about the archlinux website, since the code is a copy of that. I was able to avoid getting the permission denied message, but I got something else that is too long to post here. It was after I tried your modified version of the archlinux commands.
    – Dena
    Mar 3, 2020 at 5:34
  • Some of the reply on Terminal was this: fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory followed by this:fdisk: 1> fdisk:*1> Disk: /dev/disk2 geometry: 3891/255/63 [62521344 sectors] Offset: 0 Signature: 0xAA55 Then there was a table with zeros. This is becoming pretty frustrating since the guide made it seem like it was an easy thing to format the SD card and install a custom OS, even with little linux experience. Thank you for bearing with me.
    – Dena
    Mar 3, 2020 at 5:37
  • I did not post what you should have seen, because I would first need to know the exact size of your SD card. Fortunately, your above comment provided this information. I updated my answer to show the expected results. The zeroes occurred because the first input command was erase. The output shows the old values, but not the results after the new values are entered. I suppose another print command could been inserted before the quit command to show the results. The current MBR partition table values can also be displayed by entering the command fdisk /dev/disk2. Mar 3, 2020 at 9:30
  • Yes, that is what I got! Thank you
    – Dena
    Mar 3, 2020 at 11:27

On recent versions of macOS it is no longer enough to have root privileges in form of for example the sudo command, you've tested according to the comments. By default the user is protected from programs that could cause problems with the disk itself.

In order to get the correct permission, you have to do the following:

  1. From the Apple menu open "System Preferences"
  2. Choose "Security & Privacy"
  3. Select the "Privacy" tab
  4. In the left hand menu, select "Full Disk Access"
  5. Click the "lock" icon in the lower left-hand corner and enter your password
  6. Click the "plus" icon to add to the list
  7. Choose to add /Applications/Utilities/Terminal to the list

Now close your Terminal application and start it again. Now the Terminal has privileges to access full disks.

Then you can run your fdisk command again, remember to prefix it with sudo:

sudo fdisk [rest of the command]

NOTE: Always remember to check and double check that the disk you want to mess with is actually still /dev/disk2s1 so that you don't mess with the wrong disk.

EVEN BIGGER NOTE: It seems to me that the command you're trying to run is really for Linux. That command won't work with fdisk on macOS.

The fdisk command you have works by automating a number of key presses in the fdisks menus: "o p n p 1 +100M t c n p 2 w"

What it actually achieves is the following:

  • Creates an empty DOS partition table

  • Creates a new primary partition number 1 of 100 MB

  • Sets the system id of the new partition as "W95 FAT32 (LBA)"

  • Creates a new primary partition number 2 with the rest of the space

You can do the same with the macOS fdisk tool, or you could use the graphical DiskUtility to do the same. Note that what fdisk calls "DOS partition table" is referred to as "MBR" in Disk Utility.


DavidAnderson in the comments write that you're really following this guide for installing ArchLinux on a Raspberry Pi 4. I cannot know if that is correct or not - but I think it cannot be that specific guide, as your command that automates the fdisk commands is not in that guide. However, it does seem likely that you're trying to follow a similar guide to install ArchLinux on a Raspberry Pi.

If that is the case, I would advise you to either use a Linux computer for following the instructions, or if that is not available, then install VirtualBox or similar (VMware, Parallels, etc.) on your Mac and install ArchLinux here, so that you can follow the guide again.

  • The OP probably is supposed to be entering the commands in Arch Linux, where the user is by default the root user. There would be no reason to enter sudo. The command fdisk is interactive. An image of the interactive commands for macOS can be found here. When comparing to an image of the fdisk interactive commands found here for Arch Linux, you can see the differences. Therefore, the fdisk for macOS is not going to work when the OP uses the interactive commands intended for the Arch Linux version of fdisk. Mar 2, 2020 at 11:52
  • Yes, that is exactly what I wrote in my answer. I wrote it at the same time you added your comment above, but as I edited my answer several times, you cannot really see that in the time line.
    – jksoegaard
    Mar 2, 2020 at 11:59
  • There's nothing wrong with my answer as far as I can see. Even though "he is supposed" to be doing something in Arch Linux, there's nothing preventing him from doing so with macOS. I don't want to tell someone that they have to acquire a Linux computer or install Linux just to partition and format a disk, I would rather tell them that the same thing can be done with fdisk or DiskUtility on the Mac.
    – jksoegaard
    Mar 2, 2020 at 12:00
  • You sure seem to know a lot about what I'm doing... Ofcourse I haven't deliberately left out other errors. The OP hasn't written anywhere that they're following the guide you're linking to, so how would I know that they're following that guide. Still even if he is following that guide, the answer is still correct. He can just partition and format the SD card on his Mac - there's nothing wrong with that. You can certainly certainly create SD cards on a Mac that can be used to boot Raspberry Pi 4's - I have done that several times. Regarding the other steps in the guide that he's supposedly ...
    – jksoegaard
    Mar 2, 2020 at 13:35
  • following then you can surely format and mount FAT file systems on the Mac. He can also download and extract tar.gz files, and copy over boot files to the boot partition. For formatting and mounting an ext4 file system, he'll need to either use extFS from Paragon, or install e2fsprogs from HomeBrew to get mkfs.ext4, and then osxfuse for mounting afterwards. So all in all, it is doable from a Mac if he really wanted to do that.
    – jksoegaard
    Mar 2, 2020 at 13:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .