Using hard links to move Windows Users folder

08
2013-11
  • CJxD

    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:

    1. Locate old Users folder on HDD – the one I want to keep
    2. Install Windows 8 on SSD
    3. Reboot into recovery console – SSD=C: HDD=D:
    4. Copy ProgramData to HDD robocopy /copyall /mir /xj C:\ProgramData D:\ProgramData
    5. Reboot into Ubuntu to copy over anything that failed and delete ProgramData
    6. Reboot into recovery console
    7. Rename C:\Users to C:\Users.old
    8. Make junctions
      1. mklink /J C:\Users D:\Users
      2. mklink /J C:\ProgramData D:\ProgramData
    9. 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?

  • Answers
  • CJxD

    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:

    1. Copy the data from SSD to HDD with robocopy /copyall /mir /xj C:\Stuff D:\Stuff
    2. For each junction in C:\Stuff, create an identical junction in D:\Stuff
    3. For each junction in C:\Stuff, copy the ACL permissions to the corresponding junction in D:\Stuff
    4. Note the attributes of C:\Stuff with attrib C:\Stuff
    5. Remove or rename C:\Stuff
    6. Create the junction mklink /J C:\Stuff D:\Stuff
    7. Apply the attributes of C:\Stuff to the junction point with attrib /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!


  • Related Question

    What are hardlinks on windows 7?
  • acidzombie24

    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?


  • Related Answers
  • TuxRug

    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. Hard Link diagram

    This is different from a shortcut, because a shortcut is actually a file itself that contains information about the target. Shortcut diagram

  • David Freitas

    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:

    Hard Links and Junctions