How To Fix Read-Only File System Error When Run Mkdir Command On MacOS

When I run command mkdir in mac os to create a folder, it gives me an error message mkdir: /data: Read-only file system like below. This article will tell you how to fix it.

sh-3.2# mkdir /data
mkdir: /data: Read-only file system

1. Fix MacOS Read-Only File System Error Steps.

  1. Restart macOS, press Command+R to go to macOS utilities window.
  2. Click menu item Utilities —> Terminal at top menu bar.
  3. Then input command csrutil disable in the popup terminal window. This command will disable the System Integrity Protection.
  4. Click Mac Logo —> Restart menu item at the top left corner to restart the macOS.
  5.  After restart macOS, run the command sudo mount -uw /.
    $ sudo mount -uw /
  6. Now you can create a directory successfully with the command mkdir.
  7. If you want to check whether System Integrity Protection is enabled or disabled, you can run command csrutil status in a terminal.
    # csrutil status
    System Integrity Protection status: disabled.
  8. If you want to enable System Integrity Protection, you can restart the macOS and press Command + R to go to the macOS utilities window again to enable it with command csrutil enable in terminal.

2. Resolve Read-only File System Error When Remove Files.

Now we can create a directory in the macOS system. But when I want to remove files, it also shows me below error messages.

# rm -rf /data/db
rm: /data/db/journal/WiredTigerPreplog.0000000002: Read-only file system
rm: /data/db/journal/WiredTigerLog.0000000001: Read-only file system
rm: /data/db/journal/WiredTigerPreplog.0000000001: Read-only file system

To fix this issue, you should run command sudo mount -uw /, after that, you can remove files as you want.

$ sudo mount -uw /

3. Question & Answer.

3.1 Python script meets read-only file system error on macOS.

  1. In my python script, I want to use the python os module’s system function to execute a zip command to make a zip file like below.
    os.system('zip /usr/local/')

    But when I run the python script, it shows a permission denied error like below.

    >>> import os
    >>> os.getcwd()
    >>> os.system('zip /usr/local/')
    zip I/O error: Permission denied
    zip error: Could not create output file (

    I have run the command csrutil disable to disable the System Integrity Protection on my macOS, but it still throws the error when I run the python script.

  2. You can try the below steps.1. Run the command fsck -n -f in a macOS terminal. 2. Reboot your macOS. 3. Run the python script file with the root permission.

1 thought on “How To Fix Read-Only File System Error When Run Mkdir Command On MacOS”

  1. Is the above still applicable with recent versions of mac OS (Catalina forward) as I am thinking that the encrypted System volume will still prevent modifications.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.