Server 2008 R2 Read-Only disks in ESX Templates

During the build process of my Windows Server 2008 R2 VM templates, I had perplexing problem with my second virtual disk after sysprep completed. In my previous blog post I showed a PowerShell command that reassigned a drive letter. Worked great, but a noticed a problem. My “D” drive, which is a second PVSCSI disk, was being mounted as read-only. If I manually took the disk offline and brought it back online, magically it was read-write.

However, using a script to take the disk offline and bring it online did not remove the read-only attribute. After a bit more digging, I found a command that works like a charm. I had to change the disk attributes and clear the read-only flag.

The full PowerShell script, which I call from the c:Windowssetupscriptssetupcomplete.cmd file, is shown below.

$script = $Null

$script = @”

select disk 1

online disk noerr

attributes disk clear readonly

“@
$scriptdisk += $script + “`n”

$scriptdisk diskpart

echo E: %{$a = mountvol $_ /l;mountvol $_ /d;$a = $a.Trim();mountvol Z: $a}

I don’t know if the read-only problem comes from sysprep, changing drive letters, a VMware thing, or what. Since the script is executed during the sysprep process, you never know what is going on behind the scenes. Drive letters get changed and the D drive is read-write, just as you’d expect.

Print Friendly, PDF & Email

Related Posts

Leave a Reply

avatar
  Subscribe  
Notify of
Scroll to Top