無法創建目錄
最近小伙伴經常反饋Mac根目錄下創建文件或目錄一直失敗,並且嘗試了各種姿勢。 常見錯誤如下:
# 常見錯誤1, 直接創建目錄
mkdir -p /test
mkdir: /data: Read-only file system
# 常見錯誤2。 進入安全模式,關閉authenticated-root和SIP后,重新掛載根分區
sudo mount -uw /
mount_apfs: volume could not be mounted: Permission denied
mount: / failed with 66
解決方法
尤其是MacOS升級到Mac Big Sur版本后,關閉SIP重新掛載根分區也是行不通的。
解決方案示例:
# 創建可用目錄(不在根目錄下),如
mkdir -p ~/test #我本地目錄為/Users/hxy/test
# 增加關聯
sudo vi /etc/synthetic.conf
內容:
test /Users/hxy/test # 注意,這里test前面沒有/; 並且test與后面內容使用tab分割
# 重啟系統
sudo reboot
# 重啟后,系統會在根目錄/下創建test目錄,如下:(這里是一種軟連接方式)
➜ ~ ll /test
lrwxr-xr-x 1 root wheel 34B 2 20 17:31 /test -> /Users/hxy/test
➜ ~
-----------完美的分割線----------------