45

If fstab is deprecated in Lion (and before, I think?) how does one, properly, prevent a partition from mounting on system boot?

This is loosely related to this question which as of this post has no answer.

Edit:

So my confusion comes from reading about fstab and being told to edit /etc/fstab.hd. So.../etc/fstab is what I need to create and where I add UUID info to prevent partitions from mounting?

$ cat /etc/fstab.hd 
IGNORE THIS FILE.
This file does nothing, contains no useful data, and might go away in
future releases.  Do not depend on this file or its contents.
Meltemi
  • 6,807
  • 11
  • 30
  • 30
  • [There is a script for that](http://sourceforge.net/projects/native-ntfs-osx/files/) ([posted on apple forum by author](https://discussions.apple.com/thread/5544031)) - simple to use, tested working with 10.9 and 10.9.1. – Dmitry Verkhoturov Feb 14 '14 at 04:02
  • The accepted answer questions the assumption that fstab is deprecated. Should we edit the question accordingly? – D A Vincent Mar 31 '16 at 07:45

3 Answers3

33

Neither man fstab nor man diskarbitrationd (see here for example) mention deprecation of /etc/fstab.

It's not there by default, but why should it be, if it just were empty because the defaults are good? It's there if you need it.


Claims of deprecation of fstab has been floating around the web for some time now.

From here:

etc/fstab is deprecated in Leopard

From here:

I was going to suggest editing the /etc/fstab file, but apparently that was deprecated in Leopard, and is probably now removed from Snow Leopard...

Apart from the fact that there is no mention of deprecation in its documentation, why would Apple add utilities for properly editing deprecated configuration files?

Quoting man vifs:

NAME
     vifs -- safely edit fstab
[...]
HISTORY
     The vifs utility originates from Mac OSX 10.5.

While the following program runs (infinite loop, Ctrl-C to quit), no disk will be mounted, with proper conditions you can control it more fine-grained of course:

#include <CoreFoundation/CoreFoundation.h>
#include <DiskArbitration/DiskArbitration.h>

DADissenterRef BlockMount(DADiskRef disk, void *context)
{
        DADissenterRef dissenter = DADissenterCreate(kCFAllocatorDefault, kDAReturnNotPermitted, CFSTR("forbidden!"));
        return dissenter;
}

int main (int argc, const char * argv[])
{
    DAApprovalSessionRef session = DAApprovalSessionCreate (kCFAllocatorDefault);
    if (!session)
    {
        fprintf(stderr, "failed to create Disk Arbitration session");
    }
        else
        {
        DARegisterDiskMountApprovalCallback(session, NULL, BlockMount, NULL);
        DAApprovalSessionScheduleWithRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

        while (true) {
            CFRunLoopRunInMode(kCFRunLoopDefaultMode, 60 /* seconds */, false);
        }

        DAApprovalSessionUnscheduleFromRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
        DAUnregisterApprovalCallback(session, BlockMount, NULL);
        CFRelease(session);
    }
    return 0;
}

Save as main.c and compile using the following (you need Developer Tools):

cc main.c -o mountstopd -framework Foundation -framework DiskArbitration
Daniel Beck
  • 109,300
  • 14
  • 287
  • 334
  • It's similar with `cron`. No deprecation, just not used by default. There's a difference. – Daniel Beck Sep 16 '11 at 18:07
  • I'm intentionally not answering the part that's a duplicate of the referenced question. – Daniel Beck Sep 16 '11 at 18:07
  • maybe I'm confused, well, obviously! see **edit** above. what's difference between `/etc/fstab` and /etc/fstab.hd`? perhaps this will clear up my confusion. – Meltemi Sep 16 '11 at 19:07
  • 1
    @Meltemi: It's an entirely different file and unrelated. See for example [here](http://hintsforums.macworld.com/archive/index.php/t-62139.html) or [here](http://adam.merrifield.ca/2009/02/12/keeping-unused-hard-disks-unmounted/). – Daniel Beck Sep 16 '11 at 19:27
  • ic. i've got it working with `/etc/fstab` just fine now. thx – Meltemi Sep 16 '11 at 22:33
  • In my case `vifs` wouldn't run and show an error because `EDITOR` was not set for the root user, so it needs it to be defined for root, for example with `sudo su; export EDITOR=vim; vifs` (or `export EDITOR=nano` if that's your favorite). – ccpizza Sep 12 '15 at 10:55
  • This answer by Daniel Beck was totally unhelpful. It's a proof of why that .hd file is not used, but the answer doesn't solve something the user is trying to achieve. The user is clearly trying to find /etc/fstab, as proven by his comment. vifs is the intermediate tool to interface with /etc/fstab. – macetw Nov 18 '16 at 13:42
  • @macetw Not sure what you're referring to. The first half of this answer provides evidence to `/etc/fstab`'s continued relevance (including a reference to the then recently introduced `vifs`), and a reasonable guess why it doesn't exist out of the box (*it would be empty*) -- I just didn't copy whatever guides already exist for how to use it, as that wasn't the question. And the second half of this answer provides a different solution, if you, for whatever reason, still don't want to use it. What would you expect an answer for the question as stated should have said? – Daniel Beck Nov 19 '16 at 14:49
21

There is no need to run programs or worry about where fstab is located.

Just run sudo vifs and add the appropriate lines to the file. Mine is:-

#
# Warning - this file should only be modified with vifs(8)
#
# Failure to do so is unsupported and may be destructive.
#
UUID=E00F307A-9295-482E-8A79-2FA2C922F3CD none ntfs rw,noauto
LABEL=Tempy none ntfs rw,noauto

Make sure you know how to modify and save a file in vim. Vimtutor will teach you the basics.

PS /private/etc is actually the same as /etc. OS X processes the url internally (this is explained in API documentation - although I still don't understand why)

Milliways
  • 532
  • 1
  • 5
  • 12
  • If you're using a third-part driver such as Paragon NTFS, this technique may not work without modification. For example, I had to use a Label (UUIDs wouldn't work) and the filesystem type had to be ufsd_NTFS instead. It didn't break anything if the more standard options were used, it just didn't work. – Zxaos Sep 10 '13 at 15:35
  • It didn't work for `fat32`! I tried both `UUID` and `LABEL` as well. – Necktwi Jan 18 '17 at 03:05
3

Since I have same problem, and haven't found any resonable solution for this, I've wrote little launch daemon service that prevents mounting of volumes with specified labels.

Here it is: https://github.com/nanoant/mountblockd

Adaś
  • 131
  • 1
  • 1
    Adaś, in mountblockd, the plist says to enter volume name. But I have two volumes with the same name. Can the plist take UUID instead? – Edward Ned Harvey Dec 19 '14 at 14:48