git - git - How to determine how Linux sees Windows drives - answerstu - answerstu

git - How to determine how Linux sees Windows drives

I'm aware that the Windows C:\ drive appears in the Windows Subsystem for Linux as /mnt/c. However, in bash Git hook scripts the C:\ drive appears as /c, not /mnt/c.

Is there any way from within a bash script to determine how the C:\ drive should be referenced? In other words, is there any way to determine whether a path should be built up using /mnt/c or /c?

2 Answers

  1. Gino- Reply


    Git for Windows realm:

    Here the POSIX functionalities are provided by msys2 shared dynamic library (aka. DLL) and /bin/git.exe is cross-compiled (PE) for that environment. The mount point in this environment, is same as UNIX systems, is configured by /etc/fstab. Here is the sample:

    none / cygdrive binary,posix=0,noacl,user 0 0

    So, the Windows drives are monted in / (root) folder. For example, C:\ becomes /c. This is default option. Users can change it to desired value.

    Windows Subsystem for Linux realm:

    Here WSL executes real ELF64 binaries which are forked from /init. The mount points are managed by that init binary and Lx Subsystem Session Manager Service (LxssManager). By default, all Windows partitions are mounted in /mnt folder. Beginning with Insider Build 17093, the mount points can be configured with /etc/wsl.conf file. Read this blog post carefully for further information. Here is an sample:

    enabled = true
    mountFsTab = true
    root = /
    options = "metadata,umask=22,fmask=11"

    In short, this file:

    • enabled: Automatically mount Windows drives.
    • mountFsTab: Automatically mount user configured drives from /etc/fstab file.
    • root: Directory where Windows drives will be mounted.
    • options: Mount options for Windows drives. These are same as mount -o command.

  2. Glen- Reply


    Your question is a bit of a non-starter as it makes incorrect assumptions. For a start Windows drives can be mounted in different ways - as local disks, as SMB mounts, as NFS mounts spring to mind.

    /mnt/c may be applicable your distro, but it's not particularly common and not the case in Ubuntu type distros, which use /media?deviceid/ - where.deviceid is not a drive letter.

    Similarly, "C" drive is fairly arbitrary - Linux does have a structure for drives - so if it's a local hard drive you can probably find a way to scan /dev/sd*? for NTFS partitions and see if they are mounted. This is not a good general solution as it makes lots of assumptions which are often likely to be incorrect - you might be better off prompting for a path.

    Another (error prone) way might be to assume the disk is mounted and then use df and parse each (non shm) system for windows/

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>