Using hard links to move Windows Users folder
2013-11
I'm currently trying to move bulky folders from my SSD to my HDD (my Users
folder and ProgramData
folder). I'm following a short guide on using Directory Junctions to do this effectively.
However, this doesn't work for me. This is exactly what I did on my latest attempt:
- Locate old Users folder on HDD – the one I want to keep
- Install Windows 8 on SSD
- Reboot into recovery console – SSD=C: HDD=D:
- Copy
ProgramData
to HDDrobocopy /copyall /mir /xj C:\ProgramData D:\ProgramData
- Reboot into Ubuntu to copy over anything that failed and delete
ProgramData
- Reboot into recovery console
- Rename
C:\Users
toC:\Users.old
- Make junctions
mklink /J C:\Users D:\Users
mklink /J C:\ProgramData D:\ProgramData
- Check with
dir
that everything looks okay.
However, when I booted back up, the login splash screen was plain blue, I had no user profile picture, and upon logging in, I get:
User Profile Service service failed the sign-in. User profile cannot be loaded
So, I moved ProgramData
back again, and renamed Users.old
back to Users. This time, the splash screen shows correctly, but I still get the user profile issue.
What did I do wrong?
I've found the answer after a lot of playing. The reason this doesn't work is because when copying the data from SSD to HDD, any existing junctions are removed. This is because of the /xj
flag in robocopy
which is required to stop it from getting into an infinite loop.
In order to get around this, a PowerShell script could be made to do the following:
- Copy the data from SSD to HDD with
robocopy /copyall /mir /xj C:\Stuff D:\Stuff
- For each junction in
C:\Stuff
, create an identical junction inD:\Stuff
- For each junction in
C:\Stuff
, copy the ACL permissions to the corresponding junction inD:\Stuff
- Note the attributes of
C:\Stuff
withattrib C:\Stuff
- Remove or rename
C:\Stuff
- Create the junction
mklink /J C:\Stuff D:\Stuff
- Apply the attributes of
C:\Stuff
to the junction point withattrib /L C:\Stuff +H +I
(for example - ProgramData uses these attributes)
Hopefully, this will move everything from C:\Stuff
to D:\Stuff
whilst maintaining all junction points, permissions, and attributes.
But there is a 'shortcut', which I took. Instead of bothering with all this, I made a complete drive image of C:
, and restored it to D:
(obviously making sure no files were on D:
that would get overwritten). There is free software out there to do this such as Macrium Reflect Free and Drive Image XML.
I then copied any extra data I needed into D:
, and proceeded to skip to Step 4 of the above. Afterwards, I just removed all of my Windows files that weren't required on the drive (I had to use my Ubuntu USB stick for this part).
All working!
What are hardlinks and how are they different from files?
If i have a hardlink would all apps believe the link is a file? (I had programs not open files because they were shortcuts) If i modify a hardlink, does it modify the original or create a copy and modify that?
When you save a file on an NTFS filesystem, it creates the file somewhere on the drive, then creates a reference to it in the Master File Table (MFT). When a program requests a file, Windows looks in the MFT for the filename, and if found, returns the information the filename points to.
A hard link takes an existing file (or folder) and creates another, different entry in the MFT that points to the same data. To programs, both files look like different files with the same information, but they are actually the same file. If you modify one file, the other one is changed too because they are actually the same file going by two different names.
This is different from a shortcut, because a shortcut is actually a file itself that contains information about the target.
From the Developer's Tidbit:
For Window users unfamiliar with hard links, they not are unlike file and folder shortcuts. Except for one critical difference they are sorted and registered by the operating system’s file partition just like real files and directories. This means that unlike a shortcut, any program or application (including Windows Explorer and the Command Prompt) that looks that the hard link will always treat it the same as the original file or folder the symbolic link is pointing to.
http://ipggi.wordpress.com/2009/09/07/windows-file-junctions-symbolic-links-and-hard-links/
Check out this article from the How To Geek:
http://www.howtogeek.com/howto/windows-vista/using-symlinks-in-windows-vista/
From MSDN: