Jump to content

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


  • Please log in to reply
27 replies to this topic

#1
DucPilot1

DucPilot1

    InsanelyMac Protégé

  • Members
  • Pip
  • 10 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.


#2
quixos

quixos

    InsanelyMac Legend

  • Retired
  • 943 posts
brilliant! :D

#3
domino

domino

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPipPip
  • 1,958 posts
  • Gender:Male
  • Location:/tmp
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~

#4
FrDakota

FrDakota

    InsanelyMac Protégé

  • Members
  • PipPip
  • 74 posts
  • Gender:Male
  • Location:France
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:

#5
domino

domino

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPipPip
  • 1,958 posts
  • Gender:Male
  • Location:/tmp
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?

#6
DucPilot1

DucPilot1

    InsanelyMac Protégé

  • Members
  • Pip
  • 10 posts
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.

#7
FrDakota

FrDakota

    InsanelyMac Protégé

  • Members
  • PipPip
  • 74 posts
  • Gender:Male
  • Location:France

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:

#8
Swad

Swad

    Founder.

  • Administrators
  • 3,709 posts
  • Gender:Male
  • Location:Chicago
Thanks guys - this is what makes the Genius Bar so great!

#9
domino

domino

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPipPip
  • 1,958 posts
  • Gender:Male
  • Location:/tmp

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.

#10
Vernice

Vernice

    InsanelyMac Protégé

  • Members
  • Pip
  • 15 posts
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 ?

#11
FrDakota

FrDakota

    InsanelyMac Protégé

  • Members
  • PipPip
  • 74 posts
  • Gender:Male
  • Location:France
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.

#12
Vernice

Vernice

    InsanelyMac Protégé

  • Members
  • Pip
  • 15 posts
Yes ! I created one using Terminal command "sudo nano fstab"
and my patition is named winxp , file system is fat32
what do I do ?

#13
Proteo

Proteo

    InsanelyMac Legend

  • Members
  • PipPipPipPipPipPipPip
  • 683 posts
  • Location:Parangaricutirimicuaro
Vernice, what he's trying to tell you is that the right command is something like this:

cd /etc
sudo nano fstab

#14
Vernice

Vernice

    InsanelyMac Protégé

  • Members
  • Pip
  • 15 posts
It's worked ! thanks !

#15
FrDakota

FrDakota

    InsanelyMac Protégé

  • Members
  • PipPip
  • 74 posts
  • Gender:Male
  • Location:France
Damn, I was right. :lol:

DucPilot1, you should add cd /etc before sudo nano fstab in your How to, so that others won't do the same mistake as Vernice. :)

#16
DucPilot1

DucPilot1

    InsanelyMac Protégé

  • Members
  • Pip
  • 10 posts
DucPilot1, you should add cd /etc before sudo nano fstab in your How to, so that others won't do the same mistake as Vernice. :)
[/quote]


Done.

#17
iMcen

iMcen

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 139 posts
  • Location:Sweden
Have you guys managed to automount ext2 or ext3 partitions?
I can't get the application included in Mac OS X Ext2 Filesystem on SourceForge, version 1.4d3 (latest one), to mount them. Manual mount works.

#18
nastyhome

nastyhome

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 117 posts
From just reading this, you cant rw (read-write) NTFS partitions with this /etc/fstab method? Am i right?

Did anyone try it out?

#19
oskarloko

oskarloko

    InsanelyMac Protégé

  • Just Joined
  • Pip
  • 1 posts
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, Im 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

#20
SDRacer48

SDRacer48

    Air Cody...

  • Members
  • PipPipPipPipPipPipPip
  • 690 posts
  • Gender:Male
  • Location:UCF, Florida
  • Interests:Duh! Computers. And my wonderful wife.

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'...





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy