This is not a question, I have done it. I just want to post a little howto in case anyone runs into a similar problem.
I will not go into particular details, just the rough description. If need details on something, I'll be happy to explain the part in question.
Scenario:
I am working on linux for almost a decade now. However, there are some things that need to be done on windows, like gaming (ATI drivers for linux are still a bit tricky, especially for newer cards) or rs232 (serial port) based apps (old smartphone management, PIC or ATMega Programming, old graphic calculator like TI92 etc.).
So in short, I had once set up a windows system. I wanted to use my files both under linux and windows. The solution for this problem is obvious: I used a NTFS partition I could mount under both OS.
Since I am a security concerned citizen, I use to encrypt my disks. However I refused using Vista and Win7 hadn't come out yet, so I was running XP64. The opensource LUKS tools didn't work on that system (driver issues), so I used Truecrypt.
Some time ago, I abandoned the windows partition after a fault in the MBR, which rendered the Truecrypt bootloader unusable (yes, even with the rescue disc). Since I rarely have to time play games anymore, that's not a major concern. The rest of the tasks can be handled using a virtual machine (in my case Sun's VirtualBox).
So, after about 10 months, I had ended up with a severely fragmented, Truecrypt encrypted NTFS partition which badly needed defragmenting. Linux NTFS-3G drivers have become fairly reliable, but their reliabality decreases as the filesystem fragmentation increases. And the only OS which can defragment a filesystem of this time is windows NT.
Procedure:
The basic underlying problem is that you need to access your raw device from a windows system that by itself lives in an isolated virtual environment. The SMB/CIFS shares are ok to access data, but NAS Filesystems rely on the servers filesystem and cannot be defragmented.
What can be defragmented is a SAN share (iSCSI target), because the protocol by itself forwards the device to the host over a network, not the filesystem.
(1)
So first of, make sure you have a virtual machine running windows somewhere. it actually doesn't need to be virtual, it can be a remote computer on the same subnet, but in my case, it is a virtual machine. As I said, I used VirtualBox.
(2)
Next make sure the Windows box has access to the same network as your linux host. In VirtualBox I used a network interface in NAT mode. I suppose you could also juggle a second loopback device around on the linux host to fulfill the same purpose and keep the windows box of the public network if that is a concern.
(2.5)
If you have encrypted your NTFS partition, you need to decrypt it (not mount it!). Using LUKS, use the cryptsetup command to create a decrypted alias of the partition. If you have used Truecrypt, use it's frontend to mount the partition as you would if you wanted to access data, then unmount the alias from its final mountpoint, thus leaving the unencrypted frontend to the partition intact.
So now you have:
- A linux host with a fragmented NTFS partition (which might be encrypted) that is not mounted.
- A windows machine (either virtual or remote) with access to the same subnet as your linux host.
(3)
Next you need to setup your unencrypted partition alias as an iSCSI target. I used open-iscsi (
http://iscsitarget.sourceforge.net/). In the config file (/etc/ietd.conf), I used the following line:
Code:
Target iqn.2010-01.zw41c:disk1.part5.ntfs
Lun 0 Path=/dev/mapper/truecrypt1,Type=fileio
I will not go into iscsi details here as the topic is a bit elaborate. I hope the code fragment above is sufficient to show the concept. If you use a GUI (Suse provides one for Yast2), this task is simplified.
Start the iSCSI target daemon (in my case ietd). You can confirm that it works by detecting iscsi hosts with your initiator.
Note to those who use a second windows computer (not a virtual machine!) for this task: If you are not the only one on your network, seriously consider using a password an/or ssl tunnel! otherwise your raw hard disk partition is accessible to anyone - There are no access limits! They could simply format the whole thin! Also, reconfigure your firewall to allow access to the iscsi daemon (default tcp port should be 3650).
(4)
Next we need to enable iscsi initiator capabilities in windows. Though Microsoft never made a big hype about it, it is fairly common on servers and available to desktop windows versions. the software can be found here:
http://www.microsoft.com/downloads/d...displaylang=en
Download and install the appropriate version on your windows box. After that, you should be able to access your iscsi target using the GUI - which supprisingly is quite straight forward and self explanatory. Just Click on "Discovery"->"Add", enter the data of your linux host, confirm, let it scan, goto "Targets", open "Details" on your linux hosts target, select the drive and confirm.
(5)
If everything went ok, your explorer should now show your ntfs partition as a local drive.
And voila, defragment it! Just rightclick -> defragment or use the software of your choice.
A word of warning (again): make sure your linux host has no access to the ntfs partition when you defragment it! I do not even want to imagine how severely that might confuse the ntfs module! UNMOUNT THE PARTITION!
This procedure worked flawlessly on my host. I would be thankful if someone who tried this could give me some feedback if I was just lucky or if it really this easy.
Hope this helps
Cheers