It is a very nice application to use, and it can even download the ISO files for you. All well and good for a small flashdrive. But what if you want to keeps these ISOs for later for a larger flashdrive or for an external HDD? And what if you want to download a whole lot of ISOs? YUMI installer will allow you to do this one by one which is not bad.
So after the first 10 ISO's you say hey, might as well sort them into their correct distributions with directories. So after a few hundred GB of downloads and sorting you have a nice collection of Linux distributions. But now you want to have all these ISO files in onle single folder for the YUMI application to detect your ISOs automatically.
What do you do?
We have some possible solutions:
Solution One: Perform a dir search of all ISO files and copy them to a single directory which takes up space but it is doable and scriptable
Solution Two: Forget the nice directory arrangement and move all the files to a single directory
Solution Three: Create hardlinks to the files to a single directory
Solution three is what I wanted. I have searched for something that I can use in Windows but decided to cobble together a script.
I created a folder named Linux-ISO-HardLinks which is a seperate folder from my collection but on the same drive. You can use whatever name that you want for the folder. Make sure you know that this folder contains hard links. It starts to become confusing as the file links are indistinguishable from the originals. Deleting a hardlink (by deleting the file name) sets the counter down by one, http://en.wikipedia.org/wiki/
A batch file named CreateLinuxISOHardLinks.bat (can also use your own filename) and set the attribute to system (more on this later):
echo "" > CreateLinuxISOHardLinks.bat
attrib +S CreateLinuxISOHardLinks.bat
So my directory structure will look like this (uing the "tree" command and some copy and pasting into notepad):
├───Linux
│ ├───Acronis Antimalware CD
│ │ AcronisAntimalwareScanCD.iso
│ ├───AntiX
│ │ antiX-12-486.iso
│ └───archlinux
│ archlinux-2012.10.06-dual.iso
└───Linux-ISO-HardLink
CreateLinuxISOHardLinks.bat
And the script for the hardlink creation is below:
- del /A:-S *.* /Q
- for /f "delims=" %%a in ('Dir /s /b ..\Linux\*.ISO') do echo fsutil hardlink create "%%~nxa" "..\..\..%%~pa%%~nxa" >>output.txt & fsutil hardlink create "%%~nxa" "..\..\..%%~pa%%~nxa" 1>> output.txt 2>>&1
- copy ..\YUMI-0.0.7.7.exe .\
The first line deletes all the current hard link files except for your batch file which is a system file (which we had set earlier on). We want to delete the files to clean up the directory and start from fresh. Remember, if we delete the source ISO files in your Linux folder, the files will still exist until this folder is cleaned. Be very careful with this!!!!
The second line is the core hardlink generation script. Inside the for loop, a dir is run for all the .ISO files in the Linux directory. This command returns a list of the full path of each ISO file.
- 'Dir /s /b ..\Linux\*.ISO'
So for each result in our dir comamnd we execute the commands in the do part of the loop. Firstly we echo the command to be run to an output file (for debugging purposes).
- do echo fsutil hardlink create "%%~nxa" "..\..\..%%~pa%%~nxa" >>output.txt
Followed by an & symbol to seperate the commands, we then execute the hard link command with outputs from both stdout and stderr to the same outputfile.
The regular expressions "%%~nxa" is the name of the file alone and the "..\..\..%%~pa%%~nxa" is a manipulation of relative paths to get the actual file to link to (Remember the directory structure above).
- & fsutil hardlink create "%%~nxa" "..\..\..%%~pa%%~nxa" 1>> output.txt 2>>&1
The neat thing is that the do command is run for each result of the dir command thus putting the correct sequence of events into your output file for debugging. Works well for duplicate ISO files which you can clean up later on. I tried this on an external HDD which worked well.
Other Uses for this script with modifications:
This can be used to take your entire movie or music collection and place them in a single folder for sharing or streaming. http://www.mede8erforum.com/index.php?topic=5335.5;wap2
Summary:
Hardlinking solves the space problem instead of duplicating files.
***** DISCLAIMER *****
Do this at your own risk!!! Do not try this on a drive that you are not so sure of nor on your system drive. The delete command is the most dangerous so be careful of the paths that you are using!!!
Some references that I used to create the script in addition to the for /? command:
http://en.wikipedia.org/wiki/
http://www.microsoft.com/
http://superuser.com/
http://stackoverflow.com/