public override bool CheckPrerequisities(ref string[] messages) { List <string> messageList = new List <string>(); logger.LogDebug("Checking critical requirements."); bool osSupported = osHelper.IsOperatingSystemSupported(); if (!osSupported) { messageList.Add("Not supported operating system detected. Only the following Windows systems are supported: Windows 7 (Enterprise,Ultimate), Windows 8, Windows 8.1, Windows 10"); } if (osHelper.IsBitlockerEnabledOnSystemDrive()) { messageList.Add("Migration of operating system to VHD native boot is not supported when BitLocker is enabled. Migration cannot continue."); } if (string.IsNullOrWhiteSpace(migrationData.VhdFileTemporaryFolder)) { messageList.Add("Cannot find any drive with free space to store temporary VHD(x) file."); } IDriveInfo systemDriveInfo = fileSystemHelper.GetSystemDriveInfo(); if (systemDriveInfo.AvailableFreeSpace < (systemDriveInfo.TotalSize / 2) && !migrationData.TemporaryVhdFileIsTheFinalOne) { messageList.Add("Not enough available free space on system drive to place the VHD(x) file. System drive must have at least 50% of free space to perform in place os migration to native VHD boot."); } messages = messageList.ToArray(); return(messageList.Count == 0); }
private void ShrinkVolume() { var systemDriveInfo = fileSystemHelper.GetSystemDriveInfo(); long desiredShrinkSize = migrationData.DesiredTempVhdShrinkSize >> 20; // / (1024 * 1024); string vhdFullName = $"{migrationData.VhdFileTemporaryFolder}\\{migrationData.VhdFileName}"; logger.LogDebug($"Shrinking volume '{vhdFullName}' by {desiredShrinkSize} MB"); List <string> diskpartScriptContent = new List <string>() { $"select vdisk file={vhdFullName}", "attach vdisk", "select partition 1", $"shrink desired={desiredShrinkSize}", "detach vdisk", "exit" }; Policy retryPolicy = Policy .Handle <Exception>() .Retry(onRetry: (exception, retry) => { this.logger.LogWarning(exception, $"Shrinking volume failed {retry} time."); diskpartScriptContent = new List <string>() { $"select vdisk file={vhdFullName}", "select partition 1", $"shrink desired={desiredShrinkSize}", "detach vdisk", "exit" }; }); string diskpartScriptLocation = $"{migrationData.VhdFileTemporaryFolder}\\diskpartScriptContent.txt"; retryPolicy.Execute(() => { using (var sw = fileSystem.File.CreateText(diskpartScriptLocation)) { foreach (string line in diskpartScriptContent) { sw.WriteLine(line); } } fileSystemHelper.ExecuteDiskpart(diskpartScriptLocation, logger); }); //cleanup fileSystem.File.Delete(diskpartScriptLocation); this.ValidateVhdVolumeSize(); }
private static MigrationFlowData BuildMigrationData(OperationModeEnum operationMode, IFileSystemHelper fileSystemHelper, bool addToBootManager) { MigrationFlowData migrationData = new MigrationFlowData(); IDriveInfo systemDriveInfo = fileSystemHelper.GetSystemDriveInfo(); migrationData.OperatingSystemDriveLetter = systemDriveInfo.Name.First(); migrationData.TemporaryVhdFileMaxSize = systemDriveInfo.TotalSize + (200 << 20) /*200MB*/; migrationData.VhdFileName = "VHDNBOM_System_Image.vhdx"; migrationData.VhdFileType = Logic.Models.Enums.VhdType.VhdxDynamic; migrationData.VhdFileTemporaryFolder = vhdTemporaryFolderPath ?? fileSystemHelper.FindBestLocationForVhdTemporaryFolder(); migrationData.AddVhdToBootManager = addToBootManager; if (operationMode == OperationModeEnum.MigrateCurrentOsToVhd) { migrationData.DeleteTemporaryVhdFile = true; migrationData.DestinationVhdMaxFileSize = (systemDriveInfo.AvailableFreeSpace - Constants.FiveGigs + Constants.OneGig) + (200 << 20); migrationData.DesiredTempVhdShrinkSize = (systemDriveInfo.TotalSize - (systemDriveInfo.AvailableFreeSpace - Constants.FiveGigs)); migrationData.VhdFileDestinationFolder = $"{migrationData.OperatingSystemDriveLetter}:\\VHD_Boot"; } return(migrationData); }