Recipe3.4.Formatting a Volume


Recipe 3.4. Formatting a Volume

Problem

You want to reformat an existing volume or initialize a new one.

Solution

Using a graphical user interface

  1. Open Windows Explorer.

  2. Right-click on the drive letter for the volume you want to format and select Format.

  3. Leave NTFS selected for File system unless you have a very good reason to use FAT32. The same goes for the Allocation unit size; use the default selected unless you have a good reason.

  4. Type a description under Volume label.

  5. Check the box beside Quick Format if you've previously formatted the volume with the same filesystem and just want to delete the file table (i.e., links to all the files and folders).

  6. Check the box beside Enable Compression if you want to compress the contents of the volume.

  7. Click Start.

Using a command-line interface

The following command formats the D: drive using NTFS and sets the volume label to Data:

> format D: /fs:ntfs /v:Data

You will be prompted to enter the current label of the D: drive. Type it in and press Enter. Then you'll be asked for confirmation to continue by typing Y and pressing Enter.

Add the /q option to the previous command line to perform a quick format and add the /c option to enable compression on the volume. You can use the /x option to force a dismount in case someone has a handle open on the volume.

Using VBScript
' This code formats a volume. ' The Win32_Volume class is new in Windows Server 2003. ' ------ SCRIPT CONFIGURATION ------ strComputer = "<Server>" strDrive = "<Drive>"  ' e.g., D:     strFS = "NTFS" boolQuick = False intClusterSize = 4096 strLabel = "Data" boolCompress = False ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colVol = objWMI.ExecQuery("select * from Win32_Volume where Name = '" & _                               strDrive & "\\'") if colVol.Count <> 1 then    WScript.Echo "Error: Volume not found." else    for each objVol in colVol       intRC = objVol.Format(strFS,boolQuick,intClusterSize, _                             strLabel,boolCompress)       if intRC <> 0 then          WScript.Echo "Error formatting volume: " & intRC       else          WScript.Echo "Successfully set formatted volume."       end if    next  end if

Discussion

Before you can use a volume, you first need to format it with a filesystem. On Windows 2000 and Windows Server 2003, you can format a volume with FAT, FAT32, or NTFS. Unless you have a good reason, you should use NTFS due to its increased security features.

Another option when formatting a volume is whether to perform a quick format or normal format. Both options erase the table that tracks file locations on the filesystem. The difference is that a normal format will scan the entire volume for bad sectors. This scan is responsible for most of the time required to do a format. A quick format bypasses this, so you should only use it when the volume has been previously formatted with a filesystem and you are confident the disk isn't damaged.

You can also enable compression on a newly formatted volume. See Recipe 3.9 for more on the effects of compression.

See Also

MS KB 140365 (Default Cluster Size for FAT and NTFS) and MS KB 313348 (How to partition and format a hard disk in Windows XP)



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net