47

I'm switching to Cygwin from the bash shell that ships with Git for Windows, and encountering a strange problem. Someone thought it would be a good idea to add /cygdrive/ to all paths, while I think it's a horribly ugly idea. I've been able to determine that I can partially fix this by adding

mount --change-cygdrive-prefix /
export HOME=/c/Users/BZISAD0

in my .bashrc, but if I take a look at the PATH variable, everything still has /cygdrive/ in it. I suppose I could write a script to fix the PATH but that's even more kludgey than what I'm already doing. There's got to be a better way, and I'm pretty confident there is since Git's bash shell uses (AFAIK) an older version of Cygwin, and it's somehow configured to not prepend /cygdrive everywhere. So, how can I turn the "Suck" knob to zero?

Gary Larson comic

5 Answers 5

46

Grepping around in /etc turned up a link that Googling did not. It turns out you can control this in the file /etc/fstab. Just add a line that says

none / cygdrive binary 0 0

and the problem should be fixed. No more kludgey fixes in .bashrc, and no messed-up $PATH.

8
  • 2
    I used this method, and now when I try to do ls /, the windows drives don't appear. Not even when using ls -l /. Is this expected? Can it be fixed? This is what I have in fstab: none / cygdrive binary,posix=0,user,acl 0 0
    – Tibi
    Commented Jul 8, 2014 at 13:44
  • I didn't know there was a way to get the windows drives at /. Did you have that before? (Or at /cygdrive/?) I've always just lived with the fact that I have to know which Windows drives are available, and I hardly ever use them anyway.
    – iconoclast
    Commented Jul 8, 2014 at 15:49
  • 1
    Yes, ls /cygdrive should list the Windows drives. The output for me, for example, is c/ e/ f/. Note how drives are treated like folders.
    – Kat
    Commented Oct 13, 2014 at 4:05
  • 2
    This only half works. The two mounts (real / and cygdrive) are sort of overlaid. That is: you can get at the drives using /c, etc. - but they are never listed as part of /. I think the real / is hiding the contents of cygdrive when listing. I'm wondering if this is technically undefined behaviour and might conceivably break something. Anyway, since I prefer to be able to see anything I'm working with, I'm choosing /mnt. Commented Oct 13, 2015 at 10:51
  • 1
    @Tibi I discovered that if you cd to / and then do mkdir c (or whatever the name of your drive is), it will make that drive mount point visible to ls, instead of overwriting it with an empty directory. Who would have thought?
    – barksdml
    Commented Apr 1, 2016 at 15:53
12

Method one

mount -c /
mount -m > /etc/fstab

Method two

echo - / cygdrive acl > /etc/fstab

Example

4
  • both before and after doing this (method 1), / referred to the cygwin64 root directory, and cd /c did not work. To make cd /c work I had to do mount c: /c .
    – M.M
    Commented May 30, 2016 at 5:17
  • /c should never have worked, my solution never suggested that
    – Zombo
    Commented May 30, 2016 at 7:10
  • 2
    I interpret "how to get rid of /cygdrive in paths" to mean "how to allow /c to work instead of /cygdrive/c " (and similarly for other letters) . My PATH does now indeed show /c/bla instead of /cygdrive/c/bla
    – M.M
    Commented May 30, 2016 at 7:18
  • 2
    As of 2.9.0(0.318/5/3) 2017-09-12 10:18 x86_64 Cygwin, doing method one will allow user to cd /c or cd c:. Using cd / still goes to the cygwin64 dir. Commented Jan 5, 2018 at 17:57
4

What about cygpath (Convert Unix and Windows format paths, or output system path information)...

$ pwd
/cygdrive/c/Windows/System32

$ cygpath -w $(pwd)
C:\Windows\System32
2

Yes, mount should work.

mount -c /

If you still have entries in PATH that refer to /cygdrive, then you probably just need to reboot.

Also, check if there are any PATH settings in /etc/profile that refer to /cygdrive.

5
  • You mean restart Cygwin, or actually reboot the whole machine?
    – iconoclast
    Commented Aug 3, 2012 at 16:40
  • I think you need to terminate all Cygwin-based processes. The easiest way to do this is to reboot the machine.
    – Mikel
    Commented Aug 3, 2012 at 17:23
  • I normally give preference to other people's answers when I find answers to my own questions, but since yours requires a reboot (or simulation thereof) and since mine is the one found in cygwin's documentation, I'm going with mine.
    – iconoclast
    Commented Aug 13, 2012 at 18:07
  • If yours worked without a reboot, then by all means!
    – Mikel
    Commented Aug 13, 2012 at 18:47
  • But if I reboot the machine, this change is gone. Back to what is stored in fstab.
    – rustyx
    Commented Feb 3, 2017 at 21:51
1

Another point that wasn't mentioned is that different flavors using the Cygwin DLL use different configurations (like the above). One example would be Git for Windows, which is based on MSYS which in turn uses Cygwin.

The unified way to access the "Unix" path across these flavors is to use /proc/cygdrive; this way it doesn't matter if cygpath -u D:\ returns /d or /cygdrive/d.

The common prefix can also be got from cygpath using the -U switch.

PS: Since this doesn't answer the question, but sidestep the underlying issue (except for the cosmetic one), I am making this CW.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .