Initializing Windows Data Disks Using Script
Scenarios
This section uses Windows Server 2008 R2 Enterprise 64bit to describe how to automatically initialize data disks attached to a ECS running Windows.
The formatting procedure varies depending on the ECS OS. This section is for reference only.
![](https://support.huaweicloud.com/intl/pt-br/qs-ecs/public_sys-resources/notice_3.0-pt-br.png)
Ao usar um disco pela primeira vez, se você não o inicializou, incluindo a criação de partições e sistemas de arquivos, a capacidade adicional adicionada ao disco em uma operação de expansão posterior pode não ser usada normalmente.
Pré-requisitos
- Um disco de dados foi anexado ao ECS e não foi inicializado.
- Você fez logon no ECS.
- Para saber como efetuar logon em um ECS, consulte Logon em um ECS.
- Para saber como fazer logon em um BMS, consulte Logon no BMS.
Constraints
- This script uses the NTFS file system and MBR partition style by default.
- This script does not support the initialization of disks that form Windows logical volume groups.
- This script supports the initialization of up to 23 Windows data disks.
- Only data disks in Windows simplified Chinese and English can be initialized.
Manually Executing the Script to Initialize Windows Data Disks
- Log in to the ECS, visit https://ecs-instance-driver.obs.cn-north-1.myhuaweicloud.com/datadisk/WinVMDataDiskAutoInitialize.ps1 to obtain the automatic disk initialization script, and save it to C:\Windows\System32.
- On the ECS desktop, click Start, right-click Windows PowerShell, and choose Run as administrator from the shortcut menu.
Figura 1 Run Windows PowerShell as administrator
- In the displayed dialog box, run the following command to set the script execution policy:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Force
- Run the following command in the dialog box to execute the initialization script:
C:\Windows\System32\WinVMDataDiskAutoInitialize.ps1
Information similar to the following is displayed:
If the command output shows that PowerShell cannot load the file, the reason is that the Windows system policy does not allow the PowerShell script downloaded from the network to be executed when the script is not signed.
To solve this problem, run the set-ExecutionPolicy RemoteSigned command and restart PowerShell.
- (Optional) On the Disk Management page, view the initialization result.
Figura 2 Disk Management
Configuring Automatic Initialization of Windows Data Disks
You can configure automatic initialization for Windows data disks. After the configuration is complete, new disks purchased and attached to this ECS will be automatically initialized after the ECS is logged in to again.
![](https://support.huaweicloud.com/intl/pt-br/qs-ecs/public_sys-resources/note_3.0-pt-br.png)
To enable automatic initialization of Windows data disks on multiple ECSs, configure automatic initialization on one ECS, create a private image for this ECS, and use the image to batch create ECSs.
- On ECS desktop, click Start, right-click Computer in the list, and choose Manage from the shortcut menu.
The Server Manager window is displayed.
- In the navigation tree on the left, choose Configuration > Task Scheduler > Task Scheduler Library, then right-click and choose Create Task from the shortcut menu.
The Create Task page is displayed.
- On the displayed page, click the General tab, enter WinVMDataDiskInitialize in the Name text box, and click Change User or Group.
The Select User or Group page is displayed.
- Click Advanced in the lower left corner of the page.
- Click Find Now to the right of the page. In the search result list, select SYSTEM and click OK.
The Select User or Group page is displayed.
- Click OK.
- Click the Triggers tab and click Create in the lower left corner of the page.
- On the New Trigger page, choose At log on for Begin the task, retain the default settings for other parameters, and click OK.
- Click the Actions tab and click Create in the lower left corner of the page.
- On the Edit Action page, set the following parameters:
- Action: Choose Start a program.
- Program/Script: Select powershell.exe.
- Add arguments (optional): Enter -ExecutionPolicy Bypass C:\Windows\System32\WinVMDataDiskAutoInitialize.ps1.
Click OK.
- On the Create Task page, click OK.