Jump to content











Photo

Creating Directory Junctions (Junction Links) on Windows


  • Please log in to reply
28 replies to this topic

#1 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 31 July 2020 - 12:51 PM

This topic is mainly for non advanced users. I'm quite shure all advanced users in this forum know and make use of Junction Links. a Junction Link is like a shortcut with steroids from one folder to another folder, that can be on any drive even if it is on another HD as far as it is in same equipment.

 

On this article the author makes a short explanation of the different kind of links (taken from following gbrao post):

https://ss64.com/nt/mklink.html

 

Create a symbolic link to a directory or a file, or create a hard file link or directory junction.

Syntax
      MKLINK [[/D] | [/H] | [/J]] LinkName Target

Key:

   /D     Create a Directory symbolic link. (default is file)

   /H     Create a hard link instead of a symbolic link.

   /J     Create a Directory Junction.

   LinkName The new symbolic link name.

   Target The path (relative or absolute) that the new link refers to.

 

And for more detailed and complete info you can see this pdf from Wonko's Post No. 4 : https://www.2brights...bolic-Links.pdf

NOTE: Also attached for your conveniience.

 

This is a program Link Shell Extension. That can be handy for people prefering a GUI.

 

The talk here will be about Junction Links, also called Directory Junctions wich are very useful.

 

In elevated Command Prompt:

 

mklink /J "path to create new junction link" "path to target folder"

 

NOTE: If using mklink command it creates the junction folder pointing to the folder where info is located.

 

I have being using Junction Links since XP and then there was not many info or available, during my search I found a little GUI program that I have being using, Author's page seems not available anymore but afortunately I found a link for those interested on a GUI program (and easier to use than Link Shell Extension), Junction Link Magic 2.0.3.0, this its last version and can run from 7 to 10 but it requires to have installed .Net framework 3.5, still available on 8.x and 10 installs but you need to activate/install it on Windows features/characteristics, (it contains also 2.0 and 2.5), I can't find a link to the XP version (so it is attached).

 

Junction Link Magic 2.0.3.0 (7 to 10)

https://www.softpedi...ink-Magic.shtml

 

NOTE: If using Junction Link Magic it can use an existing empty folder as the junction folder pointing to the folder where info is located.

 

We can use Junction Links to force some programs or games that do not let the user change or select the install location, here two examples:

 

Following cases are using Junction Link Magic if using mklink command you have to delete the original folder since the command will create it as a junction link.

 

Easy case:

 

FireFox installs usually in C:\Program Files\Mozilla Firefox this is a easy case, we create the same set of folders on another drive (even located on different HD, but on same machine) like F:\Program Files\ and then copy there the folder Mozilla Firefox, going back to the original location we delete all content of Mozilla Firefox folder (but not the folder). and create a Junction Link from the empty folder to the F:\Program Files\Mozilla Firefox folder. Of course the progam should not be running during this procedure. (this will take care of frecuent FireFox updates)

 

But to take care of all acumulated info from Internet I also I recommend to make a junction link from FireFox Profile folder on %APPDATA%\Roaming\Mozilla\Firefox\Profiles to another location outside the OS drive, here the program stores all pages, videos, etc we watch, of course CClener can delete all garbich from Internet. Maybe using as target folder something like: F:\Program Files\Mozilla Firefox\Profiles

 

Hard case:

 

NOTE: Following info is not valid anymore since Avast new versions now let the user install in another drive, and do not allow to install on a Junction Folder anymore, But you can take it just as an example/guide if you have a similar case with another program.

 

Avast AV that forces the users to install it on C:\Program Files\AVAST Software\Avast & once installed it also don't let the user create a Junction Link to other location as I have tested.

 

Well as we already know the path where it will be installed, the trik we can use is create the folders it will use during install in advance and other set of folders) as an example F:\Program Files\AVAST Software\Avast, and create then the junction link on C:\Program Files\AVAST Software\Avast folder pointing to F:\Program Files\AVAST Software\Avast folder, then when you install the AV it will use its usuall location but all its files/folders will be located phisically where we selected.

 

I used this 2 programs for my examples becouse both are very well known to writte to the disk a daily average of 1 GB each.  Same applies to any other browser and AV, but Google Chrome has the bigger numbers.

 

Other potential uses:

 

Reduce wear on SSDs:

 

My brother has an Small 256 GB SSD as primary HD and a secondary 2 GB HDD on his PC, in this case I put Google Chrome, Avast and the Page File (to satisfy some programs requiring it even if they don't use it) phisically on a dedicated partition on the HDD.

 

On Wimboot or Compact installs:

 

The use of portable programs is the best option in this cases, but if here is some heavy program you need/want/like or if it writtes to the drive a lot, creating a Junction Link to an external location will reduce the required space during install and/or the used space will not grow up so much, This is like simulating a portable.

 

Additional advantage:

 

When yo make a WIM image of your OS drive (or with a backup program), the resulting image will be smaller, if keeping your Documents, Downloads and all your games and heavy programs in another drive, and when restoring your OS all will be same as before.

 

alacran

Attached Files


  • wimb and antonino61 like this

#2 gbrao

gbrao

    Frequent Member

  • Advanced user
  • 474 posts
  •  
    India

Posted 31 July 2020 - 03:35 PM

I've come across statements like "Hardlinks can only be made within one NTFS volumes, and can not span across NTFS volumes."

 

Yet e.g.

mklink /J "C:\TEMP\1by1"  "D:\1by1 Portable"

seems to work. Please clarify.

 

EDIT : maybe the statements refer to files, not directories ?

I was misled by this "directory junction (a hard link to a folder)" from the htg article ?

 

EDIT 2 :

Nice chart here : https://ss64.com/nt/mklink.html

cleared up my confusion.
 



#3 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 01 August 2020 - 10:37 AM

I'm glad you have it clear now.

 

I edited my previos post trying to make it more clear and also to let users know there has being a change in Avast, now you can select other drive for install it, and now it do not allow to be installed on a previously created junction folder.

 

alacran



#4 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 01 August 2020 - 12:23 PM

@alacran

There is the usual mish mash on terms. (they actually are confusing)

 

Read the page gbrao posted a link to:

https://ss64.com/nt/mklink.html

 

mklink makes a Symbolic Link (and NOT a Junction)
mklink /J makes a Junction (and NOT a Symbolic Link)

mklink /h makes a hardlink

 

A Hardlink is a Hardlink.

 

A Symbolic link is not a Junction and a Junction is not a Symbolic Link.

 

Your instructions are for Junctions AND NOT for Symbolic Links.

 

See also this (clear) .pdf:
https://www.2brights...bolic-Links.pdf

 

Symbolic Links have been introduced in VIsta BUT there is a driver for them for XP:

https://schinagl.pri...nksforwindowsxp

 

:duff:

Wonko


  • wimb and alacran like this

#5 antonino61

antonino61

    Gold Member

  • Advanced user
  • 1525 posts
  •  
    Italy

Posted 01 August 2020 - 12:27 PM

and single files, alas, allow for simbolic links and not for junctions, if i am not mistaken.



#6 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 01 August 2020 - 12:41 PM

*
POPULAR

and single files, alas, allow for simbolic links and not for junctions, if i am not mistaken.

It is the other way round (who does what)

 

A file is a file.

A directory is a directory.

They do nothing but occupy some space on storage devices, and do not "allow" anything.

 

A Junction is a type of soft link that can ONLY link to a folder. (if you prefer that allows only a folder as source for the link)

A Symlink is a type of soft link that can link to EITHER a file OR to a folder (if you prefer that allows both files and folders as source for the link)

 

The OS and filesystem in use may allow or not allow hard and soft links.

 

Namely, on Windows NTFS only allows for hardlinks and Junctions up to XP (with the mentioned driver added also Symlinks are allowed) while starting from VIsta all three kinds of links are allowed.

 

:duff:

Wonko


  • wimb, alacran and antonino61 like this

#7 antonino61

antonino61

    Gold Member

  • Advanced user
  • 1525 posts
  •  
    Italy

Posted 01 August 2020 - 01:52 PM

u could not have been any more accurate



#8 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 01 August 2020 - 02:39 PM

@ Wonko

 

Fixed, thanks.

 

EDIT: Also your link to that pdf file was added to first post.

 

alacran



#9 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 01 August 2020 - 03:48 PM

Very good.  :thumbup:

 

The site is MIA, but it has been archived:

https://web.archive....m/linkmagic.htm

 

Old version here:

https://web.archive....m/linkmagic.exe

 

:duff:

Wonko


  • alacran likes this

#10 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 02 August 2020 - 07:35 AM

If we run Scan Now on Junction Link Magic it will show us all Pointerts in our PC, this could be useful in some cases. As to let us identify where are located the real files/folders and wich are only pointers.

 

I don't use to do that because I prefer to keep on the list only those I have created, to keep track of them, see attached pictures with some Junctions Links I have created, and the options available on the Scan feature.

 

NOTE: Junction Link Magic requires to have installed .Net framework 3.5, still available on 8.x and 10 installs but you need to activate/install it on Windows features/characteristics

 

alacran

Attached Files



#11 wimb

wimb

    Platinum Member

  • Developer
  • 3756 posts
  • Interests:Boot and Install from USB
  •  
    Netherlands

Posted 02 August 2020 - 09:52 AM

If we run Scan Now on Junction Link Magic it will show us all Pointerts in our PC, this could be useful in some cases. As to let us identify where are located the real files/folders and wich are only pointers.

 

I don't use to do that because I prefer to keep on the list only those I have created, to keep track of them, see attached pictures with some Junctions Links I have created, and the options available on the Scan feature.

 

 

If I use Scan Now then quite an extensive list of existing Junction Links is displayed.

How do you get a list of only the user created Junction Links  ?



#12 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 02 August 2020 - 09:58 AM

Well, this Nirsoft thingy NTFSLinksView:

https://www.nirsoft....links_view.html

is 48 KB, needs no friggin' .Net and can run even from within the .zip file.

 

:duff:

Wonko


  • wimb and antonino61 like this

#13 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 02 August 2020 - 10:08 AM

@ wimb

 

If I use Scan Now then quite an extensive list of existing Junction Links is displayed.

How do you get a list of only the user created Junction Links  ?

The links in first picture are for Junction Links created by the tool, without running the scan as said on my second paragraph:

 

 

I don't use to do that because I prefer to keep on the list only those I have created, to keep track of them

 

@ Wonko

 

Thanks for the link, I will take a look to that tool.

 

alacran



#14 wimb

wimb

    Platinum Member

  • Developer
  • 3756 posts
  • Interests:Boot and Install from USB
  •  
    Netherlands

Posted 02 August 2020 - 10:14 AM

 

The links in first picture are for Junction Links created by the tool, without running the scan as said on my second paragraph:

 

 

Yes I understand that you prefer Not to use Scan Now.

But, if you would have used Scan Now,  then is there a way to get only a List of the User created Junction Links ?

I am afraid there is no way in this case to get a clean list of only the user created Junction Links.

 

The user interface of the program Junction Link Magic might be quite limited in that respect ....



#15 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 02 August 2020 - 10:23 AM

You are right, there is no way:

 

The user interface of the program Junction Link Magic do not have this option.

 

alacran



#16 wimb

wimb

    Platinum Member

  • Developer
  • 3756 posts
  • Interests:Boot and Install from USB
  •  
    Netherlands

Posted 02 August 2020 - 10:27 AM

NTFSLinksView of NirSoft offers more possibilities to View Specific Links of a given path and to create reports about it.

 

The Junction GD  Created to GoogleDrive folder today is visible on top of the list sorted  to Created Time

Also the Type of Link is displayed  and you can Sort for a given Type

 

Attached File  NTFS_Links_2020-08-02_123913.jpg   412.34KB   0 downloads == Attached File  NTFS_Links_Cyano_2020-08-02_164426.jpg   183.55KB   0 downloads

 

EDIT: I have used now mklink in command window to create SymFileLink and SymDirLink and Junction Dir Link and File Hard Link

and have learned a lot from creating and using Links, Thanks to alacran and Wonko the Sane  :)



#17 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 02 August 2020 - 12:32 PM

Yes it looks very useful as it gives us the info per folder wich sound very useful for some uses.

 

alacran



#18 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 02 August 2020 - 12:40 PM

This iinfo may be also useful for creating our Junction links pointing to a folder containing (Compressed file by file in) Compact mode (4K to LZX) files/folders into it. Basically same thing Wimboot install pointer files do pointing to the files located into the source WIM, but in this case pointing to a folder.

 

Spoiler

 

alacran



#19 antonino61

antonino61

    Gold Member

  • Advanced user
  • 1525 posts
  •  
    Italy

Posted 02 August 2020 - 02:23 PM

wonderful link viewer this one, standalone, no need for anything else and it opens worlds so far unknown to me.

 

ps.: big question now: what operational moves does this newly-acquired knowledge accrue to the user? v.i.z., shall we add or delete any of the linx in order to improve performance or save further space? os shall it be used just "per conoscenza"?


  • wimb likes this

#20 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 02 August 2020 - 03:01 PM

wonderful link viewer this one, standalone, no need for anything else and it opens worlds so far unknown to me.

 

ps.: big question now: what operational moves does this newly-acquired knowledge accrue to the user? v.i.z., shall we add or delete any of the linx in order to improve performance or save further space? os shall it be used just "per conoscenza"?

How useful can be Symlinks (NOT Junctions)?

Since Symlinks (NOT Junctions) can be both for files AND for directories AND they are "cross-volumes", would it make sense to make a (boot) volume consisting ONLY of Symlinks to objects residing on another volume?

Would the Symlink mechanism be "low level enough" to allow the booting? (or would a number of "early needed" files need to be anyway on this "hypothetical" boot volume?)

 

There is IMHO still space to experiment with what I called (well before it exists, if it will ever exist) "Parasite PE":

http://reboot.pro/to...b4dos/?p=201966

 

:duff:

Wonko


  • antonino61 likes this

#21 antonino61

antonino61

    Gold Member

  • Advanced user
  • 1525 posts
  •  
    Italy

Posted 02 August 2020 - 03:06 PM

hahahah, after all, this is what we seem to be here for, but for the time being, the project looks like just a vision.



#22 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 02 August 2020 - 03:16 PM

@ Wonko

 

This time you arrived late to the party my friend:

 

The party started on Apr 11 2014 03:18 PM with this topic started by erwan.l

 

 

There is IMHO still space to experiment with what I called (well before it exists, if it will ever exist) "Parasite PE":

 

That is basically a Wimboot install where we have only full size files wich are criticall during boot stage, and all the rest of files on it are pointers to the source.wim file located outside.

And this approach has being extensively tested, on some of previous post the junctions are recommended for all those programs that make changes/updates very frecuently and then make grow up very fast the space used for our Wimboot install.

 

alaccran


  • antonino61 likes this

#23 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 02 August 2020 - 05:31 PM

Not really.

That is a completely different thing from the Parasite PE I was talking about.

 

Hey, I know what I imagined much better than you can, after all I imagined it. 

 

And I won't provide a link to where, several years before 2014, I started advocating separating PE's in a "main" boot and a "linked to" separate filesystem,  it was on 911CD and probably circa 2006 or 2007 and later (circa 2008-2010) you will find several hints about the possible usefulness of a sort of UnionFS on windows, besides the OFS experiments.

(but this remains another thing).

 

A (again, completely hypothetical) Parasite PE is exactly (in my perverted mind) what the name implies, it uses most (nearly all) files from an existing "normal" install, i.e. there is a "normal" install of Windows (no wimboot, no .wim files, a plain NTFS volume).

 

Then the install fails.

 

99% of the times that will be due to:
1) an issue with BOOTMGR/BCD (or however connected to the early boot phase)
2) an issue with a just installed driver or program
3) something gone beserk (see also the above item #2) in the registry.

 

Now if there was a Parasite PE in dual boot (grub4dos comes to mind) with an independent "Vista boot floppy" an "own" Registry, and all (or most) the other files gathered from the existing Windows install, you would have a sort of "advanced recovery console" with a footprint on disk near to 0.

 

And - say - on a very small USB stick, let's say the crappy 2 or 4 GB ones they now use as promotion items, you could have tens of specialized builds.

 

Of course these wouldn't work if the disk (or filesystem on it) where the actual OS file reside is corrupted (i.e. the remaining 1% of cases) 

 

:duff:

Wonko


  • antonino61 likes this

#24 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 02 August 2020 - 11:02 PM

My good friend, this are my thoughts about your Parasite PE idea:

 

Even if it could be builded, and booted fine, it doesn't sound very useful as all is linked to a local install, and it will be tight to it, AFAIK Symlinks only can use relative paths on same drive, and to a different drive it has to be an absolute path then it seems to me it will not be portable, also when booting on another PC new letters are assigned to the drives, and depending on partitions layout, as an example the logical partitions get first letters before primary partitions. 

 

As we usually use a WinPE when the OS has some troubles to fix it, if the drive has damaged sectors and also as you already said if the system is corrupt  your Parasite PE is not an option.

 

To motivate some member to try to build that Frankenstein PE, it will be good if you first find in wich cases it could work better than a WinPE or Wimboot install.

 

If you do not provide the possibility of some usefulness that is better than existing tools, it is a dead idea.

 

"Es un sueño guajiro" as we say in Spanish here in Mexico.  This expression applies for ideas not practical or without any usefulness, also this meaning apply: unrealizable or unlikely fantasy, utopia.

 

alacran



#25 alacran

alacran

    Platinum Member

  • .script developer
  • 2710 posts
  •  
    Mexico

Posted 03 August 2020 - 01:11 AM

But just in case you want to run your own experiment I sugest you to use Win7x86 without any program installed, as it has less files and folders that you will need to create Symlinks for.

Also I suggest to make your test on a VHD located on OS drive root, this can let you use relative paths.

Same applies if you decide to make a WinPE based on boot.wim index 2, by the way you can delete index 1 if you want to save some MBs, but a WinPE will require extensive work to add your Symlinks targets to the registry (when required), wich will not be needed on a VHD.

And you can use attached WimbootCompress.ini wich is the last modded version wimb and I have being updating since some time ago. And it has proven to be reliable and good for a Portable (7 to 10) Compact or Wimboot install thaks to this line: \Windows\System32\drivers\*.sys

All under [CompressionExclusionList] and [PrepopulateList] sections has to be real size files (if exists), all under [ExclusionList] can be omited, about [CompressionFolderList] I haven't found info of the use of this section.

I also suggest to have installed on the source OS the wofadk.sys driver and its service to start it when booting.

Suggested Procedure:

Being you so good with batch files it can be easy for you to create some lines to make Symlinks of all folders that do not content any file on WimBootCompress.ini, for those sub-folders where exist a file on WimBootCompress.ini the Symlinks will have to be for each file and latter make additional lines to copy critical files that will just overwrite its respective symlink, this approach will let you test to copy a set of notoriously critical files (in accordance with your criteria/experience) on WimBootCompress.ini but including wofadk.sys located on Windows\System32\drivers, and latter you could make a new batch file to add one more line from WimBootCompress.ini and repeat this untill you get a good booting, testing it as much as possible to make sure no more real files are required.

I think in the end you will get something very close to a Wimboot install but all pointers will be to the installed OS (we may say coupled/associated to the installed OS) not coupled/associated to the source WIM file, I estimate the real used size on disk should be arround 300 to 400 MB, and of course this will save the space required for the source WIM file, wich is about 2.5 GB if LZX compressed.

NOTE: You can NOT check the real size on disk from Win7, it has to be done from 10 or a 10 based WinPE.

alacran

Attached Files






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users