Skip to content

Instantly share code, notes, and snippets.

@hazzik
Forked from zhylmzr/mount_ntfs_3g.plist
Last active February 6, 2022 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hazzik/e6fd032fd08e2273747c89215918e070 to your computer and use it in GitHub Desktop.
Save hazzik/e6fd032fd08e2273747c89215918e070 to your computer and use it in GitHub Desktop.
automount all ntfs volume writable in macOS Big Sur+

Prepare

Disable SIP first, download and Install macFUSE from https://osxfuse.github.io/, then do the following

brew tap gromgit/homebrew-fuse
brew install ntfs-3g-mac

Install

Download ntfs and mount_ntfs_3g.plist and then

chmod +x ntfs
sudo chown root:wheel ntfs
cp ntfs /usr/local/bin/ntfs

Set up to run automatically

chmod 600 mount_ntfs_3g.plist
chown root:wheel mount_ntfs_3g.plist
sudo cp mount_ntfs_3g.plist /Library/LaunchDaemons/
sudo launchctl load /Library/LaunchDaemons/mount_ntfs_3g.plist

Enjoy and you can also enable SIP now.

Q&A

Why is the script delayed by 3s?

Avoid the system's automount from overwriting our writable mount.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>mount_ntfs_3g</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/usr/local/bin/ntfs</string>
<string>--delay</string>
<string>3</string>
</array>
</dict>
</plist>
#!/bin/sh
main() {
local raw="$(mount | grep '^/dev' | grep 'ntfs' | sort)"
local line=(${raw// /|})
for i in ${!line[@]}; do
local l=(${line[i]//|/ })
local dev=${l[0]}
local vol=${l[2]}
mount2 $dev $vol
done
}
mount2() {
local dev=$1
local volume=$2
local volname=$(diskutil info $dev | grep 'Volume Name' | awk -F':' '{print $2}' | xargs)
echo "mount $dev to $volume, label $volname"
umount $dev
/usr/local/bin/ntfs-3g -o volname="${volname}" -o auto_xattr -o auto_cache -o allow_other -o local -o hide_hid_files $dev $volume
}
if [ "$1" == '--delay' ]; then
sleep "$2"
fi
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment