macOS - creating folder in the root
If we try to create a folder in the root of ‘Machintosh HD’ with this command
mkdir /secrets
it will give an error
mkdir: /secrets: Read-only file system
This is because, the primary volume is read-only. This means it is not immediately possible to create new folders here.
In order to get around that, the system provides what is known as synthetic firm links
. This allows us to create what appears to be folders at the root of the file system.
You need to create the file /etc/synthetic.conf
, which should be owned by root and group wheel with permissions 0644
.
The contents of the file should look like this:
newfolder Users/my-username/a-custom-folder-name
NOTE:
- It is important to ensure that the space between the two folder names is a TAB character, and not just a number of space.
- The name of the actual folder doesn’t have to exactly match the name of the synthetic folder
// To make modifications to the file
sudo chmod 0666 /etc/synthetic.conf
// After making changes, lock it down
sudo chmod 0644 /etc/synthetic.conf
// The file should be owned by root and group wheel
sudo chown root:wheel /etc/synthetic.conf
newfolder
is the name of the virtual folder that will be created in the root of the file system. Users/my-username/a-custom-folder-name
is the actual location of the folder. The actual location doesn’t need to be inside Users, but can be anywhere in the system.
After creating the file above with the specified contents, you need to reboot the system. After rebooting, you’ll see the /newfolder folder.
Reference
https://apple.stackexchange.com/questions/388236/unable-to-create-folder-in-root-of-macintosh-hd