13

macOS Big Sur 解决系统文件不可修改

 2 years ago
source link: https://shockerli.net/post/macos-big-sur-mod-sys-file/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

macOS Big Sur 解决系统文件不可修改

2022-04-09 约 698 字 预计阅读 2 分钟

本是为了删除 macOS 11.4 自带的 PHP,经历了一下步骤:

  • 先关闭 SIP
csrutil disable
  • 再删除 PHP 相关文件
cd /private/etc/ && sudo rm -rf php-fpm.conf.defaultphp.ini php.ini.default

cd /usr/bin/ && sudo rm -rf php php-config phpdoc phpize

cd /usr/include && sudo rm -rf php  // 10.14之后没有此目录

cd /usr/lib && sudo rm -rf php

cd /usr/sbin && sudo rm -rf php-fpm

cd /usr/share && sudo rm -rf php

cd /usr/share/man/man1 && sudo rm -rf php-config.1 php.1 phpize.1

cd /usr/share/man/man8 && sudo rm -rf php-fpm.8
  • 却报错文件只读
rm: php: Read-only file system
  • 按老办法挂载分区
sudo mount -uw /
  • 却又报错分卷被保护,无法挂载
mount_apfs: volume could not be mounted: Permission denied
mount: / failed with 66
  • macOS Big Sur 11.4

将系统分区重新挂载在一个有读写权限的新目录下,在该目录下修改系统文件,生成快照并重启。

关闭 SIP

关机,再开机,并按住 Command+R 进入恢复模式,然后在 实用工具 - 终端 中运行:

csrutil disable
csrutil authenticated-root disable
sudo reboot

重新开机后,查看是否关闭,显示 disable 则表示已关闭:

# csrutil status
System Integrity Protection status: unknown (Custom Configuration).

Configuration:
	Apple Internal: disabled
	Kext Signing: disabled
	Filesystem Protections: disabled
	Debugging Restrictions: disabled
	DTrace Restrictions: disabled
	NVRAM Protections: disabled
	BaseSystem Verification: enabled

This is an unsupported configuration, likely to break in the future and leave your machine in an unknown state.


# authenticated-root status
Authenticated Root status: disabled

查看系统分区

# mount
/dev/disk1s1s1 on / (apfs, sealed, local, read-only, journaled)
devfs on /dev (devfs, local, nobrowse)
/dev/disk1s4 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)
/dev/disk1s2 on /System/Volumes/Preboot (apfs, local, journaled, nobrowse)
/dev/disk1s6 on /System/Volumes/Update (apfs, local, journaled, nobrowse)
/dev/disk1s5 on /System/Volumes/Data (apfs, local, journaled, nobrowse)
map auto_home on /System/Volumes/Data/home (autofs, automounted, nobrowse)

本机的系统分区为 /dev/disk1s1disk1s1s1 是其快照,挂载的是根目录 /

在用户目录下创建一个新目录,如 /Users/jioby/mount-data

将系统分区挂载到该新目录:

sudo mount -o nobrowse -t apfs /dev/disk1s1 /Users/jioby/mount-data

(注意是 disk1s1,而非 disk1s1s1

访问并修改文件

此时,mount-data 目录相当于系统的根目录,并可对其进行访问和修改。

比如原来需要删除 /usr/bin/php 文件,则直接删除 /Users/jioby/mount-data/usr/bin/php 即可。

生成快照并重启

操作完对应的系统文件后,生成快照并重启系统,然后系统文件就被修改了。

sudo bless --folder /Users/jioby/mount-data/System/Library/CoreServices --bootefi --create-snapshot

sudo reboot

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK