Moving Windows folders around with Junction links (mklink)

23

15

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)

veljkoz

Posted 2015-06-24T12:32:56.140

Reputation: 685

It will be messing. I did exactly this and after software like Ramdisk failed to install. Same with mklink /J and /D, only moving folder back to c let me finish install.

Possibly also my windows updates had issues. – Cmazay – 2019-12-02T15:41:06.257

Answers

29

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.

veljkoz

Posted 2015-06-24T12:32:56.140

Reputation: 685

does this work in windows 10? – Syaiful Nizam Yahya – 2015-10-15T08:29:39.747

It should - all of the info still applies AFAIK. If you try it let us know how it went! – veljkoz – 2015-10-15T10:36:20.300

Worked on Windows 8 - very awesome, thanks. – Dunc – 2016-10-19T09:12:47.447

1Worked on Windows 7! – glenviewjeff – 2017-11-02T21:50:04.083

3Please 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. – 0xA3 – 2017-11-22T09:57:27.133

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. – basin – 2018-03-16T07:24:08.930

3

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)

Adam Cox

Posted 2015-06-24T12:32:56.140

Reputation: 131

1Note: 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. – TWiStErRob – 2017-06-11T20:21:57.637

2

I took similar steps, but I wanted to be able to use my computer while I did the file copy (my folder was 40 GB).

  1. Manually copy the folder to F:\Installer
  2. I am using Windows 8.1, so to get to a command line boot I held Shift while I clicked Restart, then clicked Advanced
  3. Once in the command line, I had to figure out which drive letter to use (it wasn't C: even though that is my %SystemDrive% when my OS is fully booted). I had to use echo list volume | diskpart to find out that the C: drive was now referred to as E: and the F: drive was still the F: drive
  4. I removed the hidden and system attributes on E:\Windows\Installer with attrib -s -h E:\Windows\Installer and renamed it with rename "E:\Windows\Installer" "Installer_old"
  5. I could then create the junction with mklink /J E:\Windows\Installer F:\Installer

kevinpo

Posted 2015-06-24T12:32:56.140

Reputation: 121

2

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).

Anonymous

Posted 2015-06-24T12:32:56.140

Reputation: 21

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 – NiKiZe – 2019-02-15T12:05:42.383

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? – Oleg V. Volkov – 2019-09-21T13:07:56.793

0

  1. Copy C:\Windows\Installer to another disk such as D:\C\Windows\Installer.
  2. Check and compare sizes of both folders if the source directory on C: has not been changed during copying.
  3. Rename folder on disk C:, e.g. Installer => InstallerX
  4. Run the command as an admin and launch run this command:
    • mklink /d C:\Windows\Installer D:\C\Windows\Installer
  5. Wait some time (few day) if everything is OK.
    • If yes, you can delete backup the folder C:\Windows\InstallerX.
    • If no, delete symbolic the folder C:\Windows\Installer and rename back InstallerX to Installer, or copy back the folder D:\C\Windows\Installer to C:\Windows\Installer.

Petr Voborník

Posted 2015-06-24T12:32:56.140

Reputation: 109

This duplicates another answer and adds no new content. Please don't post an answer unless you actually have something new to contribute. – DavidPostill – 2016-04-20T08:34:10.780