Discussion:
Automatically initialize data-disk on Windows Server 2016 OS template
Cloud List
2017-08-14 05:32:12 UTC
Permalink
Dear all,

I am using CloudStack 4.8.1 and KVM hypervisor. When creating my Windows
Server 2016 OS template, I tried to automate the initialization and
formatting of the data-disk so that it will automatically be put online,
initialized with MBR partition, formatted and assigned the E: drive letter,
without the user having to manually initialize the disk using Computer
Management > Disk Management.

I tried to do so by preparing 2 scripts:

1. A PowerShell script to automatically initialize and format all disks
with RAW partition, which I am taking from here:

https://blogs.technet.microsoft.com/heyscriptingguy/2013/05/29/use-powershell-to-initialize-raw-disks-and-to-partition-and-format-volumes/

I saved it on C:\script\InitializePartitionFormatNewDisks.ps1.

2. A command script to automatically run the above PowerShell script when
the Administrator user logs in. I follow the instructions on below URL:

https://stackoverflow.com/questions/20575257/how-to-run-powershell-script-when-computer-starts

to create a command script to set PowerShell execution policy to
"unrestricted" and then run the script.

===
PowerShell -Command "Set-ExecutionPolicy Unrestricted" >>
"%TEMP%\StartupLog.txt" 2>&1 PowerShell
C:\script\InitializePartitionFormatNewDisks.ps1 >> "%TEMP%\StartupLog.txt"
2>&1
===

I saved the command script onto:
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\Startup\startup.cmd

The issue I face is that the command script I put onto
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\Startup\startup.cmd is deleted during the "sysprep" process,
as part of the Windows template creation on CloudStack as per:

http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/4.8/templates/_create_windows.html

Is there a way I can put the startup.cmd file somewhere else so that it
will not be deleted during the sysprep process but will still be executed
when the VM boots up or when the Administrator user logs in? Or is there
any better approach on how to automate the data-disk initialization?

Any advice is highly appreciated.

Looking forward to your reply, thank you.

Cheers.
Cloud List
2017-08-16 04:12:04 UTC
Permalink
Dear all,

Anyone who has created a Windows Server 2016 OS template on CloudStack can
advise on what's the best way to auto-initialize the data-disk upon VM
provisioning?

Any advice is highly appreciated.

Thank you.
Post by Cloud List
Dear all,
I am using CloudStack 4.8.1 and KVM hypervisor. When creating my Windows
Server 2016 OS template, I tried to automate the initialization and
formatting of the data-disk so that it will automatically be put online,
initialized with MBR partition, formatted and assigned the E: drive letter,
without the user having to manually initialize the disk using Computer
Management > Disk Management.
1. A PowerShell script to automatically initialize and format all disks
https://blogs.technet.microsoft.com/heyscriptingguy/
2013/05/29/use-powershell-to-initialize-raw-disks-and-to-
partition-and-format-volumes/
I saved it on C:\script\InitializePartitionFormatNewDisks.ps1.
2. A command script to automatically run the above PowerShell script when
https://stackoverflow.com/questions/20575257/how-to-run-
powershell-script-when-computer-starts
to create a command script to set PowerShell execution policy to
"unrestricted" and then run the script.
===
PowerShell -Command "Set-ExecutionPolicy Unrestricted" >>
"%TEMP%\StartupLog.txt" 2>&1 PowerShell C:\script\
InitializePartitionFormatNewDisks.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
===
I saved the command script onto: C:\Users\Administrator\
AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\startup.cmd
The issue I face is that the command script I put onto
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\Startup\startup.cmd is deleted during the "sysprep"
http://docs.cloudstack.apache.org/projects/cloudstack-
administration/en/4.8/templates/_create_windows.html
Is there a way I can put the startup.cmd file somewhere else so that it
will not be deleted during the sysprep process but will still be executed
when the VM boots up or when the Administrator user logs in? Or is there
any better approach on how to automate the data-disk initialization?
Any advice is highly appreciated.
Looking forward to your reply, thank you.
Cheers.
Nux!
2017-08-30 07:40:48 UTC
Permalink
Hello,

Hopefully my reply does not come too late.

I have not tried 2016 yet, but on 2012R2 the process I used is:

1. Create C:\Windows\Setup\Scripts\SetupComplete.cmd - this will get executed once after first boot, Sysprep does not delete it.

2. From it I call - among others: "diskpart /s C:\extend.txt" which looks like this:
select disk 0
select partition 2
extend

Now in my case there is no data disk, I just use the root resize feature and extend the Windows C: partition accordingly, but there is no reason why you can't "select disk 1" and perform all sorts of other operations on it it to make it available to the user.

HTH
Lucian

--
Sent from the Delta quadrant using Borg technology!

Nux!
www.nux.ro

----- Original Message -----
Sent: Wednesday, 16 August, 2017 05:12:04
Subject: Re: Automatically initialize data-disk on Windows Server 2016 OS template
Dear all,
Anyone who has created a Windows Server 2016 OS template on CloudStack can
advise on what's the best way to auto-initialize the data-disk upon VM
provisioning?
Any advice is highly appreciated.
Thank you.
Post by Cloud List
Dear all,
I am using CloudStack 4.8.1 and KVM hypervisor. When creating my Windows
Server 2016 OS template, I tried to automate the initialization and
formatting of the data-disk so that it will automatically be put online,
initialized with MBR partition, formatted and assigned the E: drive letter,
without the user having to manually initialize the disk using Computer
Management > Disk Management.
1. A PowerShell script to automatically initialize and format all disks
https://blogs.technet.microsoft.com/heyscriptingguy/
2013/05/29/use-powershell-to-initialize-raw-disks-and-to-
partition-and-format-volumes/
I saved it on C:\script\InitializePartitionFormatNewDisks.ps1.
2. A command script to automatically run the above PowerShell script when
https://stackoverflow.com/questions/20575257/how-to-run-
powershell-script-when-computer-starts
to create a command script to set PowerShell execution policy to
"unrestricted" and then run the script.
===
PowerShell -Command "Set-ExecutionPolicy Unrestricted" >>
"%TEMP%\StartupLog.txt" 2>&1 PowerShell C:\script\
InitializePartitionFormatNewDisks.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
===
I saved the command script onto: C:\Users\Administrator\
AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\startup.cmd
The issue I face is that the command script I put onto
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\Startup\startup.cmd is deleted during the "sysprep"
http://docs.cloudstack.apache.org/projects/cloudstack-
administration/en/4.8/templates/_create_windows.html
Is there a way I can put the startup.cmd file somewhere else so that it
will not be deleted during the sysprep process but will still be executed
when the VM boots up or when the Administrator user logs in? Or is there
any better approach on how to automate the data-disk initialization?
Any advice is highly appreciated.
Looking forward to your reply, thank you.
Cheers.
Continue reading on narkive:
Loading...