如何使用 PowerShell 创建基于 VHD 的开发驱动器?

问题描述 投票:0回答:1

我看到很多人讨论如何使用

storageDSC
在PowerShell中创建基于分区的Dev Drive(还有示例yaml配置PR到
storageDSC
)。我也可以在 PowerShell 中创建基于 VHD 的开发驱动器吗?

类似:

$vhd = Make-AVHD
Make-TheVHDIntoADevDrive $vhd
# set filters, etc...

我知道

Format-Volume
有一个
-DevDrive
参数
,所以我认为这应该可行。

powershell dev-drive
1个回答
0
投票

您确实可以在 PowerShell 中创建基于 VHD 的开发驱动器:

function New-VHDDevDrive
{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]$Path, # e.g. 'C:\test4.vhdx'

        [string]$Size = 5GB
    )

    $vhd = New-VHD -Path $Path -Dynamic -SizeBytes $Size
    $disk = $vhd | Mount-VHD -Passthru
    $init = $disk | Initialize-Disk -Passthru

    # New-Partition pops open explorer to the new drive before Format-Volume
    # completes, so it often tells you to format the drive.
    #
    # > You need to format the disk in drive R: before you can use it.
    #
    # Just ignore the pop-up until the formatting is complete, then click Cancel.
    $part = $init | New-Partition -AssignDriveLetter -UseMaximumSize
    $part | Format-Volume -DevDrive -FileSystem ReFS -Confirm:$false -Force
}

用途:

New-VHDDevDrive -Path 'c:\test5.vhdx' -size 20GB

修改此脚本以支持

-DriveLetter
等中的特定
New-Partition
应该很简单。

附录

要删除这些 VHD(因为您在测试时创建了 20 个):

Dismount-VHD -Path 'c:\test5.vhdx'
Remove-Item -Path 'c:\test5.vhdx'

此外,如果您想知道的话,它们在空时似乎每个占用约 450MB。

© www.soinside.com 2019 - 2024. All rights reserved.