During a VDI deployment with VMware Horizon, I discovered that one of the applications in the environment was saving important user information inside the ProgramData folder. Even though the end-user was utilizing persistent disks, the ProgramData folder by default gets saved on the C-drive and would be cleared of any user-specific when utilizing a refresh or recompose.
Typically in a scenario like that it is normally to discuss adjusting licensing to VMware Horizon Enterprise edition http://www.vmware.com/products/horizon-view/compare or utilizing desktop virtualization management software developed by companies such as Liquidware Labs http://www.liquidwarelabs.com/. However, since there was only one problematic application in the environment and there were budgetary constraints, the end-user wanted to explore a more creative and budgeted solution. The solution was to for this case was to utilize symbolic links.
Understanding Symbolic Links
First, it is important to note that symbolic links (sometimes referred to as soft links) can be absolute symbolic links or relative symbolic links. Additionally, there are also hard links.
A great bullet point explanation of the two pulled from the following link has been provided below
- indistinguishable from other directory entries, because every directory entry is hard link
- “original” can be moved or deleted without breaking other hard links to the same inode
- only possible within the same filesystem
- permissions must be the same as those on the “original” (permissions are stored in the inode, not the directory entry)
- can only be made to files, not directories
Symbolic links (soft links)
- simply records that point to another file path. (ls -l will show what path a symlink points to)
- will break if original is moved or deleted. (In some cases it is actually desirable for a link to point to whatever file currently occupies a particular location)
- can point to a file in a different filesystem
- can point to a directory
- on some file system formats, it is possible for the symlink to have different permissions than the file it points to (this is uncommon)
Additionally, an example showing the difference between an Absolute Symbolic Link and Relative Symbolic Link pulled from the following forum post has been displayed below:
Example 1: Absolute Symlink
/some-folder/absolute-symlink -> /target-folder/file.txt
If you move this symlink to some other folder, this doesn’t affect the resolved path:
/some-other-folder/absolute-symlink -> /target-folder/file.txt
still resolves to
Example 2: Relative Symlink
/some-folder/relative-symlink -> target-folder/file.txt
If you move this symlink to some other folder, the resolved path will change accordingly:
/some-other-folder/relative-symlink -> target-folder/file.txt
now resolves to
Note: Some applications do not support symbolic links and some applications require a hard link. It is important to test functionality after creating a symbolic link.
Creating a Symbolic Link
For creating a Symbolic Link, our syntax will be (screenshot shown below of help menu):
mklink [[/d] | [/h] | [/j]]
Symbolic Link to Local Drive
In the example below, I am making a symbolic link for a file called test.txt.
Source File: C:ProgramDatasymboliclink-oldlocationtest.txt
Destination File: D:symboliclink-oldlocationtest.txt
Before creating the symbolic link make sure that text.txt file has been moved from the old location to the new location. If this action is not performed, an error will appear stating “cannot create a file when that file already exists” If the file is created successfully, a confirmation message will appear.
mklink “C:ProgramDatasymboliclink-oldlocationtest.txt“ “D:symboliclink-oldlocationtest.txt”
If a directory search is performed, the file will now display as a SYMLINK.
Symbolic Link to a SMB Share
Similar to the Symbolic Link to Local Drive, make sure that the file or folder already exists in the new location before creating the link. When creating a symbolic link to a SMB or CIFS share, the mapped drive or the SMB share can be utilized. Both examples have been shown below. Similar to the previous example, a directory search will display the SYMLINK.
Source File: C:ProgramDatasymboliclink-oldlocationsmb-old.txt
Destination File: P:smb-new.txt OR cifs-shareSMB-new.txt
mklink "C:ProgramDatasymboliclink-oldlocationsmb-old.txt" "P:smb-new.txt"
mklink "C:ProgramDatasymboliclink-oldlocationsmb-old.txt" "cifssharesmb-new.txt"
Application of Symbolic Links in VMware Horizon and VDI
A creative way of redirecting saved data for an application in VDI in a persistent or non-persistent disk configuration, is to utilize environmental variables (such as those listed in this article: https://technet.microsoft.com/en-us/library/cc749104%28v=ws.10%29.aspx) to redirect data to a user share or directory. It is important to make sure that the symbolic link is created on the deployed virtual machine and not the golden image as environmental variables are applied to the existing user and desktop, not the one to be deployed.
For example, if I want to have my symbolic link write to the user directory by utilizing the %USERNAME% variable and I try to create symbolic link on the golden image (in my example I logged on with the administrator account), the symbolic link is immediately created and %USERNAME% will equal administrator. To get around this, a script or GPO can be utilized to create the symbolic link after the user has logged into their persistent desktop or the linked clone.
Example code has been provided for reference.
mklink "C:ProgramDatasymboliclink-oldlocationsmb-old.txt" "cifsshare%USERNAME%smb-new.txt"
Creating Symbolic Links, https://msdn.microsoft.com/en-us/library/windows/desktop/aa363878%28v=vs.85%29.aspx. Accessed May 05, 2014
Difference between relative & absolute symbolic links?, https://forums.obdev.at/viewtopic.php?t=2764. Accessed June 10, 2015.
Mklink https://technet.microsoft.com/en-us/library/cc753194.aspx. Accessed May 05, 2014
Recognized Environment Variables, https://technet.microsoft.com/en-us/library/cc749104%28v=ws.10%29.aspx. Accessed June 10, 2015
What is the difference between symbolic and hard links?, http://unix.stackexchange.com/questions/9575/what-is-the-difference-between-symbolic-and-hard-links. Accessed June 10, 2015.
Windows 7: How to Create Symlinks (Symbolic Links), http://www.tech-recipes.com/rx/13085/windows-7-how-to-create-symlinks-symbolic-links/. Accessed May 05, 2014
Windows Environmental Variables, http://ss64.com/nt/syntax-variables.html. Accessed June 10, 2015