Windows Tools: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
(Even more to come :))
No edit summary
Line 1: Line 1:
Windows provides some useful utilities for using [[Loopback Device|loopback devices]] and manipulating files that OS developers should know about; most of the time they are unaware of this and thus download tools that give them functionality they already had. This page attempts to describe these utilities and how these can be used.
Windows provides some useful utilities for using [[Loopback Device|loopback devices]] and manipulating files that OS developers should know about; most of the time they are unaware of this and thus download tools that give them functionality they already had. This page attempts to describe the Windows utilities and how they can be used.


Note: Wherever you see a drive letter followed by a semicolon in the examples, remember that you can just as well specify a GUID instead.
Note: Wherever you see a drive letter followed by a semicolon in the examples, remember that you can just as well specify a GUID instead.
Line 27: Line 27:
There are a few things worth noting:
There are a few things worth noting:
* The utility expects you to specify full paths.
* The utility expects you to specify full paths.
* When the '''maximum'''argument is omitted, the default size is set to '''24''' GiB.
* When the '''maximum'''argument is omitted, the default size is set to '''24''' GiB. When it is present, a valid hard disk size is needed.
* If not type is specified, the default is set to '''fixed'''. Expandable images grow in size as needed, while fixed ones do not.
* If not type is specified, the default is set to '''fixed'''. Expandable images grow in size as needed, while fixed ones do not.
* The '''source="bar.vhd"''' argument can be used in order to intialize the contents of the new image with ''bar.vhd''.
* The '''source="bar.vhd"''' argument can be used in order to intialize the contents of the new image with ''bar.vhd''.
Line 34: Line 34:
Although expandable images grow in size, they do not also automatically reduce in size. To manually reduce the size of the selected virtual disk:
Although expandable images grow in size, they do not also automatically reduce in size. To manually reduce the size of the selected virtual disk:
compact vdisk
compact vdisk
Here's an example of how to change the maximum size of the selected VHD to 20 MiB:
expand vdisk maximum=20
The following attaches the selected VHD:
attach vdisk
* The '''readonly''' argument can be used; its purpose is obvious.
After attaching a virtual disk, you need to create a partition for and mount it (i.e., assign it a letter):
create partition primary
assign letter=G
Finally, the following unmounts the selected VHD:
detach vdisk


== fsutil ==
== fsutil ==

Revision as of 14:08, 9 June 2011

Windows provides some useful utilities for using loopback devices and manipulating files that OS developers should know about; most of the time they are unaware of this and thus download tools that give them functionality they already had. This page attempts to describe the Windows utilities and how they can be used.

Note: Wherever you see a drive letter followed by a semicolon in the examples, remember that you can just as well specify a GUID instead.

copy

Except for its obvious purpose, the copy utility is also useful for concatenating files; this can come in handy when producing disk images, for instance. To illustrate the point, suppose we wanted to produce a file called foobar from files foo and bar; we would use the following command:

copy foo+bar foobar

diskcopy

DOS users will remember diskcopy, which replicates volumes. It only works with removable media such as memory cards, and floppy disks. The media must be of the same type for the operation to work. E.g., if we had two floppy drives A:, and B:, we could copy A:'s image to B: as such:

diskcopy A: B:

If the destination drive is not specified, the current one will be used. In addition, the /v argument can be used for verification (remember, floppy disks are not exactly reliable).

diskpart

The diskpart utility is useful for managing partitions and virtual hard drives, which can be used as loopback devices. If you want other types of loopback devices, you might want to consider VFD for floppy drives, and DAEMON Tools for optical media.

This isn't your usualy command-line utiliy: you run it from the command prompt, after which you query commands.

In order to create a VHD (Virtual Hard Disk) image that is 10 MiB in size, you can use the following command:

create vdisk file="C:\foo.vhd" maximum=10 type=expandable

There are a few things worth noting:

  • The utility expects you to specify full paths.
  • When the maximumargument is omitted, the default size is set to 24 GiB. When it is present, a valid hard disk size is needed.
  • If not type is specified, the default is set to fixed. Expandable images grow in size as needed, while fixed ones do not.
  • The source="bar.vhd" argument can be used in order to intialize the contents of the new image with bar.vhd.

Most operations require one to shift focus to the virtual disk beforehand. Creating a VHD automatically shifts focus to it but when working with multiple images, the select command is useful:

select vdisk file="C:\foo.vhd"

Although expandable images grow in size, they do not also automatically reduce in size. To manually reduce the size of the selected virtual disk:

compact vdisk

Here's an example of how to change the maximum size of the selected VHD to 20 MiB:

expand vdisk maximum=20

The following attaches the selected VHD:

attach vdisk
  • The readonly argument can be used; its purpose is obvious.

After attaching a virtual disk, you need to create a partition for and mount it (i.e., assign it a letter):

create partition primary
assign letter=G

Finally, the following unmounts the selected VHD:

detach vdisk

fsutil

The fsutil utility can be used to perform all sorts of NTFS and FAT operations, including file manipulation. Of these, the following are useful for OS developers:

Subcommand Parameter Description
8dot3name query This can be used in order to find out whether a volume (which may very well be a loopback device) is configured to use the 8.3 file naming scheme. Example:
fsutil 8dot3name query C:

If no volume is specified, information on all volumes is displayed.

set This option can set one or all volumes to (not) use the 8.3 file name scheme. Before this can be used on a per volume basis, the registry key HKLM\System\CurrentControlSet\Control\FileSystem\NtfsDisable8dot3NameCreationNtfsDisable8dot3NameCreationNtfsDisable8dot3NameCreation must be set to the value 2, if this is not already true. This can be done by using the following command:
fsutil 8dot3name set 2

Next, we are free to play around with individual volumes:

fsutil 8dot3name set C: 0

The last parameter can take the value 0 (enable) or 1 (disable). This is somewhat odd; the reason behind it is probably that Microsoft, in order to avoid confusion, decided to preserve these values, which are also used in a similar command.

file createnew Creates an empty file (all zeroes) of some size specified in bytes. Example:
fsutil createnew foobar 42
setshortname Sets the 8.3 name for a file (while preserving its long name). Example:
fsutil setshortname foobarbaz fooba~1
setvaliddata Sets the VDL for a file. Example:
fsutil setvaliddata foobar 4096
setzerodata Sets one or more bytes in a file to zero. Example:
fsutil setzerodata foobar offset=42 length=42 foobar