Mr. Script

Build a Better NTFS Converter

Help for working through the steps.

I recently replaced the hard drive in my notebook computer. I just love getting new hardware! My new drive is faster (5,400 RPM as opposed to 4,800), larger by 10GB and quieter. I also doubled my RAM to 1GB.When my new drive arrived, I used a USB 2.0 hard drive upgrade kit to clone my existing drive to my new one. This process was, to coin a phrase, dead sexy! If you ever need to upgrade your notebook hard drive, go this route. It’s a lot easier than re-installing everything on the new drive.

My point in telling this story (and it’s equally valuable to desktop hard drive upgrades, as well) is that I was able to convert my file system to NTFS. You might say, “Well, that’s easy,” and you’d be right. Sure, I could have done it at any time, just by using CONVERT.EXE. But there are issues with converting a file system to NTFS that don’t arise when you format one from scratch. I wanted to work through those issues, and now I had a complete backup of my notebook drive, just in case. If anything went wrong, all I had to do was replace the new drive with the old one and start over. There’s tremendous freedom in having that kind of safety.

NTFS Is Good
Any administrator worth his or her salt can enumerate the benefits of NTFS. First and foremost, it’s secure. This is particularly important on notebook computers. I have documents and spreadsheets on my computer that I’d like to keep secure. With FAT32, all an intruder needs is a DOS boot disk and access to my computer to see everything. NTFS also supports encryption, compression, quotas and more. Finally, when properly tweaked, NTFS is faster.

Converting to NTFS Is Bad
As I said, there are issues that arise when converting to NTFS. Most notable among them is fragmentation of the Master File Table (MFT). The CONVERT utility creates this MFT on the drive during the conversion process. Even if you defrag your hard drive immediately prior to running CONVERT, there’s no guarantee that the MFT will occupy a contiguous area of the drive. Because the MFT is used for every file access operation (indeed, many files are stored in the MFT in their entirety), a fragmented MFT can really affect performance.

In light of these challenges, I created a process to convert a FAT or FAT32 file system to NTFS while circumventing or eliminating most of the pitfalls. And I’ve written a script to automate the entire process. This may not seem like much of a timesaver if you’re just upgrading your own computer, but if those 20 new workstations that just arrived pre-loaded with Windows XP on FAT32 hard drives need NTFS, you have two choices if you want to extract anything resembling acceptable performance and security: Run this script or rebuild them from scratch.

The Process
First, I explain each step in the process and why it’s important. Next, we look at the script. Finally, there’s an additional tweak you can use to squeeze even more performance out of your conversion.

Before we get started, one final point: This conversion method only works on Windows XP/Windows 2003 because the most important step—using a CvtArea—is only supported in the XP/Windows 2003 version of CONVERT.EXE.

1. Reserve an area for the MFT. To prevent the MFT from being created in a fragmented state, we need to set aside an area of contiguous space—referred to by CONVERT.EXE as the CvtArea—on the drive. The size of this file should be at least the total number of files and folders that exist on your drive multiplied by 1,024. (It doesn’t hurt to add some “buffer zone.”) So, if we have 9,000 files and 1,000 folders, the file would be 10,240,000 bytes in size. We use the FSUtil program to create the file.

C:\>fsutil file createnew MFTArea.txt 10240000

Note: This file must be in the root of the C: drive.

2. Ensure that the file is contiguous. SysInternals has a free utility called Contig.exe that will defragment a single file. You can download it at www.sysinternals.com/files/contig.zip.

Extract it to a folder that’s in your path, then “defrag” the MFTArea.txt file:

C:\>contig mftarea.txt

3. Run the CONVERT utility:

C:\>convert c: /FS:NTFS /CvtArea:MFTArea.txt

And now, the script:

<package>
<comment>
SmartConvert.wsf
Converts file system to NTFS using /CvtArea
flag to avoid MFT fragmentation
</comment>

  <job>
   <object id="
objFSO" progid="Scripting.FileSystemObject"/>
   <object id="
objShell" progid="WScript.Shell"/>
   <script language="
VBScript">
   Dim objDrive, objFolder, objWMI
   Dim strVolume, colOS, clsOS
   Dim iFilesFolders, iCvtArea

   'Get the drive volume info
   Set objDrive=objFSO.GetDrive("c:")
   strVolume=objDrive.VolumeName
   If objDrive.FileSystem="NTFS" Then
   WScript.Echo "File system already NTFS"
   WScript.Quit
   End If

   'Get the root folder
   set objFolder=objFSO.GetFolder("c:\")

   'Count total files and folders
   iFilesFolders=0
   WScript.Echo "Calculating size of CvtArea..."
   CountFilesAndFolders objFolder
   iCvtArea=iFilesFolders*1024

   'Add 20MB to CvtArea for buffer
   iCvtArea=iCvtArea+20480000

   'Create CvtArea file
   WScript.Echo "Creating file for CvtArea..."
   objShell.Run _
     "fsutil file createnew c:\MFTArea.txt " & iCvtArea,,True
   WScript.Echo "File: c:\MFTArea.txt created"

   'Make file contiguous
   WScript.Echo "Making CvtArea file contiguous..."
   objShell.Run "contig c:\MFTArea.txt",,True
   WScript.Echo "File Is contiguous"

   'Convert file system to NTFS
   WScript.Echo "Enter volume label when prompted"
   WScript.Echo "Volume label is: " & strVolume
   objShell.Run _
     "convert c: /FS:NTFS /CvtArea:MFTArea.txt"

   'Reboot computer to begin conversion
      Set objWMI=GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate,(Shutdown)} " _
      & "!\\.\root\cimv2")
      Set colOS=objWMI.ExecQuery _
        ("Select * from Win32_OperatingSystem")
      For Each clsOS in colOS
        clsOS.Reboot()
      Next

      Sub CountFilesAndFolders (objFol)
        Dim iCount, clsFolder
        iCount=objFol.Files.Count+objFol.SubFolders.Count
        iFilesFolders=iFilesFolders + iCount
        For Each clsFolder In objFol.SubFolders
          CountFilesAndFolders (clsFolder)
        Next
     End Sub
     </script>
  </job>
</package>

The script essentially takes us through the steps for converting the drive. In its current state, it still requires a bit of user interaction—such as entering the Volume name of the drive. Still, when converting many drives at once, it can really save some time.

Making it Better
While utilizing the above method will provide much better performance than a simple “raw” conversion to NTFS, there’s still one area where we can improve things: Cluster size. The CONVERT utility automatically sets the cluster size to 512 bytes. While this cuts down on wasted disk space, it also leads to increased file fragmentation. A cluster size of 4K is generally considered optimal for most uses. Unfortunately, there isn’t a built-in or free utility that can perform this task. You’ll need to purchase a partition management tool, such as PowerQuest’s PartitionMagic, and resize the clusters to 4K (or whichever size works best in your environment).

Congratulations! You now have a finely tuned, smooth-running, secure file system.

About the Author

Chris Brooke, MCSE, is a contributing editor for Redmond magazine and director of enterprise technology for ComponentSource. He specializes in development, integration services and network/Internet administration. Send questions or your favorite scripts to [email protected].

comments powered by Disqus
Most   Popular