Moving Windows folders around with Junction links (mklink)

39,653

Solution 1

OK, I've taken the risk and it was worth it - everything works normally, but I have freed the 17GB on my SSD now.

Basically, the steps are:

  1. Restart your PC, press F8 continuously to bring up boot menu, and choose "Command prompt with safe mode" (this is to ensure you can move the windows folder around)
  2. Once the command prompt is shown, type the command to move the folder to another drive:
    robocopy C:\Windows\Installer D:\Windows\Installer /MOVE /e
  3. Next, create a "Junction" link for the missing folder:
    mklink /J C:\Windows\Installer D:\Windows\Installer

Of course, this assumes that your %WINDIR% is C:\Windows, that your D drive is the one with more space, that you want your destination in "D:\Windows\Installer" (it could be any folder, just be consistent) etc...

This should do the trick.

Solution 2

While attempting to reclaim space on my main drive, an 120GB SSD, I found these instructions on how to relocate Users, Program Files, Program Files (x86), and ProgramData. It includes some registry edits "to set default locations", as follows:

  1. Replace drive letters of paths listed at HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion (for example C:\Program Files\Common Files would become D:\Program Files\Common Files)
  2. Replace environment variables %SystemDrive% with drive path at HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/ProfileList (i.e. %SystemDrive%\ProgramData would become D:\ProgramData)

Solution 3

You can use same trick for pagefile.sys and swapfile.sys (not sure if also for hiberfile.sys, not tested since i hate hibernating on multi-boot).

Just ensure to deactivate virtual ram and reboot prior to create the symlinks, then after creating them reactivate virtual ram.

I tend to create (with notepad) an empty file on destiny of the link prior to create the link.

Remember: When Windows10 UpGrade it will remove the links and put real files, after UpGrades you can repeat the process.

Working upto Windows 10 version 1803.48, since WindowsXP (oldest i had tried).

Share:
39,653

Related videos on Youtube

veljkoz
Author by

veljkoz

Updated on September 18, 2022

Comments

  • veljkoz
    veljkoz almost 2 years

    Space on my SSD is running pretty low, and there seems to be a 19GB folder in Windows that sticks out (%windir%\Installer) and cannot be safely deleted (as explained here: https://serverfault.com/q/15746).

    Now, the mklink provides a neat little thing called Junction links - if I boot in cmd prompt, and move all of the files to the other hard drive, and then run this:

    mklink /J C:\Windows\Installer D:\Windows\Installer
    

    Will I be messing up my Windows in some way, or is this an OK thing to do? Will folder permissions/attributes stay the same across the link?

    I've used hard links before, and it worked like a charm freeing up my SSD significantly, but I've never tried it on system folders (I don't see why it wouldn't work, but I'm not in the mood of reinstalling entire windows in case I'm wrong)

  • Syaiful Nizam Yahya
    Syaiful Nizam Yahya over 8 years
    does this work in windows 10?
  • veljkoz
    veljkoz over 8 years
    It should - all of the info still applies AFAIK. If you try it let us know how it went!
  • ajf0
    ajf0 about 7 years
    Note: any already installed apps may still look in the old location if their configuration/registry entries point to a location that was resolved before this change. Reinstall of those apps may fix the issue.
  • glenviewjeff
    glenviewjeff over 6 years
    Worked on Windows 7!
  • 0xA3
    0xA3 over 6 years
    Please be aware that this might cause problems when installing major Windows updates (such as Windows 10 Fall Creators Update) because the junction will be replaced with an empty folder.
  • basin
    basin over 6 years
    Didn't work on Win7 with junction: I ran a program installer after moving. It took more than usual and then I saw why: Windows deleted all the files below C:\Windows\Installer and replaced the junction with a normal folder containing just the recent files. The installer was: PatchCleaner_1.4.2.0.exe.
  • NiKiZe
    NiKiZe over 5 years
    if you don't want hibernation, turn it of with powercfg -h offinstead. Using links on these files sounds like a sure receipt for disaster
  • Oleg V. Volkov
    Oleg V. Volkov almost 5 years
    Why bother moving/liningk swap with its TEMPORARY content that you don't want to preserve if you can simply disable it on one drive and enable on another?