Detailed steps for creating a junction for winsxs folder in Windows 7

7,931

The most important thing you should know about WinSxS:

It doesn't take as much space as its properties show.

WinSxS properties screenshot

WinSxS contains mostly hard links. A hard link is similar to symlink, but it's much more transparent.

Files aren't stored on hard disk as a tree, but rather in a flat structure. Items from this structure are then mapped into folder tree and given names. Each such mapping is a single hard link. So hard link is what connects a file name and path to file's contents.

Most files have only one hard link. For example when you download a file, its contents are stored somewhere on hard disk and a named hard link is created in C:\Users\<yourUsername>\Downloads.

You can create extra hardlink if you want, either in the same directory (with a different file name) or somewhere else on the same drive. File contents will be stored on the drive only once, so creating second hard link won't increase disk usage. The file will be accessible from two paths. Both of these hard links will share properties, modification dates and file contents. Any modifications to one file are immediately effective on the second one. File won't be erased from the flat structure until all its hard links are removed, so deleting hard link will leave the file untouched unless it's the last hard link. Hard links are undistinguishable from each other, you can't tell which one was created first. They are both completely equivalent. (As opposed to symlinks, where there is one "master" file.)

Files from other drives can be symlinked to any drive and directory junctions can be created across drives. You can't create a hard link to a file on another drive, though. All hard links have to point to a file on the same volume.

Now let's make an experiment. I'll create two folders, then a 64 KB file in one of them and a hard link to this file in the second one.

C:\Users\gronostaj\Desktop\experiment>mkdir A B

C:\Users\gronostaj\Desktop\experiment>fsutil file createnew A\hardlink1 65536
File C:\Users\gronostaj\Desktop\experiment\A\hardlink1 is created

C:\Users\gronostaj\Desktop\experiment>mklink /h B\hardlink2 A\hardlink1
Hardlink created for B\hardlink2 <<===>> A\hardlink1

We have a folder tree like this:

+ experiment
|-+ A
| `-- hardlink1
`-+ B
  `-- hardlink2

Here are properties of A, which contains one hard link to a 64 KB file:

Properties of A, showing total size 64 KB

Seems legit. Properties of B, which also contains one hard link to the same 64 KB file:

Properties of B, showing total size 64 KB

This is also fine. Now I'll select both A and B and let's see how much space they take according to properties:

Properties of A and B, showing total size 128 KB

... and this window is lying to us. There is only one physical file that takes 64 KB. Windows Explorer doesn't know this, though - it counts total size of files pointed by hard links and there are two hard links to 64 KB files. That's why it thinks that these folders take twice as much space as they actually do. Don't trust folder size in properties.

WinSxS contains hard links to system files that Windows used at some point. When a system file is installed, it is hard linked in its main location and in WinSxS. On a freshly installed Windows system WinSxS appears to be few GB big, but its effective size is zero, because it contains only files that are hard linked somewhere else.

When a system file is replaced (for example by Windows Update) it is removed from main location and a new file is installed in its place. This new file is also hard linked in WinSxS. At this point Windows uses only newer version of the file, but your hard disk contains two versions, one of them no longer used. This actually causes WinSxS to grow.

Why does Windows do this?

  1. Updates can be easily uninstalled - old files are still there, waiting for you in WinSxS.
  2. Windows is able to automatically fix some problems with damaged files because good copies are kept in WinSxS. This is what sfc /scannow does.

At this point we can conclude that we can't move WinSxS to a different drive, because some files inside are hard linked somewhere else in C:\Windows. You could copy them to a different drive and create a junction, but it would increase total disk usage (extra hard links don't take space, extra copies do) and would probably break WinSxS.

The only reasonable way to reduce size of WinSxS is to remove unused old versions of files. This can be done using the Disk Cleanup tool (which is available in Windows) by checking the Windows Update Cleanup checkbox. If it doesn't show up in Disk Cleanup, then your WinSxS is already compacted.

Share:
7,931

Related videos on Youtube

Xirux Nefer
Author by

Xirux Nefer

Updated on September 18, 2022

Comments

  • Xirux Nefer
    Xirux Nefer almost 2 years

    I was searching for a list of detailed steps in Windows 7 for moving the winsxs folder to my data HDD drive and creating a junction in the SSD with

    mklink /J oldpath newpath
    

    I could only find this, which is linked from a superuser question (Can winsxs be moved and if so how?), but it is for Vista and was published in... 2007:

    How to move the WinSxS directory in Vista

    I also found these answers here on superuser:

    1. In Windows 7, can I create a Symlink or Junction for winsxs or installer folders In this superuser question, a user is asking if they can make an mlink to the winsxs folder after moving it to another drive, and the answer is "you can do this for Installer". But the question was, can you do it for winsxs? Specially after the first comment under the question saying that "this can't be done because those are "already" symlinks".

    2. How can I free up drive space from the Windows installer folder without killing Windows? This is for the Windows/Installer folder, NOT winsxs, and using the /D option instead of the /J option in mlink. But they are doing what I want to do with winsxs: copy the contents of the folder to another drive, then doing mklink /D oldpath newpath. But can I do this with winsxs? (the linked blog post also didn't move the winsxs folder, they only moved the other folders). Also, commenters of the linked blog post are reporting that they couldn't change from Admin privileges to SYSTEM privileges, which is the first step before running the commands or moving the folders.

    3. How can I free up drive space from the Windows installer folder without killing Windows? Another commenter in the previous superuser link says that, if you make a junction,

    "msiexec (apparently) ignores the junction, and manually creates C:\Windows\Installer. This 1) removes the junction, and 2) completely deletes the contents of the target directory."

    Would this happen to the winsxs folder too?

    So, summarizing:

    I want to move the winsxs folder and then create a junction to it, but I'm not sure if I can do it or the consecuences of it.

    • Would those steps written for Vista in 2007 that I linked at the beginning work for Win 7?
    • Is the user who says that "this can't be done because those are "already" symlinks" right?
    • If Vista steps to move the folder and create the junction won't work in Win 7, would those described in the linked blog post of point 2 work? How to change the privileges correctly from Admin to SYSTEM without getting the reported errors?
    • If I manage to create the junction, will msiexec ignore the junction, and manually create C:\Windows\winsxs, removing the junction and completely deleting the contents of the target directory?
    • What option would I use, /J (junction) or /D (symlink link)? I'm guessing /J, and I know the difference between the two, but since the other option also appeared on an answer, I don't know anything anymore. Different options appear in different sources. Who is right?
    • I say Reinstate Monica
      I say Reinstate Monica about 9 years
      I understand and appreciate your meticulous effort to show your own research but there's so much information here it's hard to know which question you want to walk away with an answer to. Is your core question How can I move the WinSXS folder to another drive on the Windows 7 OS? If so, edit your question to focus on that specifically.
    • Xirux Nefer
      Xirux Nefer about 9 years
      Yes, that is exactly my question, and the information there is not to show my research, but to show the obstacles I'm finding or the doubts I face in order to move that folder. Should I move it or not? Do I move it like this or like that? If this way doesn' t work, would this other way work? All the information is related with my question and supports it. In fact, I thought I was almost repeating myself, if anything. Also, I'm showing that even if it looks like other questions, it's really not, since those don't have satisfactory answers. I don't want it to be marked as duplicate when it isnt.
    • I say Reinstate Monica
      I say Reinstate Monica about 9 years
      You do well to clarify how your question isn't a duplicate. However its lack of focus has it in danger of being closed as too broad. I suggest you ask your core question, then should a helpful answer leave you uncertain of its implementation, request better detail. None of this can happen if your question remains too broad and is closed as such.
    • Xirux Nefer
      Xirux Nefer about 9 years
      Is it better now? I really don't know how to make it more specific. When I read it, it doesn't sound broad or lacking focus... I'm talking about the junction all the time.
    • Dave
      Dave about 9 years
      I think the downvote is unfair, so +1 but sorry, I'm going to close with final vote
  • Xirux Nefer
    Xirux Nefer about 9 years
    I knew that the winsxs folder was not as big as the system tells me, but I thought the files inside it were symlinks, as one of the commenters I mentioned said.Why is so many people advising to move winsxs to another drive and make a junction from Windows/winsxs to the newpath?There are even apps to do it so that you don't have to do it manually (they don't look safe though).Are the other folders mentioned in my question hardlinks too, & is that the reason why one commenter says that msiexec ignores the junction, manually creates the folder, removing the junction,and deleting target directory?
  • qasdfdsaq
    qasdfdsaq about 9 years
    @XiruxNefer: The files inside WinSXS are hardlinks not symlinks. As for why so many people advise it, many people advise dumb things without understanding what they're on about. This is nothing new. If you want to, the Vista instructions will work for Windows 7. But you will waste more space on the destination drive as you will be duplicating the hardlinked files. The Installer folder can easily be moved and replaced with a symlink. I haven't tried using a junction point, symlink works fine. msiexec does not ignore symlinks.
  • Xirux Nefer
    Xirux Nefer about 9 years
    Thank you both. Your answers were very detailed and helpful.
  • Rex Whitten
    Rex Whitten over 7 years
    So when your C:\ is full and WinSxS is huge, there is nothing you can do to tell windows that are you not really out of space? How do you tell other programs that you have plenty of space, and WinSxS is not half of my disk?
  • gronostaj
    gronostaj over 7 years
    @RexWhitten Windows and other programs are well aware of this. They don't check disk usage by counting total file size (which would be slow and give incorrect results, as shown in my answer). Instead they query file system, which is designed to quickly calculate disk usage and available free space accurately. So when Windows and other programs tell you that you're out of space, it means you really are - with the fact that WinSxS is smaller than it seems already taken into account.