Terminal command ln generates error: Read-only file system [closed]
I'm trying to create a symlink to a file in order to enable Docker CLI completion, following these instructions.
https://docs.docker.com/desktop/mac/#zsh
> etc=/Applications/Docker.app/Contents/Resources/etc
> ln -s $etc/docker.zsh-completion /usr/share/zsh/site-functions/_docker
ln: /usr/share/zsh/site-functions/_docker: Read-only file system
I've tried sudo
. It's macOS Monterey. I'm new to Mac and old to PC. It seems that Zsh on my machine is in a strange directory, i.e. not in /usr/local/
.
The new protection system was originally preventing me from making my link giving Operation not permitted
error but I disabled the protection using csrutil
from Recovery Mode and I now get this new error.
- Have I now hit a second protection system?
- Can I turn this second one off, too??
- Is there an end of level boss?
- Else, how can I get Zsh installed in the directory that isn't locked?
- How do I prevent other stuff installing into the 'wrong' directory?
Solution 1:
Modern Macs split the disk it two volumes (a "volume" is similar to a partition, but different in several ways). By default the volumes are named Macintosh HD
and Macintosh HD - Data
.
The way disks/volumes/partitions/etc work on Mac OS or any UNIX system is you "mount" the volume to a path in the filesystem. Macintosh HD
is "mounted" at the path /
. And Macintosh HD - Data
is mounted at the path /System/Volumes/Data
.
The Macintosh HD
(or /
) volume is mounted as read only and it can only be modified while installing an operating system update. There's no sudo or privilege escalation - think of it as a CD-ROM (with a few exceptions).
It gets a little bit messy, for example /Applications
exists both at that path and at /System/Volumes/Data/Applications
. The latter is the real path, the former is a convenience and also exists for backwards compatibility.
Most of this is invisible with ordinary usage of a Mac, but you can bump into it while working in the command line.
How do I prevent other stuff installing into the 'wrong' directory?
Because /
is read only, nothing can be installed there, so you're all good. :-) Everything you install will be under /System/Volumes/Data
or a path that points to that.
Solution 2:
The instructions you're using are for zsh
installations made by Homebrew - not the zsh
installation that comes with macOS. This is why the paths are different. You can install zsh
from Homebrew and then the instructions will be valid.
And yes, in some sense you have hit another "protection system", if you want to call it that. The file system you're trying to modify is simply mounted read-only, meaning that it cannot be modified. It is possible to get read-write accesss to these files and make modifications - however I would strongly discourage you from doing so. It is almost certain to give you more problems in the long run.