46

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

Kevdog777
  • 3,194
  • 18
  • 43
  • 64
iconoclast
  • 9,057
  • 12
  • 56
  • 95

5 Answers5

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.

iconoclast
  • 9,057
  • 12
  • 56
  • 95
  • 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 Jul 08 '14 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 Jul 08 '14 at 15:49
  • I don't really know... I never tried it before. – Tibi Jul 18 '14 at 08:07
  • 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 Oct 13 '14 at 04: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`. – underscore_d Oct 13 '15 at 10:51
  • @underscore_d: fair enough. thanks for the info! – iconoclast Oct 15 '15 at 14:02
  • works pretty good! love it. – Nicholas DiPiazza Nov 30 '15 at 20:33
  • 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 Apr 01 '16 at 15:53
12

Method one

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

Method two

echo - / cygdrive acl > /etc/fstab

Example

Zombo
  • 1
  • 5
  • 43
  • 62
  • 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 May 30 '16 at 05:17
  • `/c` should never have worked, my solution never suggested that – Zombo May 30 '16 at 07: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 May 30 '16 at 07: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. – Marcel Wilson Jan 05 '18 at 17:57
3

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.

Mikel
  • 56,387
  • 13
  • 130
  • 149
  • You mean restart Cygwin, or actually reboot the whole machine? – iconoclast Aug 03 '12 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 Aug 03 '12 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 Aug 13 '12 at 18:07
  • If yours worked without a reboot, then by all means! – Mikel Aug 13 '12 at 18:47
  • But if I reboot the machine, this change is gone. Back to what is stored in fstab. – rustyx Feb 03 '17 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.

0xC0000022L
  • 16,189
  • 24
  • 102
  • 168