1. Improving Disk Access Performance with the Defrag Utility
As your hard drive
processes files, it becomes fragmented; a file may appear in several
segments on the hard drive. Moving the disk head to read each of these
file segments is time consuming and hurts the performance of your
system. Windows provides a graphical interface for defragmenting your
hard drive, but using the command line interface can be more efficient,
especially when you automate the process so that it starts
automatically. This utility uses the following syntax:
defrag <volume> -a [-v]
defrag <volume> [{-r | -w}] [-f] [-v]
defrag -c [{-r | -w}] [-f] [-v]
The following list describes each of the command line arguments.
volume Specifies the drive letter or mount point to defragment.
-a Performs only an
analysis of the drive. The analysis tells you whether the drive requires
defragmentation, but doesn't actually perform the task. The output
information includes the fragmentation percentage, which you can use as
an indicator of drive condition. Don't use this command line option when
you want to automate the defragmentation process.
-f Forces a
defragmentation, even if the drive or mount point free space is low.
Normally, the Defrag utility requires 15 percent free space to perform a
complete defragmentation. Using this command line switch lets you
perform a partial defragmentation when the free space is less than
optimal.
-v Displays additional information about the defragmentation process.
-r Performs a partial
defragmentation, which runs faster, but doesn't assure the hard drive
will run at peak efficiency. Defrag only consolidates fragments smaller
than 64 MB. This is the default setting under Server Core.
-w Performs a
full defragmentation of the drive regardless of fragment size. Although
this option can improve performance on heavily fragmented drives, you
pay a penalty in additional defragmentation time.
-c Performs defragmentation of all drives on the system. Combine this command line switch with the -w or -r command line switch to specify the level of defragmentation.
2. Managing Partitions with the DiskPart Command
The DiskPart command
lets you manage partitions on your hard drive without relying on the
graphical utilities. In some cases, this utility is your only resource
when the graphical environment isn't running and you need to make a
repair. You can use DiskPart with direct command line input or supply a
text file containing a script of actions for DiskPart to perform. You'll
usually have a better experience with DiskPart if you create a script
to perform the required tasks. Using a script reduces the potential for
error. To use a script, type DiskPart /s
ScriptName and press Enter. Otherwise, start the command line version of DiskPart by typing DiskPart and pressing Enter. You'll see the DISKPART> prompt where you enter the specific subcommands described in the following list.
active Marks the partition
with focus as active. Making a partition active informs the Basic
Input/Output System (BIOS) or Extensible Firmware Interface (EFI) that
the partition is a valid system partition that the system can use to
boot. If you mark a partition that doesn't contain system files active,
the system may not boot. DiskPart doesn't check your partition selection
for accuracy.
add disk=n [noerr] Mirrors a simple
volume with the focus set to the specified disk. The disk must contain
enough unallocated space to match the size of the simple volume that you
want to mirror.
NOTE
Use the noerr option only with scripts. Normally, a script ends when it encounters an error. Using the noerr option lets the script continue running.
assign [{letter=D | mount=Path}] [noerr] Assigns a drive
letter or mount point to the volume with focus. If you don't specify a
drive letter or mount point, the utility uses the next available drive
letter. The utility generates an error when you attempt to assign an
existing drive letter to the volume. The system won't allow you to
assign drive letters to system volumes, boot volumes, or volumes that
contain the paging file. In addition, you can't assign a drive letter to
an Original Equipment Manufacturer (OEM) partition or any GUID
Partition Table (GPT) partition other than a basic data partition.
attributes volume [{set | clear}] [{hidden | readonly | nodefaultdriveletter | shadowcopy}] [noerr]
Displays, sets, or
clears attributes on the specified volume. This command is only
available on Windows 2003 and above systems. Use attributes with a
volume specification alone to see the attributes for that volume. The
set option adds an attribute, while the clear option removes the
attribute. The hidden attribute hides the volume from view, while the readonly attribute makes it impossible for the user to write to the volume. The nodefaultdriveletter
attribute prevents the drive from receiving a drive letter during the
boot cycle. Generally, there isn't a good reason to use this feature
unless you want to create an invisible drive for a specific reason, such
as a ghost backup of the system. The shadowcopy
attribute defines the drive as a shadow copy of another drive.
automount [enable] [disable] [scrub] [noerr] Defines
the automatic mounting functionality that Windows provides. Normally,
Windows automatically mounts any new basic disks that it finds during
the boot cycle. The enable option enables automatic basic disk mounting. The disable option disables the automatic mounting feature. The scrub
object removes any mount point directories and registry settings for
volumes that are no longer in the system. This feature ensures that each
new drive that you mount or remount receives a clean setup and that
Windows doesn't attempt to use old and possibly incorrect settings. This
command is only available on Windows 2003 and above systems.
break disk disk=N [nokeep] [noerr] Breaks mirrored
volumes into two simple volumes. You can only use this command with
dynamic disks. The first disk in the set retains the current drive
letter and any mount points. The second disk receives the focus so that
you can assign it a new drive letter. The nokeep
option tells the utility to free any data on the second disk. The
second disk becomes a new empty disk that you can format and use as a
simple volume.
clean [all] Removes the
partition and volume formatting on the disk with focus. The system
overwrites the Master Boot Record (MBR) partitioning information and
hidden section information on MBR disks. The system overwrites the GPT
partitioning information, including the Protective MBR, on GPT disks. A
GPT disk doesn't include hidden sector information. The system
completely erases the disk when you use the all option.
convert basic [noerr] Converts an empty dynamic disk into a basic disk.
NOTE
The system won't
convert a disk that has data on it. Back up the hard drive data and
remove the partitions and volumes before you perform a conversion. This
same note holds true for any conversion you want to perform.
convert dynamic [noerr] Converts an empty basic disk into a dynamic disk.
convert gpt [noerr] Converts an empty
basic disk that relies on the MBR partition style into an empty basic
disk that relies on the GPT partition style.
convert mbr [noerr] Converts an empty
basic disk that relies on the GPT partition style into an empty basic
disk that relies on the MBR partition style.
create partition efi [size=N] [offset=N] [noerr] Creates an EFI
partition on a GPT disk. You must have an Itanium computer to use this
feature. The utility gives the new partition the focus once the system
creates it. The size argument defines the size of the partition in
megabytes. The utility uses all of the free space on the disk when you
don't specify this option. The offset argument defines the byte offset
of the new partition. If you don't specify an offset, the utility
creates the partition at the beginning of the first disk extant that's
large enough to hold it.
create partition extended [size=N] [offset=N] [noerr] Creates an
extended partition on the current drive. The utility gives the new
partition the focus once the system creates it. A disk can only have one
extended partition. You must create an extended partition before you
can create logical drives. The size argument defines the size of the
partition. For example, if you specify a size of 500 MB, the system
rounds the size of the partition up to 504 MB. The system uses all of
the free space on the disk when you don't define a partition size. The
offset only affects MBR disks. The offset defines the byte offset of the
partition. If you don't specify an offset, the partition begins at the
beginning of the free space on the disk. The system snaps the partition
size to the cylinder size; it rounds the offset to the closest cylinder
boundary. For example, if you specify an offset that's 27 MB and the
cylinder size is 8 MB, the system rounds the offset to the 24 MB
boundary.
create partition logical [size=N] [offset=N] [noerr] Creates a logical
disk within an extended partition. The utility gives the new partition
the focus once the system creates it. The system snaps the partition
size to the cylinder size. For example, if you specify a size of 500 MB,
the system rounds up the size of the partition to 504 MB. The system
uses all of the free space on the disk when you don't define a partition
size. The offset only affects MBR disks. The offset defines the byte
offset of the partition. If you don't specify an offset, the partition
begins at the beginning of the extended partition. The offset you
specify must allow enough room for the partition defined by the size
argument. If the offset won't allow enough space, the system changes the
offset so that the logical disk can fit within the extended partition.
create partition msr [size=N] [offset=N] [noerr] Creates a Microsoft
Reserved (MSR) partition on a GPT disk. The size argument defines the
size of the partition in MB. The utility uses all of the free space on
the disk when you don't specify this option. The offset argument defines
the byte offset of the new partition. If you don't specify an offset,
the utility creates the partition at the beginning of the first disk
extant that's large enough to hold it. The offset is sector snapped. The
system rounds up the value of the offset to fill an entire sector.
MSR partitions can
cause a number of problems. The most significant problem is that Itanium
computers won't mount an MSR partition. This means you can't store data
on the partition or delete it; the partition ends up wasting space on
the disk. In addition, GTP disks require a specific partition layout.
Adding an MSR partition could disrupt the layout and make the disk
unreadable. On GPT disks used to start Windows XP 64-bit Edition
(Itanium), the EFI System partition is the first partition on the disk,
followed by the MSR partition. GPT disks used only for data storage
don't have an EFI System partition; the MSR partition is the first
partition.
|
|
create partition primary[size=N] [offset=N] [ID={Byte | GUID}] [align=N] [noerr]
Creates a
primary partition on a disk. The utility gives the new partition the
focus once the system creates it. The system snaps the partition size to
the cylinder size. For example, if you specify a size of 500 MB, the
system rounds up the size of the partition to 504 MB. The system uses
all of the free space on the disk when you don't define a partition
size. The offset only affects MBR disks. The offset defines the byte
offset of the partition. If you don't specify an offset, the partition
begins at the beginning of the extended partition. The offset you
specify must allow enough room for the partition defined by the size
argument. Microsoft sets the ID argument aside for OEMs. Never specify
an ID for a GPT disk. Use the create partition EFI and create partition
MSR as needed to set up GPT disks. When working with an MBR disk, you
can use the ID to set the disk type. The MBR values include
C12A7328-F81F-11D2-BA4B-00A0C93EC93B (EFI system partition),
E3C9E316-0B5C-4DB8-817D-F92DF00215AE (MSR partition),
EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 (basic data partition),
5808C8AA-7E8F-42E0-85D2-E1E90434CFB3 (LDM Metadata partition on a
dynamic disk), and AF9B60A0-1431-4F62-BC68-3311714A69AD (LDM Data
partition on a dynamic disk). The align
argument specifies the alignment of the primary partition on a disk
that isn't cylinder aligned. You normally use this value for hardware
Redundant Array of Inexpensive Disks (RAID) setups to improve
performance. The value is the number of kilobytes from the beginning of
the disk to the closest alignment boundary.
create volume raid [size=N] disk=N,N,N[,N,...] [noerr] Creates a RAID-5
volume based on three or more dynamic disks. The utility automatically
changes focus to the new volume once the system creates it. The size
argument specifies the amount of space that the RAID-5 volume consumes
on each drive. When you don't specify the size, the utility creates the
largest possible RAID-5 volume by using the maximum space on the
smallest volume (or the maximum available space when the drives are the
same size). The RAID-5 volume consumes the same amount of space on each
disk. The disk argument defines which
disks to use in the RAID-5 volume. The volume must contain at least
three drives simply because of the way that RAID-5 works.
create volume simple [size=N] [disk=N] [noerr] Creates a
simple volume. The utility automatically changes focus to the new volume
once the system creates it. The size argument defines the size of the
volume in megabytes. The utility uses the entire free space on the disk
when you don't specify the size argument. The disk argument specifies
the disk to receive the new volume. The utility uses the current disk
when you don't specify the disk option.
create volume stripe [size=N] disk=N,N[,N,...] [noerr] Creates a
striped volume using two or more dynamic disks. The utility
automatically changes focus to the new volume once the system creates
it. The size argument defines the amount
of space the volume consumes on each drive. Every drive provides
precisely the same amount of space toward the total volume size. The
system uses all of the free space on the smallest drive when you don't
provide the size argument. The disk argument specifies the drives to use to create the striped set. You must provide a minimum of two drives for a striped set.
delete disk [noerr] [override] Removes a missing
dynamic disk from the disk list. The override option enables DiskPart to
remove all of the simple volumes on a disk. When the disk contains half
a mirrored volume, the system removes the half of the mirrored volume.
This command fails on RAID-5 volumes.
delete partition [noerr] [override] Removes the
partition with focus from the drive. You can't delete the system
partition, boot partition, or any partition that contains the active
paging file or crash dump (memory dump). Use the override argument to
allow DiskPart to remove partitions of any type on a drive. Normally,
DiskPart removes only data partitions from the drive.
Deleting a partition on a
dynamic disk could delete all of the volumes on the disk and leave the
disk in an unusable state. Always remove volumes on a dynamic disk using
the delete volume command.
|
|
delete volume [noerr] Deletes the volume
with focus from the drive. You can't delete the system volume, boot
volume, or any volume that contains the active paging file or crash dump
(memory dump).
detail disk Displays the properties of the disk with focus. In addition, this command shows any volumes on the disk.
detail partition Displays the properties of the partition with focus.
detail volume Displays the disks on
which the current volume resides. You can use this command with a
volume that spans multiple disks, such as a mirrored, striped, or RAID-5
volume.
exit Terminates the DiskPart session.
extend [size=N] [disk=N] [noerr] Extends the
currently selected volume into the next contiguous unallocated space.
The unallocated space must appear on the same disk. The unallocated
space must also appear after the current partition; the sector number of
the unallocated space must be higher than the sector number of the
currently selected volume. This command only works for NTFS-formatted
volumes. The size argument defines the amount of space to add to the current partition. If you don't specify the size argument, the system uses all of the contiguous unallocated space. The disk
argument applies to dynamic disks. Use this argument to specify the
dynamic disk to use to extend the volume. If you don't specify the disk argument, the system uses the current disk.
gpt attributes= NApplies the
specified attributes to a GPT disk. The GPT attribute field is 64-bits
long and contains two subfields. The higher subfield applies only to
partition identifiers; the lower subfield applies to all identifiers.
Currently, the file system only supports two attributes. The 0x0000000000000001
attribute defines a required partition. Adding this attribute means
that disk utilities won't delete the partition for any reason. The 0x8000000000000000
attribute tells the system not to automatically assign the drive a
drive letter. The main purpose for this attribute is to ensure the
system won't automatically assign a drive letter when you move the drive
to another machine. Using this feature allows the user of the other
machine to assign a drive letter based on that machine's configuration.
This command is only available on Windows 2003 and above systems.
help Displays a list of DiskPart commands.
import [noerr] Imports a foreign
disk group into the local computer's disk group. This command imports
every disk that's in the same group as the disk that has focus.
inactive Marks the current
MBR disk partition inactive, which means you can no longer boot from
the partition. When the computer reboots, the system starts using the
next available boot option specified in the BIOS, such as a CD-ROM drive
or a Pre-Boot eXecution Environment (PXE)–based boot environment. A PXE
can include Remote Installation Services (RIS). Some computers won't
restart without an active partition, so use this command with care. If
you're unable to start your computer after marking the system or boot
partition as inactive, insert the Setup CD in the CD-ROM drive, restart
the computer, and repair the partition using the FixMBR and FixBoot
utilities from the Recovery Console.
list disk Lists the disks
installed and detected for the current machine. The output includes the
disk number, disk status, total disk size, amount of free space,
whether the disk is basic or dynamic, and the GPT style. The disk with
the asterisk (*) is the one with focus.
list partition Lists the
partitions for the currently selected disk. The output includes the
partition number, the partition size, the partition type, and the offset
of the partition from the beginning of the disk. On dynamic disks,
these partitions may not correspond to the dynamic volumes on the disk.
This discrepancy occurs because dynamic disks contain entries in the
partition table for the system volume or boot volume (if present on the
disk). The partition with the asterisk (*) is the one with focus.
list volume Lists the volumes
on all disks for the current machine. The output includes the volume
number, the volume drive letter, the volume label, the file system used
to support the volume, the volume type (such as partition, DVD-ROM, or
CD-ROM), the volume size, the volume status, and information about the
volume purpose (such as a system or a boot drive). The volume with the
asterisk (*) is the one with focus.
online [noerr] Brings the offline volume with focus online. This command also resynchronizes the mirrored or RAID-5 volume.
rem Provides a means for making comments in scripts. You won't use this command in interactive mode.
remove [{letter=D | mount=Path | all}] [dismount] [noerr] Removes a drive
letter or mount point from the drive with focus. If you don't specify a
drive letter or mount point, the utility removes the first drive letter
or mount point that it encounters. The letter option specifies the drive letter that you want to remove. The mount option specifies the path of the mount point that you want to remove. Use the all option to remove all of the drive letters and mount paths for a drive. The dismount
option takes the drive offline when it no longer has any drive letters
or mount points assigned to it. You can't access a dismounted drive. You
can't remove the drive letters on system, boot, or paging volumes, OEM
partition, any GPT partition with an unrecognized GUID, or any of the
special, nondata, GPT partitions such as the EFI system partition.
repair disk=N [noerr] Repairs the RAID-5
volume with focus by replacing a failed RAID-5 member with the
specified dynamic disk. The new disk must have free space equal to or
greater than the disk that it replaces.
rescan Locates any new disks that you've added to the computer.
retain Prepares an existing
simple volume for use as a boot or system volume. When working with an
MBR disk, the utility adds the partition entry to the MBR. The dynamic
system volume must begin at a cylinder-aligned offset and be an integral
number of cylinders in size. When working with a GPT disk, the utility
creates a partition entry in the GPT.
select disk [=n]Selects the specified disk and gives it focus. If you don't provide a number, the utility lists the drive that has the focus.
select partition [=n]Selects the
specified partition and gives it focus. If you don't provide a number,
the utility lists the partition that has the focus.
select volume[={n | d }] Selects the
specified volume and gives it focus. You may provide either a volume
number or a drive letter as input. If you don't provide a number or
letter, the utility lists the volume that has the focus.
|