{"id":254993,"date":"2014-12-03T22:59:08","date_gmt":"2014-12-03T14:59:08","guid":{"rendered":"http:\/\/blog.zhenglei.net\/?p=254993"},"modified":"2014-12-03T23:07:13","modified_gmt":"2014-12-03T15:07:13","slug":"windows-iscsicli","status":"publish","type":"post","link":"https:\/\/blog.zhenglei.net\/?p=254993","title":{"rendered":"windows iscsicli"},"content":{"rendered":"<div id=\"wrap\">\n<div id=\"header\">\n<div class=\"wrap\">\n<div id=\"title-area\">\n<p id=\"title\">1.\u547d\u4ee4\u884c\u914d\u7f6eISCSI\u3002<br \/>\n\u5f00\u542fiSCSI server &amp;&amp; \u8bbe\u4e3a&#8221;automatically&#8221; \u81ea\u52a8&#8211;\u5f00\u673a\u542f\u52a8\u3002<br \/>\nsc config msiscsi start= auto<br \/>\nnet start msiscsi<br \/>\n2.\u4f7f\u7528iscsi\u547d\u4ee4\u884c\u63a5\u53e3\u8fde\u63a5iSCSI\u76ee\u6807\u3001\u5217\u51fa\u6709\u6548\u76ee\u6807\u3002<br \/>\niscsicli QAddTargetPortal 192.168.1.31<br \/>\n3.\u5217\u51fa\u76ee\u6807<br \/>\niscsicli ListTargets<br \/>\n4.\u8fde\u63a5\u76ee\u6807<br \/>\niscsicli qlogintarget TargetName<br \/>\n5.\u786e\u8ba4\u8fde\u63a5\u6210\u529f<br \/>\niscsicli reporttargetmappings<br \/>\n6.\u65ad\u5f00\u76ee\u6807<br \/>\niscsicli logouttarget SESSIONID(\u5982\uff1a0xfffffa800626e018-0x4000013700000006)<br \/>\n7.\u786e\u8ba4\u65ad\u5f00\u6210\u529f<br \/>\niscsicli reporttargetmappings<\/p>\n<p>&nbsp;<\/p>\n<p>*********************************************************************************************************<\/p>\n<h1>How to Automate Windows Diskpart Commands in a Scrip<\/h1>\n<div id=\"nrelate_flyout_placeholder\">\n<p>Being able to automate disk partitioning, volume creation, and filesystem formatting can be very useful. It is especially handy for imaging processes, e.g. from a WinPE boot disk.<\/p>\n<p>&nbsp;<\/p>\n<p>The windows diskpart command can be automated using a simple text file. Unfamiliar with Diskpart? Open Windows Command Processor (cmd.exe) and type:<\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #888888\">diskpart<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #888888\">help<\/span><\/p>\n<p><span style=\"color: #000000\">If you want help with a specific command, type:<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #339966\">help &lt;command&gt;<\/span><\/p>\n<p><span style=\"color: #000000\">Where &lt;command&gt; is the command that you want help with.<\/span><\/p>\n<p><span style=\"color: #000000\">To automate diskpart, you simply need to create a text file with your diskpart commands, then call diskpart from your command prompt or script and pass it the name of the text file.<\/span><\/p>\n<p>For example, let\u2019s say that you have booted a computer to WinPE, and wish to wipe the local \u201cC:\u201d drive and create a fresh one. To do so, open notepad.exe, then type the following:<\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #339966\">select disk 0<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #339966\">clean<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #339966\">create partition primary<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #339966\">assign letter=C<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #339966\">active<\/span><\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #339966\">format fs=ntfs label=Windows quick<\/span><\/p>\n<p>Now save that as WipeC.txt and close Notepad.<\/p>\n<p>Then run it like so:<\/p>\n<p style=\"padding-left: 30px\"><span style=\"color: #339966\">diskpart.exe \/s WipeC.txt<\/span><\/p>\n<p>Please note that this example will completely remove the contents of the local Disk 0!<\/p>\n<p>More specifically, it will: wipe all partitions off of Disk 0, create a single primary partition which will occupy the whole disk, assign that partition the drive letter C:, set it as active so that you can boot from it, and then create a volume called \u201cWindows\u201d formatted quickly as NTFS.<\/p>\n<\/div>\n<\/div>\n<div class=\"widget-area\">\n<div id=\"search-2\" class=\"widget widget_search\">\n<div class=\"widget-wrap\">\n<form class=\"searchform search-form\" action=\"http:\/\/www.iconixit.net\/\" method=\"get\"><a href=\"\/\/ss64.com\/nt\/diskpart.html\">\u00a0http:\/\/ss64.com\/nt\/diskpart.html<\/a>*********************************************************************************************************<\/p>\n<\/form>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"inner\">\n<div class=\"wrap\">\n<div id=\"content-sidebar-wrap\">\n<div id=\"content\" class=\"hfeed\">\n<div class=\"breadcrumb\">The iscsicli.exe Command<\/div>\n<div class=\"date published time\" title=\"2011-11-22T22:53:32+00:00\"><span id=\"more-317\"><\/span><\/p>\n<div class=\"entry-content\">\n<table border=\"1\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"30%\"><strong>Action<\/strong><\/td>\n<td valign=\"top\" width=\"70%\"><strong>Command<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Set startup type to automatic<\/td>\n<td valign=\"top\"><code>sc [server-name] config msiscsi start= auto<\/code><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Add iSCSI Targets<\/td>\n<td valign=\"top\"><code>iscsicli.exe QAddTargetPortal [tartget-portal-address] [chap-username] [chap-password]<\/code><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Get iSCSI Targets<\/td>\n<td valign=\"top\"><code>iscsicli.exe ListTargets<\/code><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Login to Targets<\/td>\n<td valign=\"top\"><code>iscsicli.exe QLoginTarget [target-iqn]<\/code><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Set up a persistent connection (reconnects after server reboot)<\/td>\n<td valign=\"top\"><code>iscsicli.exe PersistentLoginTarget [target-iqn] T * * * * * * * * * * * * * * * 0<\/code><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">List the persistent connections to target LUNs<\/td>\n<td valign=\"top\"><code>iscsicli.exe ListPersistentTargets<\/code><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">Check active connections<\/td>\n<td valign=\"top\"><code>iscsicli.exe ReportTargetMappings<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1.\u547d\u4ee4\u884c\u914d\u7f6eISCSI\u3002 \u5f00\u542fiSCSI server &amp;&amp;  &hellip; <a href=\"https:\/\/blog.zhenglei.net\/?p=254993\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[192],"tags":[195],"class_list":["post-254993","post","type-post","status-publish","format-standard","hentry","category-windows7","tag-iscsicli"],"_links":{"self":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/254993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=254993"}],"version-history":[{"count":2,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/254993\/revisions"}],"predecessor-version":[{"id":254995,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/254993\/revisions\/254995"}],"wp:attachment":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=254993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=254993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=254993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}