磁盘管理工具(Disk Management Tool)是管理 Windows 磁盘和分区的有用且有效的工具,但它不如Diskpart强大。此命令行工具可让您删除、创建和修改PC 可以检测到的任何硬盘驱动器或USB存储设备上的分区。(USB)
我们建议在大多数情况下使用磁盘管理工具,但如果(Disk Management Tool)Windows无法正常启动,或者您更喜欢使用 PowerShell 终端(use the PowerShell terminal),Diskpart是完美的选择。以下是一些更常见的Diskpart命令,可帮助您学习如何有效地使用Diskpart。
如何使用 Diskpart(How To Use Diskpart)
如果你想使用Diskpart,你需要打开一个Windows命令行或PowerShell终端。Diskpart是一种破坏性工具,因此您需要以正确的管理权限打开终端窗口。
- 要在Windows中打开Diskpart,请右键单击Windows开始菜单按钮,然后单击Windows PowerShell (Admin)。
- 在您的管理员级PowerShell终端(或类似的Windows命令行)中,键入diskpart并按 Enter。
- Diskpart工具将在窗口中启动,供您使用。在“DISKPART>”提示符下键入exit ,并在完成使用后按回车键。(exit)
- Diskpart也适用于引导到Windows 恢复环境的用户,当您使用“(Windows Recovery Environment)Settings > Windows Update & Security > Recovery菜单中的“高级启动(Advanced Startup)”模式启动 PC 时可用。
- 单击立即重新启动(Restart Now)以启动到 WinRE。
我们将在本文中探讨一些最常见的Diskpart命令,但如果您想快速查看可用Diskpart命令的完整列表,请在“DISKPART>”帮助(help)并回车。
列出现有的硬盘驱动器(Hard Drives)、卷(Volumes)和分区(Partitions)
打开Diskpart后,您应该做的第一件事是检查硬盘驱动器和附加存储的当前布局。
- 在“DISKPART>”提示符下,输入list disk并回车。这将列出您的 PC 当前可以检测到的所有可用存储驱动器(包括硬盘驱动器、USB存储、SD 卡等)。
- 从数字零开始,Diskpart将列出所有检测到的磁盘。您需要记住磁盘编号(例如,Windows硬盘驱动器的“0”)以用于将来的Diskpart命令。
- 除了磁盘列表之外,您还可以向Diskpart询问检测到的卷列表。在“DISKPART>”提示符下,键入list volume。
- Diskpart还可以让您列出单个硬盘驱动器分区(其中一些可能与“list volume”命令列出的卷匹配)。您需要先使用list disk命令选择硬盘。
- 在 “DISKPART>”提示符下,键入select disk后跟磁盘编号(例如,选择磁盘 0(select disk 0))。Diskpart将确认此时已选择磁盘。
- 选择磁盘后,键入list partition。这将列出驱动器上的当前分区。您可以使用稍后的Diskpart命令中的分区号从此处删除或修改这些分区。
使用 Diskpart 删除硬盘分区或卷(Deleting a Hard Drive Partition Or Volume Using Diskpart)
硬盘驱动器(磁盘)被分成多个分区,这些分区通常与列出的卷相同。如果您的硬盘驱动器被分成多个分区或卷,并且您希望删除一个,您可以使用Diskpart命令来执行此操作。
- 使用选择磁盘选择您的硬盘驱动器。 (select disk. )
- 在“DISKPART>”提示符下,键入list partition,然后select partition #,将 # 替换为您的分区号。
- 选择分区后,键入delete partition。Diskpart之后会确认分区是否已被删除。
- 如果您愿意,也可以直接删除磁盘卷。键入list volume,找到您选择的卷号,然后键入select volume #,将 # 替换为您的卷号。
- 键入delete volume以完全删除该卷。Diskpart将在之后确认命令是否成功。
使用 Diskpart Clean 彻底擦除硬盘驱动器(Wiping a Hard Drive Completely Using Diskpart Clean)
您可以使用Diskpart (Diskpart) clean命令完全擦除硬盘驱动器,而不是删除驱动器上的单个卷或分区。如果您要擦除USB闪存驱动器以进行格式化,也可以使用此命令。
除非您在Windows安装中使用Diskpart ,否则您将无法在系统驱动器上执行此操作(您也不想这样做!)
- 在“DISKPART>”select disk #要擦除的磁盘,将 # 替换为您的磁盘编号。如果您不知道您的磁盘号,请先键入list disk。
- 如果您确定要完全擦除磁盘(删除所有驱动器卷/分区),请键入clean并按 Enter。系统不会要求您进行确认,因此请确保在开始之前进行此操作。
- Diskpart将确认驱动器已“清理”,准备好创建新分区。
创建和格式化新的硬盘分区(Creating & Formatting New Hard Drive Partitions)
有了一个“干净”的驱动器,您就可以使用Diskpart create partition命令在可用空间中创建一个分区了。然后,您可以使用Diskpart格式(format)命令使用Windows 友好的文件系统(如NTFS或FAT32 )格式化该新分区。(FAT32)
- 首先使用select disk # 选择您选择的磁盘,将 # 替换为您的磁盘编号(如果您不知道,请使用list disk查找您的磁盘编号。)(list disk)
- 选择您的磁盘后,键入create partition primary以使用该驱动器上的整个空间创建一个分区。
- 如果您想创建一个仅占用部分空闲空间的分区(让您创建多个分区),请键入create partition primary size=X ,将 X 替换为分区大小,以兆字节为单位(例如,size=1024为 1GB 空间)。
- 键入list partition以确保列出了您的新分区,然后键入select partition 1将其选中。在 “DISKPART>”提示符下键入活动,将分区(active)标记(Mark)为活动。如果您想将其用作可引导驱动器,这是必要的。
- 要使用NTFS文件系统快速格式化驱动器,请键入format fs=NTFS label=Y quick.您可以将Y替换为您喜欢使用的任何标签。
- 格式化后,Windows可能会自动分配驱动器号。如果不是,请键入assign letter Z,将Z替换为空闲驱动器号。
扩展硬盘卷(Extend a Hard Drive Volume)
如果您有一个现有的硬盘驱动器卷不会占用驱动器上的所有可用空间,并且您希望扩大它,Diskpart命令允许您这样做。
- 首先使用select disk # 选择您选择的磁盘,将 # 替换为您的磁盘编号(如果您不知道,请使用list disk查找您的磁盘编号。)(list disk)
- 键入list volume以列出您 PC 上的所有可用卷,然后键入select volume #,将 # 替换为您要扩展的卷。
- 键入extend以将其扩展到可用的最大大小。Diskpart将确认扩展命令是否正常工作。之后再次键入list volume(list volume)以确认卷的大小已增加。
Diskpart有其他可用选项,如帮助(help)命令简要说明的那样。如果您需要有关如何使用Diskpart的更多信息,Microsoft提供了更多Diskpart 支持信息(Diskpart support information)。
How to Use DiskPart Utility in Windows
The Disk Mаnаgеment Tool is a useful, effective tool for manаging your Windows disks and partitions, but it isn’t as powerful to use as Diskpart. This command-lіne tool lets you delete, сreate and modify partitions on any hard driνes or USB storage your PC can detect.
We’d recommend using the Disk Management Tool for most situations, but if Windows isn’t starting up properly, or if you prefer to use the PowerShell terminal, Diskpart is the perfect alternative. Here are some of the more common Diskpart commands to help you learn how to use Diskpart effectively.
How To Use Diskpart
If you want to use Diskpart, you need to open up a Windows command line or PowerShell terminal. Diskpart is a destructive tool, so you’ll need to open a terminal window with the right administrative privileges.
- To open Diskpart in Windows, right-click your Windows Start menu button and click Windows PowerShell (Admin).
- In your admin-level PowerShell terminal (or similar Windows command line), type diskpart and hit enter.
- The Diskpart tool will launch within the window, ready for you to use. Type exit at the “DISKPART>” prompt and hit enter once you’ve finished using it.
- Diskpart is also available for users booting into the Windows Recovery Environment, available when you boot your PC using the Advanced Startup mode in your Settings > Windows Update & Security > Recovery menu.
- Click Restart Now to boot to WinRE.
We’ll explore some of the most common Diskpart commands in this article, but if you want to quickly see the full list of available Diskpart commands, type help at the “DISKPART>” prompt and hit enter.
Listing Existing Hard Drives, Volumes & Partitions
Once Diskpart is open, the first thing you should do is check the current layout of your hard drives and attached storage.
- At the “DISKPART>” prompt, type list disk and hit enter. This will list all of the available storage drives (including hard drives, USB storage, SD cards, etc.) that your PC can currently detect.
- Starting with the number zero, Diskpart will list any detected disks. You’ll need to remember the disk number (for instance, “0” for your Windows hard drive) to use with future Diskpart commands.
- Along with your list of disks, you can also ask Diskpart for a list of detected volumes. At the “DISKPART>” prompt, type list volume.
- Diskpart can also let you list individual hard drive partitions (some of which may match the volumes listed with the “list volume” command). You’ll need to select a hard disk first with the list disk command.
- At the “DISKPART>” prompt, type select disk followed by the disk number (for instance, select disk 0). Diskpart will confirm that the disk is selected at this point.
- Once a disk is selected, type list partition. This will list the current partitions on your drive. You’ll be able to delete or modify these partitions from here, using the partition number in a later Diskpart command.
Deleting a Hard Drive Partition Or Volume Using Diskpart
A hard drive (disk) is separated into partitions, which are often the same as listed volumes. If your hard drive is separated into several partitions or volumes, and you wish to delete one, you can do that using Diskpart commands.
- Select your hard drive using select disk.
- At the “DISKPART>” prompt, type list partition, then select partition #, replacing # with your partition number.
- Once a partition is selected, type delete partition. Diskpart will confirm whether or not the partition has been deleted afterward.
- You can also delete disk volumes directly if you’d prefer. Type list volume, locate your chosen volume number, then type select volume #, replacing # with your volume number.
- Type delete volume to delete the volume completely. Diskpart will confirm if the command was successful or not afterward.
Wiping a Hard Drive Completely Using Diskpart Clean
Rather than removing individual volumes or partitions on a drive, you can wipe a hard drive completely using the Diskpart clean command. You can also use this command if you’re looking to wipe a USB flash drive, ready for formatting.
You won’t be able to do this on your system drive (nor would you want to!) unless you’re using Diskpart on a Windows installation
- At the “DISKPART>” prompt, select the disk you wish to wipe by typing select disk #, replacing # with your disk number. If you don’t know your disk number, type list disk first.
- If you’re sure you want to wipe the disk completely (deleting all drive volumes/partitions), then type clean and hit enter. You won’t be asked for confirmation, so be sure you wish to do this before you begin.
- Diskpart will confirm that the drive has been “cleaned”, ready for new partitions to be created.
Creating & Formatting New Hard Drive Partitions
With a “clean” drive, you’re ready to create a partition in the free space using the Diskpart create partition command. You can then format that new partition with a Windows-friendly file system like NTFS or FAT32 using the Diskpart format command.
- Start by selecting your chosen disk with select disk #, replacing # with your disk number (and using list disk to find your disk number, if you don’t know.)
- With your disk selected, type create partition primary to create a partition using the entire space on that drive.
- If you want to create a partition to take up only some of the free space (letting you create more than one partition), type create partition primary size=X instead, replacing X with the partition size, measured in megabytes (for example, size=1024 for 1GB of space).
- Type list partition to make sure that your new partition is listed, then type select partition 1 to select it. Mark the partition as active by typing active at the “DISKPART>” prompt. This is necessary if you want to use it as a bootable drive.
- To quickly format the drive with the NTFS file system, type format fs=NTFS label=Y quick. You can replace Y with any label you’d prefer to use.
- Once formatted, Windows will likely assign a drive letter automatically. If it doesn’t, type assign letter Z, replacing Z with a free drive letter.
Extend a Hard Drive Volume
If you have an existing hard drive volume that doesn’t take up all of the free space on a drive, and you wish to enlarge it, Diskpart commands allow you to do that.
- Start by selecting your chosen disk with select disk #, replacing # with your disk number (and using list disk to find your disk number, if you don’t know.)
- Type list volume to list all the available volumes on your PC, then type select volume #, replacing # with the volume you’re looking to extend.
- Type extend to expand it to the maximum size available. Diskpart will confirm whether or not the extend command has worked correctly. Confirm the size of the volume has increased by typing list volume for a second time afterward.
Diskpart has other options available, as the help command briefly explains. If you need further information on how to use Diskpart, Microsoft has further Diskpart support information available.