A bash script to mount and unmount the Windows partition in Mac OS X

Discussion in 'Windows, Linux & Others on the Mac' started by svenbox, Apr 24, 2006.

  1. svenbox macrumors newbie

    Joined:
    Apr 24, 2006
    #1
    Hi all,
    I was getting a little annoyed with seeing my WindowsXP partition in the Finder and on the desktop all the time, so I looked around for a way to easily mount and unmount it. This bash script comes from a hint on Macosxhints.com, I didn't write it, just modified it a little bit! I've added it as a startup item, and whenever I need my WindowsXP volume mounted (it's a FAT32 formatted partition) I just run the script again and the volume will get mounted. This script sort of toggles the mounting status of my partition.

    What you need to do is to find out a) your volumes name and b) your volumes partition (you can do this by showing info on the partition in Disk Utility. Put this in the script, save the script in for example /usr/local/bin and make it execute (chmod 777) and off you go.

    Code:
    #!/bin/bash
    NAME=WINDOWSXP
    PART=disk0s3
    
    if [ -z `ls -1 /Volumes/ | grep $NAME` ] ; then 
        # check that PART appears to be a disk partition
        echo Checking $NAME $PART
        if [ `file /dev/$PART | awk '{print $2}'` = "block" ] ; then
      echo Mounting $NAME $PART
         diskutil mount /dev/$PART
        else
           echo /dev/$PART does not appear to be a disk partition - exiting
      exit 1
        fi
    else
        echo unmounting $NAME
        diskutil unmount /Volumes/$NAME
    fi
    If you want to make this more gui friendly, you can wrap it in an Applescript app (with the line do shell script "/usr/local/bin/WindowsXPmount" for example), add the Windows XP logo and wowee you got a little app that toggles the visibility for your Win partition.

    Now if I only could find out a way to make the Volume name lowercase, eg WindowsXP instead of WINDOWSXP, I would be really happy. Somehow FAT32 formatting makes it impossible to get rid of these screamin CAPS in drive names...

    /S
     
  2. Gordy macrumors 6502a

    Joined:
    May 22, 2005
    Location:
    Bristol, UK
    #2
    To change the volume name boot into windows and change the name of the hard disc to whatever you want :)

    Great script by the way! :)
     
  3. svenbox thread starter macrumors newbie

    Joined:
    Apr 24, 2006
    #3
    Hi, If you would have read my post, you would have seen that I have problems getting the drive name to be in lower case characters instead of CAPITALS, renaming the drive is not a problem to do (even in os x i think).

    /S
     
  4. Gordy macrumors 6502a

    Joined:
    May 22, 2005
    Location:
    Bristol, UK
    #4
    I renamed mine in windows to Windows HD and it shows up on the desktop as that. No capitols except where I specified them. It shows up in disc utility as Windows HD too.

    I just booted up in windows loaded my computer or windows explorer clicked on the hard disc and pressed f2 to rename.

    Hope that works for you
     
  5. svenbox thread starter macrumors newbie

    Joined:
    Apr 24, 2006
    #5
    NTFS or FAT32?

    /S
     
  6. Gordy macrumors 6502a

    Joined:
    May 22, 2005
    Location:
    Bristol, UK
    #6
    NTFS. Don't know why I chose that over fat32 it would have been easier to go for fat32 and allow me to use it on either partition.

    I need to do a reinstall at some time so I will sort it out then.
     
  7. MRU macrumors demi-god

    MRU

    Joined:
    Aug 23, 2005
    Location:
    Ireland
    #7
    Or simply in windows rename c:local disk to .windows

    then when your in OSX it wont appear on the desktop ever. Life is simple why complicate it? :D
     
  8. elcid macrumors 6502

    Joined:
    May 5, 2007
    #8
    Not to raise an old post from the dead, but this doesn't work for me. I try and rename the drive under My Computer from Local Disc (C) to .Windows and it says it is an illegal naming. Any ideas?
     

Share This Page