Disk Operations in Server Core

Reading Time: 7 minutes

Sometimes a Windows disk encounters an error. Luckily it doesn't happen a lot. A Windows-equipped hard disk is bound to become fragmented. Bits and bytes are placed, deleted and moved across the drive and is in the end effectively bringing your beloved Server Core box to a standstill. In fact: after installation the drive is already fragmented, which is not a good sign if you want to use it to create multiple virtual machines from it using differencing disks.

Time to look at disk operations in Server Core. I'll start with looking at disks and continue with managing partitions and volumes. Drives, that can actually be used in Windows can be placed on partitions and volumes, so these get a quick look too.

 

Working with disks

Converting

Windows Server offers two types of disks: Basic disks and Dynamic disks. By default Windows Server 2008 installs on a basic disk.

Basic disks follow the PC BIOS rules, containing up to four partitions. Each of them can be a primary partition and at most one can be an extended one. All these partitions are described by 16-byte entries that constitute the Partition Table which is (normally) located in the Master Boot Record. Dynamic disks, introduced in Windows 2000, can hold any number of simple volumes, spanned volumes, mirrored volumes, striped volumes, and RAID-5 volumes.

With dynamic disks, you can have more volumes and perform disk and volume management without having to restart the operating system, but you will no longer be able to boot Operating Systems that don't support dynamic disks, like Windows 9x and Windows NT4.

Converting your first disk to dynamic can be done using the following commands:

diskpart.exe
DISKPART> select disk 0
DISKPART> convert dynamic
DISKPART> exit

Using the list disk command inside the diskpart.exe context shows you the disks in your Server Core box. This enables you to select the right disk to convert.

You can also convert an empty dynamic disk (a dynamic disk without any volumes on it) back to a basic disk. Use convert basic instead of convert dynamic inside the diskpart.exe context to achieve this.

 

Working with volumes,partitions

Creating

On a basic disk you can create partitions. On dynamic disks you can create volumes.

Tip!
after selecting a disk (select disk) in the diskpart.exe context and using the disk detail  command, you can view details on the disk and the partitions/volumes on it.

Partitions

You can create two types of partitions: primary partitions and extended partitions. Inside extended partitions you can create logical partitions. The command to do this in is diskpart.exe again. The commands to create these partitions inside the diskpart.exe context are:

create partition primary
create partition extended
create partition logical

You can provide optional size= and offset= parameters to prevent the commands from slurping up every available unused byte on the disk. The values of these parameters are interpreted in MegaBytes (MBs).

Example:

diskpart.exe
DISKPART> select disk 0
DISKPART> create partition primary size=1539
DISKPART> exit

This command will create a primary partition in unused space on a basic disk, 1539 MB in size (displaying as 3,00 GB)

Volumes

You can create three types of volumes on dynamic disks: Simple volumes, striped volumes and RAID5 volumes. Simple volumes resemble primary partitions: they reside on one disk. Striped volumes offer RAID0 functionality and use space on 2 dynamic disks. RAID5 disks can use space on a minimum of three dynamic disks, offering fault tolerance.

The commands to create these volumess inside the diskpart.exe context are:

create volume simple
create volume stripe
create volume raid

For the create volume stripe and create volume raid commands you need to use the disk= parameter to provide the IDs of the disks to use, separated by commas.

You can provide optional size= parameter to prevent the commands from slurping up every available unused space on the disk. The values of these parameters are interpreted in MegaBytes (MBs).

Example:

diskpart.exe
DISKPART> create volume raid size=20483 disk=1,2,3
DISKPART> exit

This command will create a RAID5 volume in unused space on a dynamic disks with IDs 1, 2, and 3, 1539 MB in size (displaying as 3,00 GB)

Shrinking

On both basic and dynamic disks you can shrink partitions/volumes inside the diskpart.exe context. This allows you to use free space inside a partition or volume and make it into unused space on a disk, so you can create new volumes/partitions.

While this command sounds exciting, a couple of requirements exist:

  • The volume/partition must be formatted using NTFS
  • The command does not work on RAID5 volumes

You can use this command in three ways: You can use it without any parameters, with the desired= parameter and with both the desired= and minimum= parameters.

  • When used without parameters the selected volume/partition will be shrunk with the maximum amount, eating away all free space in the partition/volume. This is potentially dangerous to your system when done on the partition/volume Windows is installed.
  • When used with the desired= parameter the volume/partition is shrunk by the amount of MegaBytes (MBs) you specify. You will receive an error when the amount of free space is not available in the volume/partition
  • When used with both the desired= and minimum= parameters you can specify a maximum and minimum amount of MegaBytes (MBs) to shrink the volume/partition. The volume/partition will at least be shrunk with the amount of MegaBytes(MBs) supplied with minimum= and as much as possible of the amount you specified with the desired= parameter.

Example:

diskpart.exe
DISKPART> select disk 0
DISKPART> select volume 1
DISKPART>
shrink desired=1500
DISKPART> exit

This command will shrink the first volume on the first disk with 1500 MBs.

Extending

Besides shrinking a volume/partition, extending it is also an option. On basic disks you can extend a partition with unused space on the same disk. When using multiple dynamic disks you can optionally use space on a different disk. If the partition was previously formatted with the NTFS file system, the file system is automatically extended to fill the larger partition. No data loss occurs.

You can provide an optional size= parameter to prevent the commands from slurping up all available unused space on the disk. The values of this parameter is interpreted in MegaBytes (MBs). When extending a volume on a dynamic disk with unused space on a different dynamic disk, you can use the size= parameter to specify the disk with unused space.

Example:

diskpart.exe
DISKPART> select disk 0
DISKPART> select volume 1
DISKPART>
extend size=1500 disk=2
DISKPART> exit

This command will extend the first volume on the first disk with 1500 MBs using unused space from disk 2.

Deleting

Of course deleting a volume or partition is also possible. If you want to you can delete the volumes and partitions on your basic or dynamic disks with ease in the comfort of the diskpart.exe context. All you need to do is select it and type delete. followed by the type. (partition or volume)

Example:

diskpart.exe
DISKPART> select disk 0
DISKPART> select volume 1
DISKPART>
delete volume
DISKPART> exit

This command will delete the second volume on the first (dynamic) disk.

 

Working with drives

Formatting and assigning a drive letter

Disks, partitions and volumes are not very useful without a file system. While partitions and volumes can be placed on disks, file systems can be placed on volumes and partitions. Inside the context of diskpart.exe you can also place filesystems on volumes and partitions. You can specify the following parameters:

 

Parameter Values Description
fs= ntfs, fat or fat32 Specifies the file system to use when formatting the volume or partition
label=" " Any Specifies a label
quick Specifies whether to perform a quick format
compress Specifies whether to enable compression.
(Can only be used when using NTFS file system)

 

After formatting a partition or volume you can assign a drive letter using the assign command in the diskpart.exe context.

Example:

diskpart.exe
DISKPART> select disk 0
DISKPART> select volume 2
DISKPART>
format fs=ntfs label="Compressed Data" compress
DSKPART> assign letter=e
DISKPART> exit

This command will format the second volume on the first (dynamic) disk with the NTFS filesystem and enable compression. The  specified label is Compressed Data. The disk will be accessible as E:\.

Reformatting existing drives

Format.exe is another command that can be used to format existing volumes and partitions. It offers some more features than the format command in the diskpart.exe context. Using format.exe you can specify the allocation unit size to use on FAT, FAT32, or NTFS volumes (/a), the number of tracks on the disk (/t) and the number of sectors per track (/n). Optionally you can dismount the volume before it is formatted: Any open handles to the volume will no longer be valid.

Checking

To check the file system and file system metadata of a drive for logical and physical errors you can use the chkdsk.exe and chkntfs.exe utility.

Chkdsk.exe

When you're an administrator (or equivalent) on the Server Core installation you can use chkdsk.exe to analyze and optionally fix problems on your disks. These problems can be bad sectors, bad clusters, corrupt index entries and cycles within the folder structure.

Example:

chkdsk.exe D: /f

This example command will check the disk in drive D and fix errors. Your Server Core box may need to be restarted before analysis and fixing will commence.

Chkntfs.exe

When you're an administrator (or equivalent) on the box you can also use the chkntfs.exe utility to display the file system type, the status of the file system dirty bit, and whether or not chkdsk.exe is manually scheduled to run against the volume at boot time.

Example:

chkntfs.exe /D

This example command will disable the previous chkdsk.exe command, that was scheduled to run at the next reboot. (and any other scheduled chkdsk.exe commands)

Defragmenting

Defragmentation is actually pretty simple once you know where to find defrag.exe, which is the tool that locates and consolidates fragmented files on local volumes. It is located in the Windows\System32 folder on your System drive. Since this folder by default is part of the %PATH% variable you can simply execute it from any location by typing defrag.exe.

Example:

defrag.exe -c

This example command will defragment all volumes on the Server Core box.

 

Concluding

You need disks to store data. Disks can contain volumes or partitions, depending on their type (basic or dynamic). Volumes and partitions can be formatted to create drives. You can read and write data from within Server Core on drives only.

Working with disks, partitions, volumes and drives isn't very hard when you know the commands. Use a ? or help switch or command in case you need help with these.

Further reading

Description of Enhanced Chkdsk, Autochk, and Chkntfs Tools
Modifying the Autochk.exe Time-out Value
CHKNTFS.EXE: What You Can Use It For
Chkdsk /f Does Not Run on the Shared Cluster Disk
Dynamic vs. Basic Storage in Windows 2000
Using DiskPart.exe As Disk Management Alternative in Windows Vista, 2000, 2003 and XP
Shrinking Hard Disk With Free Tools – VMWare Disk Manager And DiskPart
TechNet: Diskpart
KB 300415 A Description of the Diskpart Command-Line Utility
Virtualbox: Expanding A Disk Drive
Windows Diskpart
Managing disk partitions in Windows with command line utilities
Diskpart and Windows 2008 and Exchange Server 2007
Resize a partition in Vista

leave your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.