Jump to content

[How To] Auto-Mount only selected partitions. Two Methods


28 posts in this topic

Recommended Posts

Method 1:

This method involves utilizing the File System Table (fstab) for the BSD subsytem.

 

First you need to know the mount points of the partitons you don't want to see. I'll use "winxp" and "backup" for the examples. If you didn't know, the partition on which OS X resides is mounted to / (root), and all subsequent partitons are mounted to /Volumes/. You can find the mount point of any given partiton using disk utility, selecting the partiton and hit the info button up top. I have 2 drives. One with 2 partitions and one with 3 partitions. The primary drive has my OSX partition and one for winxp. The second drive has a documents partition, and media partition, and a backup partition. For day to day use in OS X I don't want to see the winxp nor the backup partions. From disk utility, I find their mount points are /Volumes/winxp and /Volumes/backup respectivley.

 

The first thing we need to do is to crate the fstab file in the /etc folder. Open up a Terminal and:

sudo nano /etc/fstab

 

now we need to edit to suit our needs. The typical entry line in fstab contains on line for each mount, with the data in the format :

file system mount-point type options

So to tell it to not mount a specific drive or partition, we just need to specify not to do so.

 

LABEL=winxp none ntfs ro,noauto
LABEL=backup none HFS+ ro,noauto

 

In the example,

"LABEL=winxp" is my windows partition, "none" is the mount point, "ntfs" is the type, and "ro,noauto" are the options.

 

You must use the appropriate type for the partiton, ie: ntfs HFS HFS+ msdos etc.

 

The options "ro,noauto" mean read only, don't auto mount. For read / write of supported file systems use rw.

 

If your partition name has a space on the name, you need to replace the space with "\040" ie. "LABEL=Win\040XP" for Win XP.

 

Once you have the code entered, hit cntrl-x and it will ask if you want to save. Hit y for yes, and it'll ask if you want to save it as fstab. Hit enter.

 

Now just restart, and the drives won't auto-mount.

 

Method 2:

 

Technically, this method will not enable you to pick which partitions to auto-mount. It will have the desired effect though, as it will auto-unmount selected partitions at login.

 

The proceedure is rather simple in that you just add a short login script to unmount the partitions you don't want to see.

 

Once again you need to know the mount points of the partitons you don't want to see. I'll use "winxp" and "backup" for the examples. If you didn't know, the partition on which OS X resides is mounted to / (root), and all subsequent partitons are mounted to /Volumes/. You can find the mount point of any given partiton using disk utility, selecting the partiton and hit the info button up top. I have 2 drives. One with 2 partitions and one with 3 partitions. The primary drive has my OSX partition and one for winxp. The second drive has a documents partition, and media partition, and a backup partition. For day to day use in OS X I don't want to see the winxp nor the backup partions. From disk utility, I find their mount points are /Volumes/winxp and /Volumes/backup respectivley.

 

Now that we know the mount points it's time to make the script. I also made a directory to store scripts in.

 

Open terminal (Applications/Utilities/Terminal)

 

I made a folder in /Library called Management to store the script in:

 

sudo mkdir /Library/Management

 

The sudo command makes you the super user (*nix) / administrator, and grants you full access, and you will need to enter your password.

 

To create the script :

sudo nano /Library/Management/login.sh

 

nano is a command line (terminal) text editor, and the command above will create and open "login.sh" in the /Library/Management folder.

 

The script itself needs just a few basics

 

#!/bin/bash

umount /Volumes/winxp

umount /Volumes/backup

exit 0

 

The first line tells the computer to use the bash shell, and it's an exclamtion point ! not a 1

 

you need one "umount" line for each partition you want to unmount. The command is "umount" only one n.

 

exit 0 tells the computer to exit the script with a 0 status.

 

Once you have the code entered, hit cntrl-x and it will ask if you want to save. Hit y for yes, and it'll ask if you want to save it as login.sh. Hit enter.

 

 

Now you need to ensure that the script has the proper permissions and is executable.

 

In Terminal :

sudo chmod u+x /Library/Management/login.sh

 

Now add the script to run at login.

 

In Terminal

sudo defaults write com.apple.loginwindow LoginHook /Library/Management/login.sh

 

Close the terminal, logout and back in and the drives should be gone.

 

 

If for some reason you want to mount a drive you have umounted using this script, simply edit the login script and insert a " # " at the begining of the line for that drive.

 

Example:

#!/bin/bash

umount /Volumes/winxp

#umount /Volumes/backup

exit 0

 

If for some reason down the line you wish to remove the login script alltogether, then;

sudo defaults delete com.apple.loginwindow LoginHook.

Link to comment
Share on other sites

WOW! I couldn't have explained it better myself. Thanks for posting and i hope this thread clears a lot of the questions conserning unwanted drives showing up on the Desktop.

 

Thank you,

D~

Link to comment
Share on other sites

I was very interested with your method, since I don't like having my Windows' disks on the desktop.

 

But I discovered it's not working correctly.

 

The Finder doesn't show the disks, but the system considers them sort of mounted.

 

If you go to the /Volumes folder (By Terminal or by Finder) the disks are defined (sort of) unusable of course and empty.

 

If you try to mount them with DiskUtility, you can't, they are considered mounted, seen as folders. (And you can't unmount them)

 

So I went searching for a better way and I finaly found it, you can use DiskUtility as usual and they do not exist in /Volumes.

 

You must use in fact the fstab way.

 

In /etc create a file (with nano, pico...) called fstab, (sudo nano fstab) and type something like I did.

 

LABEL=WINDOWS\040XP none msdos ro,noauto
LABEL=DATA none msdos ro,noauto

 

In my case I have two disks WINDOWS XP and DATA and I prepare to mount them read only.

If you want them to be writable use rw instead of ro.

 

They are both FAT 32, if you need NTFS replace msdos with ntfs.

 

The \040 must be used to replace a space.

 

Another thing, you must not with the LABEL method use two disk with the same name.

 

To stop using the script you created, in Terminal type sudo defaults delete com.apple.loginwindow LoginHook.

 

Thanks for pushing me to find a solution to my problem (and yours). :(

:blink:

Link to comment
Share on other sites

Yea, volume names with spaces tend to be a problem :). How well is the rw support? I don't think I can muster up the currage to switch wr enabled.

 

edit: and have you tried mounting ext paritions with fstab?

Link to comment
Share on other sites

FrDakota. Thanks for the input on the fstab method. It is indeed a more appropriate method, and I'll add it to the [How To] with your permission. I'm keeping the script method posted as it is more of a login scripting how-to. I was unsure of the status of fstab in OS X as it seemed depreciated to me.

Link to comment
Share on other sites

Yea, volume names with spaces tend to be a problem :D. How well is the rw support? I don't think I can muster up the currage to switch wr enabled.

 

edit: and have you tried mounting ext paritions with fstab?

 

R/W mode is on by default with FAT volumes and it works perfectly. NTFS is always R/O.

 

Ext volumes are not working on OS X, you need a kernel extension to do that.

 

I found Mac OS X Ext2 Filesystem on SourceForge.

 

I tried it and it sees my Ext3 partition, but trying to mount it gave me an error and I didn't want to try fixing it since I have my Windows partitions on the same disk. I don't want to risk havoc. :D

 

Besides that, apparently a NTFS Read/Write driver will be included in MacOS X Leopard, says it's developper.

 

 

FrDakota. Thanks for the input on the fstab method. It is indeed a more appropriate method, and I'll add it to the [How To] with your permission. I'm keeping the script method posted as it is more of a login scripting how-to. I was unsure of the status of fstab in OS X as it seemed depreciated to me.

 

You have my agreement. :blink:

Link to comment
Share on other sites

Ext volumes are not working on OS X, you need a kernel extension to do that.

 

I found Mac OS X Ext2 Filesystem on SourceForge.

 

I tried it and it sees my Ext3 partition, but trying to mount it gave me an error and I didn't want to try fixing it since I have my Windows partitions on the same disk. I don't want to risk havoc. :D

Yea, that driver, actually 2 versions of it. the one you want is the "b" version. It still had difficulties with mounting ext partitions using the coa gui. If it's possible to auto mount the ext drive in fstab and use the driver strictly for r/w operations, that might work... I hope....

 

I'll go into linux and create a small 50mb ext partition and try to mount it using OS X fstab. Might take me a few days since i got something more urgent to do.

Link to comment
Share on other sites

Not worked for me, I first created the file "fstab" with

sudo nano fstab

then I tried several time with something like this

LABEL=winxp none msdos ro,noauto
LABEL=winxp /Volumes/winxp msdos ro,noauto
LABEL=winxp none msdos rw,noauto
LABEL=winxp /Volumes/winxp msdos rw,noauto

none of them worked, is anything go wrong ?

Link to comment
Share on other sites

Vernice, pardon me for a stupid question, (maybe) have you created the fstab file in the /etc folder ? (If not it won't work)

 

Is your hard disk you want not to mount called Winxp ?

 

And do not mismatch types, if your hard disk is ntfs do not give msdos and vice versa.

 

Also you don't need to give a mount point, OS X will do it just for you when you mount manually with Disk Utility.

Link to comment
Share on other sites

  • 2 months later...
  • 5 months later...

Well, I make it work with another method.

 

My FAT32 shared data partition is on 6th partition

(I'm a happy triplebooter ^_^ )

 

Just mounting it with a command on /etc/rc file

hard unix style, I´m afraid

 

Enter on the console and

 

mkdir /Data

sudo nano /etc/rc

And then edit, on this point

 

echo "Mounting local filesystems"

mount -uw /

[ -f /etc/fstab ] && mount -vat nonfs

##Here we write

mount -t msdos /dev/disk0s6 /Data

 

And then

 

ln -s /Data Data

 

Reboot and its done !!

 

 

:) SkArLoKO

Link to comment
Share on other sites

  • 6 months later...
Method 1:

This method involves utilizing the File System Table (fstab) for the BSD subsytem.

 

First you need to know the mount points of the partitons you don't want to see. I'll use "winxp" and "backup" for the examples. If you didn't know, the partition on which OS X resides is mounted to / (root), and all subsequent partitons are mounted to /Volumes/. You can find the mount point of any given partiton using disk utility, selecting the partiton and hit the info button up top. I have 2 drives. One with 2 partitions and one with 3 partitions. The primary drive has my OSX partition and one for winxp. The second drive has a documents partition, and media partition, and a backup partition. For day to day use in OS X I don't want to see the winxp nor the backup partions. From disk utility, I find their mount points are /Volumes/winxp and /Volumes/backup respectivley.

 

The first thing we need to do is to crate the fstab file in the /etc folder. Open up a Terminal and:

sudo nano /etc/fstab

 

now we need to edit to suit our needs. The typical entry line in fstab contains on line for each mount, with the data in the format :

file system mount-point type options

So to tell it to not mount a specific drive or partition, we just need to specify not to do so.

 

LABEL=winxp none ntfs ro,noauto
 LABEL=backup none HFS+ ro,noauto

 

In the example,

"LABEL=winxp" is my windows partition, "none" is the mount point, "ntfs" is the type, and "ro,noauto" are the options.

 

You must use the appropriate type for the partiton, ie: ntfs HFS HFS+ msdos etc.

 

The options "ro,noauto" mean read only, don't auto mount. For read / write of supported file systems use rw.

 

If your partition name has a space on the name, you need to replace the space with "40" ie. "LABEL=Win40XP" for Win XP.

 

Once you have the code entered, hit cntrl-x and it will ask if you want to save. Hit y for yes, and it'll ask if you want to save it as fstab. Hit enter.

 

Now just restart, and the drives won't auto-mount.

 

A revision to your process for some people.

 

When putting the information into the fstab file, the hfs+ line above would not work for me.

 

This worked after some trial and error.

 

LABEL=Local40Disk none ntfs ro,noauto

LABEL=Test none hfs ro,noauto 0 0

LABEL=Leopard none hfs ro,noauto 0 0

 

The first line is the same as above, it is a windows Local Disk partition on a separate SATA HDD.

The second line is the 3rd partition on the same HDD as my OSX86 Tiger install. It is hfs extended. **Notice I have only hfs, instead of hfs+. Won't work any other way. **Be sure to add the 0 0 at the end or it will not work.

The thrid line is the 2nd partition on the same HDD as my OSX86 Tiger install. Same as the second line.

 

Hope this helps someone out.

 

Keep on macKin'...

Link to comment
Share on other sites

  • 11 months later...
  • 2 months later...

I cannot get the fstab method to work.

 

I have three NTFS partitions (on two different disks). And they are labeled: C, D, E

 

I've tried:

my-macintosh:/ me$ cat /etc/fstab
LABEL=C none ntfs rw,noauto 0 0
LABEL=D none ntfs rw,noauto 0 0
LABEL=E none ntfs rw,noauto 0 0
my-macintosh:/ me$

 

I've also tried with ntfs-3g as the fstype.

I've even tried with fusefs as the fstype, as that is what shows up when I list mounted fs'es

 

my-macintosh:/ me$ mount
/dev/disk1s1 on / (hfs, local, journaled)
devfs on /dev (devfs, local)
fdesc on /dev (fdesc, union)
map -hosts on /net (autofs, automounted)
map auto_home on /home (autofs, automounted)
/dev/disk0s2 on /Volumes/D (fusefs, local, synchronous, noatime)
/dev/disk1s2 on /Volumes/E (fusefs, local, synchronous, noatime)
my-macintosh:/ me$

 

(C is not currently mounted as Windows did not shutdown properly and ntfs fs is locked)

 

 

I've also tried using the disk id (/dev/diskXsY) as opposed to labels, like other Unix's do, but that did not work either,

 

my-macintosh:/ me$ cat /etc/fstab
/dev/disk0s1 none ntfs rw,noauto 0 0
/dev/disk0s2 none ntfs rw,noauto 0 0
/dev/disk1s2 none ntfs rw,noauto 0 0
my-macintosh:/ me$

 

Again, using this method, I've tried with fstype = ntfs, ntff-3g and fusefs, but no joy.

Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

Does not work for me either, I have iPC 10.5.6, have no idea...

My-X61t-OSX:~$ cat /etc/fstab

LABEL=Vista none ntfs ro,noauto 0 0

LABEL=DATA none ntfs ro,noauto 0 0

 

My-X61t-OSX:~$ ls -l /etc/fstab

-rw-r--r-- 1 root wheel 71 5 Jul 18:40 /etc/fstab

 

Anybody?

Link to comment
Share on other sites

 Share

×
×
  • Create New...