EDIT: After more testing, it appears the ONLY change needed is to add the "D" for Data flag to the APFS volume. /etc/fstab changes are not needed.
I've changed the text below to show this.
I got this to work on APFS volumes in macos Catalina 10.15.2 - I can't confirm if this works on earlier versions. This also does not apply to HFS as far as I know.
Suppose your volume name is TestVolume, and the device path is /dev/disk2s4. You can get both of these from the output of
The device path is /dev/[IDENTIFIER].
You need to modify the apfs volume meta-data flags for this volume. I found I had to add the "D" flag for which stands for "Data". Without this flag, the volume is still mounted automatically on boot even with the correct fstab line added.
diskutil apfs changeVolumeRole /dev/disk2s4 D
Again, change /dev/disk2s4 to YOUR volume. After doing both of these things, the volume no longer attempts to mount itself. You will have to use Disk Utility to mount the volume or the command line.
You can confirm that the metadata flag has been set by typing:
diskutil apfs list
You're looking for the line that says:
APFS Volume Disk (Role): disk2s4 (Data)