Created
January 1, 2024 21:24
-
-
Save zcshiner/7216ef77910cfe4e420274fbfbe4f431 to your computer and use it in GitHub Desktop.
Mount APFS volumes as read only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage | |
# mountAPFSreadOnly device | |
# Example | |
# mountAPFSreadOnly /dev/disk8s1 | |
# inspiration via: https://forums.macrumors.com/threads/how-to-mount-an-external-drive-apfs-as-read-only.2241919/post-28578009 | |
#require sudo | |
if [ "$(whoami)" != "root" ] ; then | |
echo "Run this script with sudo" >&2 | |
exit 1 | |
fi | |
# stdout is hidden on some commands to make the output make more sense | |
diskutil unmount $1 > /dev/null | |
echo "Volume passphrase needed" | |
diskutil apfs unlockVolume $1 -nomount > /dev/null | |
diskutil mount readOnly $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment