File tree Expand file tree Collapse file tree 2 files changed +18
-31
lines changed
AutomatedLabWorker/functions/VirtualMachines Expand file tree Collapse file tree 2 files changed +18
-31
lines changed Original file line number Diff line number Diff line change @@ -556,36 +556,6 @@ rm -rf /etc/cron.d/postconf
556
556
557
557
$vm = Hyper-V\New-VM @vmParameter
558
558
559
- if ($vm.Generation -ge 2 -and $Machine.OperatingSystemType -eq ' Linux' -and $Machine.LinuxType -eq ' Ubuntu' )
560
- {
561
- $systemDisk = $vm | Get-VMHardDiskDrive
562
- $ubuntuSpecialDisk = $vm | Add-VMHardDiskDrive - Path " $vmPath \$ ( $Machine.ResourceName ) _INSTALL.vhdx" - Passthru
563
- $vm | Set-VMFirmware - BootOrder $systemDisk , $ubuntuSpecialDisk
564
-
565
- Start-Job - Name " Ensure Ubuntu Boot Order $ ( $Machine.ResourceName ) " - ScriptBlock {
566
- param
567
- (
568
- $Name
569
- )
570
-
571
- # Boot order of Ubuntu system changes during installation. We need to ensure the OS
572
- # is booted, lest it is stuck in an installation loop.
573
- # No cancellation token, we'll remove the job if the lab installation has finished.
574
- while ($true )
575
- {
576
- Write-Verbose " Reordering boot order for Ubuntu VM '$Name '"
577
- $linvm = Get-LWHypervVM - Name $Name
578
- $order = ($linvm | Get-VMFirmware ).BootOrder
579
- if ($order [0 ].BootType -eq ' Drive' -and $order [0 ].Device.Path -like " *_INSTALL*" )
580
- {
581
- $newOrder = $order [1 .. $order.Count ] + $order [0 ]
582
- $linvm | Set-VMFirmware - BootOrder $newOrder
583
- }
584
- Start-Sleep - Seconds 1
585
- }
586
- } - ArgumentList $Machine.ResourceName
587
- }
588
-
589
559
Set-LWHypervVMDescription - ComputerName $Machine.ResourceName - Hashtable @ {
590
560
CreatedBy = ' {0} ({1})' -f $PSCmdlet.MyInvocation.MyCommand.Module.Name , $PSCmdlet.MyInvocation.MyCommand.Module.Version
591
561
CreationTime = Get-Date
Original file line number Diff line number Diff line change 24
24
foreach ($Name in $ (Get-LabVM - ComputerName $ComputerName - IncludeLinux | Where-Object SkipDeployment -eq $false ))
25
25
{
26
26
$machine = Get-LabVM - ComputerName $Name - IncludeLinux
27
+ $hvMachine = Get-LWHypervVM - Name $Name.ResourceName
28
+
29
+ <#
30
+ Remove _INSTALL.vhdx on Ubuntu if the VM has been shut down once - indicating that the
31
+ cloudinit/subiquity phase was successfully finished.
32
+ We compare GuestStatePath LastWriteTime as a simple and quick way to check if
33
+ the VM's status has changed i.e. when it was stopped.
34
+ One minute seems like a sane interval, we might need to increase it in the future.
35
+ #>
36
+ if ($hvMachine.State -ne ' Running' -and ((Get-Item - Path $hvMachine.GuestStatePath ).LastWriteTime - $hvMachine.CreationTime ) -gt ' 00:01:00' )
37
+ {
38
+ Write-ScreenInfo - Type Verbose " Removing installation disk '$Name '"
39
+ $disk = $hvMachine | Get-VMHardDiskDrive | Where-Object Path -like " *_INSTALL*"
40
+ $diskPath = $disk.Path # Otherwise $disk will be update after remove-vmharddiskdrive was called
41
+ $disk | Remove-VMHardDiskDrive
42
+ Remove-Item - Path $diskPath - Force
43
+ }
27
44
28
45
try
29
46
{
30
- Get-LWHypervVM - Name $Name .ResourceName | Hyper-V\Start-VM - ErrorAction Stop
47
+ $hvMachine | Hyper-V\Start-VM - ErrorAction Stop
31
48
}
32
49
catch
33
50
{
You can’t perform that action at this time.
0 commit comments