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.
- Restart macOS, press Command+R to go to macOS utilities window.
- Click menu item Utilities —> Terminal at top menu bar.
- Then input command
csrutil disable
in the popup terminal window. This command will disable the System Integrity Protection. - Click Mac Logo —> Restart menu item at the top left corner to restart the macOS.
- After restart macOS, run the command
sudo mount -uw /
.$ sudo mount -uw / Password:
- Now you can create a directory successfully with the command
mkdir
. - 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.
- 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 / Password:
3. Question & Answer.
3.1 Python script meets read-only file system error on macOS.
- In my python script, I want to use the python
os
module’ssystem
function to execute a zip command to make a zip file like below.os.system('zip target-file.zip /usr/local/abc.py')
But when I run the python script, it shows a permission denied error like below.
>>> import os >>> >>> os.getcwd() '/usr/local' >>> >>> os.system('zip target-file.zip /usr/local/abc.py') zip I/O error: Permission denied zip error: Could not create output file (target-file.zip) 3840
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. - 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.
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.