How to Mount a Windows Folder as a Virtual Drive Using mklink and subst Commands


1 views

When working with Windows systems, you might need to map a physical directory to a virtual drive letter for easier access or application compatibility. Unlike Linux's bind mounts, Windows offers several methods including NTFS junctions, symbolic links, and the subst command.

The simplest way to create a virtual drive is using the subst command in Command Prompt:

subst M: C:\foo

This creates a temporary mapping that disappears after reboot. To make it persistent, you can add it to your startup scripts.

For a more permanent solution, use the mklink command as Administrator:

mklink /D M: C:\foo

Note that this requires:

  • Administrator privileges
  • NTFS filesystem
  • Target folder must exist

For more control, you can use DiskPart:

diskpart
select vdisk file="C:\foo"
attach vdisk

Here's how I use this in my development workflow:

:: Map my project folder to P: drive
subst P: C:\dev\projects\current

:: For testing cross-drive references
mklink /D T: C:\test\environments

If you encounter errors:

  • "System error 67" - The drive letter is already in use
  • "Access denied" - Run Command Prompt as Administrator
  • "Local Device name is already in use" - The mapping exists

Remember that these mappings are visible only to your user session. For system-wide access, consider creating proper network shares.


When working with deep directory structures or frequently accessed folders, mounting them as drive letters can significantly improve workflow efficiency. Unlike Linux's bind mounts, Windows offers two primary methods for this operation: the mklink command (for symbolic links) and the subst command.

For a simple, session-based solution:

subst M: C:\foo

This creates a virtual drive M: pointing to C:\foo. The mapping persists until reboot or until you run:

subst M: /D

For a persistent solution that survives reboots, create a directory junction:

mklink /J M: C:\foo

Note: This requires running Command Prompt as Administrator.

For modern Windows systems (Windows 10+), you can use PowerShell:

New-PSDrive -Name "M" -PSProvider FileSystem -Root "C:\foo" -Persist

The -Persist parameter makes the mapping available in File Explorer.

  • Accessing deep project directories quickly: subst P: C:\dev\projects\current\src
  • Creating a persistent tools drive: mklink /J T: C:\Program Files\DevelopmentTools
  • Network folder access: subst N: \\server\shared\team

1. Drive letters must not conflict with existing volumes
2. Junction points require NTFS file system
3. Some applications might not handle virtual drives properly
4. For network paths, consider using net use instead for better reliability