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:
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 thewinsxs
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".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 inmlink
. But they are doing what I want to do with winsxs: copy the contents of the folder to another drive, then doingmklink /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.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?
Answer
The most important thing you should know about WinSxS
:
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\
.
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:
Seems legit. Properties of B, which also contains one hard link to the same 64 KB file:
This is also fine. Now I'll select both A and B and let's see how much space they take according to properties:
... 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?
- Updates can be easily uninstalled - old files are still there, waiting for you in WinSxS.
- 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.
No comments:
Post a Comment