如何在 Windows 中以编程方式挂载原始 iSCSI 卷并准备使用?

发布于 2024-07-25 13:52:13 字数 172 浏览 2 评论 0原文

在 SAN 上创建新卷的 API 非常简单。 我无法弄清楚的是如何以编程方式将 iSCSI 启动器连接到它,初始化空间(在 Windows 磁盘管理器意义上),最后格式化它并将其挂载为驱动器号。

我目前使用 win2k3,但是如果迁移到 win2k8 可以简化实现,那么迁移到 win2k8 也是一个选择。

The API for creating a new volume on our SAN is pretty straight forward. What I have not been able to figure out is how to programatically connect the iSCSI initiator to it, initialize the space (in the windows disk manager sense) and finally format it and mount it is a drive letter.

I currently use win2k3, however moving to win2k8 is an option if it would simplify implementing this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

懷念過去 2024-08-01 13:52:14

我必须为我公司的一款产品实现磁盘初始化、分区和格式化。 我无法分享代码,但我可以为您指出正确的方向。

您想要的 API 称为 VDS - 虚拟磁盘服务。 它是一个 COM API,但我已经在 C++(使用 ATL)和 C#(COM 互操作)中成功使用了它。

遗憾的是,文档非常缺乏; 你只需要让自己沉浸在对象模型中,编写一些代码,慢慢地你就能感受到它了。

Windows Server 2008 附带了一个未记录但非常有用的 VDS 周围的 C# 包装器。 查找名为 Microsoft.Storage.Vds.dll 的 DLL。 您可以使用 Reflector 来发现它的各种类和方法。 当我阅读 这篇博文,其中作者尝试使用上述 DLL 从 PowerShell 初始化磁盘。

VDS 包括可由 SAN 供应商实施的 API,用于配置 LUN 并执行其他 SAN 操作; 建议您避免这些并专注于基本软件提供商,它将在 MBR 或 GPT 磁盘上创建基本(而不是动态)分区。 请注意,我提到的 Microsoft 包装器对 GPT 支持有点少; 我必须对其进行一些修改才能使 GPT 磁盘正常工作。

VDS 是一个复杂且挑剔的 API,但如果您只是想初始化磁盘、创建分区、格式化分区并将其安装到驱动器盘符,那么您需要的大部分内容都在那里并且相当容易完成。 祝你好运。

I had to implement disk initialization, partitioning, and formatting for one of my company's products. I can't share the code but I can point you in the right direction.

The API you want is called VDS - Virtual Disk Service. It's a COM API, but I've used it successfully from C++ (with ATL) and C# (COM interop).

Sadly the documentation is quite lacking; you just have to immerse yourself in the object model, write some code, and gradually you get a feel for it.

Windows Server 2008 ships with an undocumented but quite usable C# wrapper around VDS. Look for a DLL called Microsoft.Storage.Vds.dll. You can use Reflector to discover its various classes and methods. I found out about this when I read this blog post, in which the author is trying to initialize a disk from PowerShell using the aforementioned DLL.

VDS includes APIs that could be implemented by SAN vendors to provision a LUN and do other SAN things; suggest you avoid those and focus on the basic software provider, which will create basic (as opposed to dynamic) partitions on either an MBR or GPT disk. Note that the Microsoft wrapper I mentioned is a bit light on GPT support; I had to modify it a bit to get GPT disks working.

VDS is a complex and finicky API, but if you're just looking to initialize a disk, create a partition, format it, and mount it to a drive letter, most of what you need is there and fairly easy to do. Good luck.

默嘫て 2024-08-01 13:52:14

我已经通过 Powershell 使用 diskpart 和脚本完成了此操作。

就像是:

$target    = ''    #Desired target IQN
$partition = 1     #Desired partition
$drvLetter = ''    #Desired drive letter

#get the disk device number from the iscsi session class (diskpart needs it)
$iscsiSsn = gwmi -namespace "root\wmi" -class MSiSCSIInitiator_SessionClass
$diskNum = ($($iscsiSsn | where { $_.targetname -eq $target}).devices).deviceNumber

#create the diskpart script on-the-fly then call the utility
$dskPrtScr = "$($env:temp)\diskpart.scr"
"sel disk $diskNum`nsel par 1`nassign letter=$drvLetter`nexit" | out-file $dskPrtScr -encoding ascii
diskpart /s $dskPrtScr

I have done this from Powershell using diskpart with a script.

Something like:

$target    = ''    #Desired target IQN
$partition = 1     #Desired partition
$drvLetter = ''    #Desired drive letter

#get the disk device number from the iscsi session class (diskpart needs it)
$iscsiSsn = gwmi -namespace "root\wmi" -class MSiSCSIInitiator_SessionClass
$diskNum = ($($iscsiSsn | where { $_.targetname -eq $target}).devices).deviceNumber

#create the diskpart script on-the-fly then call the utility
$dskPrtScr = "$($env:temp)\diskpart.scr"
"sel disk $diskNum`nsel par 1`nassign letter=$drvLetter`nexit" | out-file $dskPrtScr -encoding ascii
diskpart /s $dskPrtScr
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文