After MacOS was upgraded to Big Sur, I found that the file could not be written to the disk using the os module of Python3. It will be reported OSError: [Errno 30] Read-only file system
error.
1. Analysis error
Since there is an error, we will analyze the error!
After understanding, after Mac OS 10.11, Apple introduced a kernel protection measure SIP
(System Integrity Protection), also known as the Rootless mode mechanism , in order to improve the security of the system environment .
In SIP
case the mechanism, the system will default lock /system
, /sbin
, /usr
three directories, even if the switch to the root
user can only see, can not perform other operations.
SIP
It can effectively prevent malicious programs from damaging the computer, so it is recommended to keep it turned on.
For more detailed understanding, please check https://eclecticlight.co/2020/06/25/big-surs-signed-system-volume-added-security-protection .
Solve the problem
Then understand the problem, to address the issue, since it is SIP
a result of that we have from the SIP
start.
View SIP
status.
MacBook:~ zhangyi$ csrutil status
System Integrity Protection status: open.
Found SIP
in the open state, it will be SIP
disabled.
MacBook:~ zhangyi$ csrutil disable
csrutil: This tool needs to be executed from Recovery OS.
When I entered the command, I found that this command can only be executed in recovery mode.
。。。
What about entering Apple's recovery mode?
First, restart the computer, the Apple icon dark, while holding down Command+R
into recovery mode.
Enter the recovery page, open the terminal.
[Top Menu Bar] -> [Utilities] -> [Open Terminal]
and execute the disable command.
csrutil disable
Finally, restart it.
reboot
This general to step on it, if you want to reopen SIP
also need to be performed in recovery mode.
csrutil enable
If you don't solve it, remember to try this command.
sudo mount -uw /
Mount the root directory.
However, there may be an error due to insufficient permissions:
mount_apfs: volume could not be mounted: Permission denied
mount: / failed with 66
mount_apfs: volume could not be mounted: Operation not permitted
mount: / failed with 77