我們有兩台 Hyper-V 做 Cluster,某天發現上面的 VM 全部有重新啟動的現象,而SCVMM 2008 R2 管理主機剛好在上面,登入檢查發現一堆 VM 名稱重覆,而且這些重覆的 VM 有的狀態是「遺失」,有的狀態「更新失敗」。
若是狀態是「遺失」的 VM 在微軟 KB983839 中有說明如何刪除 SCVMM 2008 R2 中遺失的VM。
1. 關閉 SCVMM 系統管理員主控台。
2. 停止 Virtual Machine Manager 服務。
以系統管理員身份執行命令提示字元,然後執行下列指令。
> net stop vmmservice
3. 完整備份 SCVMM 資料庫。
4. 在 SCVMM 上安裝 Microsoft SQL Management Studio。
5. 在 Microsoft SQL Management Studio 執行下列 Script。
執行 Microsoft SQL Management Studio,然後點選「新增查詢」,選擇正確的 DB。
將下列 Script 複製 / 貼上。
RemoveMissingVMs
BEGIN TRANSACTION T1
DECLARE custom_cursor CURSOR FOR
SELECT ObjectId from
dbo.tbl_WLC_VObject WHERE [ObjectState] = 220
DECLARE @ObjectId uniqueidentifier
OPEN custom_cursor
FETCH NEXT FROM custom_cursor INTO @ObjectId
WHILE(@@fetch_status = 0)
BEGIN
DECLARE vdrive_cursor CURSOR FOR
SELECT VDriveId, VHDId, ISOId from
dbo.tbl_WLC_VDrive WHERE ParentId = @ObjectId
DECLARE @VDriveId uniqueidentifier
DECLARE @VHDId uniqueidentifier
DECLARE @ISOId uniqueidentifier
OPEN vdrive_cursor
FETCH NEXT FROM vdrive_cursor INTO @VDriveId, @VHDId, @ISOId
WHILE(@@fetch_status = 0)
BEGIN
DELETE FROM dbo.tbl_WLC_VDrive
WHERE VDriveId = @VDriveId
if(@VHDId is NOT NULL)
BEGIN
DELETE FROM dbo.tbl_WLC_VHD
WHERE VHDId = @VHDId
DELETE FROM dbo.tbl_WLC_PhysicalObject
WHERE PhysicalObjectId = @VHDId
END
if(@ISOId is NOT NULL)
BEGIN
DELETE FROM dbo.tbl_WLC_ISO
WHERE ISOId = @ISOId
DELETE FROM dbo.tbl_WLC_PhysicalObject
WHERE PhysicalObjectId = @ISOId
END
FETCH NEXT FROM vdrive_cursor INTO @VDriveId, @VHDId, @ISOId
END
CLOSE vdrive_cursor
DEALLOCATE vdrive_cursor
-----------------
DECLARE floppy_cursor CURSOR FOR
SELECT VFDId, vFloppyId from
dbo.tbl_WLC_VFloppy WHERE HWProfileId = @ObjectId
DECLARE @vFloppyId uniqueidentifier
DECLARE @vfdId uniqueidentifier
OPEN floppy_cursor
FETCH NEXT FROM floppy_cursor INTO @vfdId, @vFloppyId
WHILE(@@fetch_status = 0)
BEGIN
DELETE FROM dbo.tbl_WLC_VFloppy
WHERE VFloppyId = @vFloppyId
if(@vfdid is NOT NULL)
BEGIN
DELETE FROM dbo.tbl_WLC_VFD
WHERE VFDId = @vfdId
DELETE FROM dbo.tbl_WLC_PhysicalObject
WHERE PhysicalObjectId = @vfdId
END
FETCH NEXT FROM floppy_cursor INTO @vfdId, @vFloppyId
END
CLOSE floppy_cursor
DEALLOCATE floppy_cursor
----------------
DECLARE checkpoint_cursor CURSOR FOR
SELECT VMCheckpointId from
dbo.tbl_WLC_VMCheckpoint WHERE VMId = @ObjectId
DECLARE @vmCheckpointId uniqueidentifier
OPEN checkpoint_cursor
FETCH NEXT FROM checkpoint_cursor INTO @vmCheckpointId
WHILE(@@fetch_status = 0)
BEGIN
DELETE FROM dbo.tbl_WLC_VMCheckpointRelation
WHERE VMCheckpointId = @vmCheckpointId
FETCH NEXT FROM checkpoint_cursor INTO @vmCheckpointId
END
CLOSE checkpoint_cursor
DEALLOCATE checkpoint_cursor
-------------------------
---------Clean checkpoint
DELETE FROM dbo.tbl_WLC_VMCheckpoint
WHERE VMId = @ObjectID
exec [dbo].[prc_VMMigration_Delete_VMInfoAndLUNMappings] @ObjectId
DECLARE @RefreshId uniqueidentifier
exec [dbo].[prc_RR_Refresher_Delete] @ObjectId, @RefreshId
DELETE FROM dbo.tbl_WLC_VAdapter
WHERE HWProfileId = @ObjectId
DELETE FROM dbo.tbl_WLC_VNetworkAdapter
WHERE HWProfileId = @ObjectId
DELETE FROM dbo.tbl_WLC_VCOMPort
WHERE HWProfileId = @ObjectId
DELETE FROM dbo.tbl_WLC_HWProfile
WHERE HWProfileId = @ObjectId
DELETE FROM dbo.tbl_WLC_VMInstance
WHERE VMInstanceId = @ObjectId
DELETE FROM dbo.tbl_WLC_VObject
WHERE ObjectId = @ObjectId
FETCH NEXT FROM custom_cursor INTO @ObjectId
END
CLOSE custom_cursor
DEALLOCATE custom_cursor
COMMIT TRANSACTION T1
確認 DB 選擇正確,然後點擊「執行」。
執行結果。
6. 完成後,重新啟動 Virtual Machine Manager 服務。
以系統管理員身份執行命令提示字元,然後執行下列指令。
> net start vmmservice
7. 開啟 SCVMM 系統管理員主控台,確認狀態遺失的 VM 已刪除。
若是狀態是「更新失敗」另外有一篇「SCVMM 2008 R2 VM Status Tricks」可參考。
1. 關閉 SCVMM 系統管理員主控台。
2. 停止 Virtual Machine Manager 服務。
以系統管理員身份執行命令提示字元,然後執行下列指令。
> net stop vmmservice
3. 執行執行 Microsoft SQL Management Studio,並展開「資料庫/VirtualManagerDB/資料表」。
4. 在 dbo.tbl_WLC_VObject 上按滑鼠右鍵,點擊「開啟資料表」。
5. 將 ObjectState 狀態為 107 (更新失敗)的欄位修改為 220(遺失)。
欄位值代表意義:
The ObjectType means the VM file type: 46 is snapshot, 1 is normal VM, 3 is the VM template.
The ObjectState means the VM status: 0 is running, 1 is stopped, 107 is update failed, 201 is migration failed, 220 is missing, 223 is incomplete configuration, 225 is unsupported cluster configuration …
6. 將狀態改為遺失後,就可以使用上面微軟提供的 RemoveMissingVMs 刪除重覆的 VM。
7. 刪除成功後,再將 Virtual Machine Manager 服務重新啟動,開啟 SCVMM 系統管理員主控台。
沒有留言:
張貼留言