๐Ÿคฏ Unmount volume on launch


1 min read

So here is my setup, I have 2 volumes (macOS Monterey and macOS Ventura), and my goal is to have just the required volume for each macOS


So when launching macOS Monterey I just want the macOS Ventura volume unmounted.

1) Using diskutil it's very easy to force unmount a volume.

diskutil unmountDisk force /Volumes/macOS\ Ventura

2) Let's create a Launch Agent plist file at $HOME/Library/LaunchAgents and we will call it com.ruiaureliano.unmount.plist.

<?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">

        <true />






4) Let's create the .unmount-disk.sh that will be executed on launch, it should be placed on WorkingDirectory that we defined on the list, in my case /Users/ruiaureliano/.unmount-disk.sh

echo "macOS ventura unmount"
/usr/sbin/diskutil unmountDisk force /Volumes/macOS\ Ventura

3) Now we just load the plist file using launchctl tool.

 launchctl load $HOME/Library/LaunchAgents/com.ruiaureliano.unmount.plist

If we need to unload

 launchctl unload $HOME/Library/LaunchAgents/com.ruiaureliano.unmount.plist

Restart your Mac and voila ๐Ÿง™โ€โ™‚๏ธ๐Ÿง™โ€โ™‚๏ธ๐Ÿง™โ€โ™‚๏ธ