mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Removed the need for Insider ADK but still allow optimize FFU
Optimize-FFU is broken due to the Recovery partition not having a name. dism checks for the presence of a name for each partition and if it doesn't have one, optimize-FFU breaks. The fix is in the ffuprovider.dll in the 25255 branch, which is in the Insider ADK. The public release for that isn't coming soon, and using the Insider ADK requires test signing/test mode to be turned on and secureboot disabled. This causes issues with systems that have virtualization-based security. Due to this, changing the code back to not creating a recovery partition while building the FFU, and creating the recovery partition during deployment and then letting Windows copy in and configure WinRE after. Later this year, whenever the ADK gets released, I'll update the script to revert this behavior.
This commit is contained in:
@@ -167,6 +167,7 @@ param(
|
|||||||
[string]$ProductKey,
|
[string]$ProductKey,
|
||||||
[bool]$BuildUSBDrive
|
[bool]$BuildUSBDrive
|
||||||
)
|
)
|
||||||
|
$version = '2305'
|
||||||
|
|
||||||
if (($InstallOffice -eq $true) -and ($InstallApps -eq $false)) {
|
if (($InstallOffice -eq $true) -and ($InstallApps -eq $false)) {
|
||||||
throw "If variable InstallOffice is set to `$true, InstallApps must also be set to `$true."
|
throw "If variable InstallOffice is set to `$true, InstallApps must also be set to `$true."
|
||||||
@@ -239,6 +240,7 @@ function LogVariableValues {
|
|||||||
)
|
)
|
||||||
|
|
||||||
$allVariables = Get-Variable -Scope Script | Where-Object { $_.Name -notin $excludedVariables }
|
$allVariables = Get-Variable -Scope Script | Where-Object { $_.Name -notin $excludedVariables }
|
||||||
|
Writelog "Script version: $version"
|
||||||
WriteLog 'Logging variables'
|
WriteLog 'Logging variables'
|
||||||
foreach ($variable in $allVariables) {
|
foreach ($variable in $allVariables) {
|
||||||
$variableName = $variable.Name
|
$variableName = $variable.Name
|
||||||
@@ -848,7 +850,8 @@ function New-FFU {
|
|||||||
$FFUFile = "$FFUCaptureLocation\$FFUFileName"
|
$FFUFile = "$FFUCaptureLocation\$FFUFileName"
|
||||||
#Capture the FFU
|
#Capture the FFU
|
||||||
WriteLog 'Capturing FFU from VHDX file'
|
WriteLog 'Capturing FFU from VHDX file'
|
||||||
Invoke-Process cmd "/c ""$DandIEnv"" && dism /Capture-FFU /ImageFile:$FFUFile /CaptureDrive:\\.\PhysicalDrive$($vhdxDisk.DiskNumber) /Name:$($winverinfo.Name)$($winverinfo.DisplayVersion)$($winverinfo.SKU) /Compress:Default"
|
#Invoke-Process cmd "/c ""$DandIEnv"" && dism /Capture-FFU /ImageFile:$FFUFile /CaptureDrive:\\.\PhysicalDrive$($vhdxDisk.DiskNumber) /Name:$($winverinfo.Name)$($winverinfo.DisplayVersion)$($winverinfo.SKU) /Compress:Default"
|
||||||
|
Invoke-Process cmd "/c dism /Capture-FFU /ImageFile:$FFUFile /CaptureDrive:\\.\PhysicalDrive$($vhdxDisk.DiskNumber) /Name:$($winverinfo.Name)$($winverinfo.DisplayVersion)$($winverinfo.SKU) /Compress:Default"
|
||||||
WriteLog 'FFU Capture complete'
|
WriteLog 'FFU Capture complete'
|
||||||
WriteLog 'Sleeping 60 seconds before dismount of VHDX'
|
WriteLog 'Sleeping 60 seconds before dismount of VHDX'
|
||||||
Dismount-ScratchVhdx -VhdxPath $VHDXPath
|
Dismount-ScratchVhdx -VhdxPath $VHDXPath
|
||||||
@@ -879,7 +882,8 @@ function New-FFU {
|
|||||||
}
|
}
|
||||||
#Optimize FFU
|
#Optimize FFU
|
||||||
WriteLog 'Optimizing FFU - This will take a few minutes, please be patient'
|
WriteLog 'Optimizing FFU - This will take a few minutes, please be patient'
|
||||||
Invoke-Process cmd "/c ""$DandIEnv"" && dism /optimize-ffu /imagefile:$FFUFile"
|
#Invoke-Process cmd "/c ""$DandIEnv"" && dism /optimize-ffu /imagefile:$FFUFile"
|
||||||
|
Invoke-Process cmd "/c dism /optimize-ffu /imagefile:$FFUFile"
|
||||||
WriteLog 'Optimizing FFU complete'
|
WriteLog 'Optimizing FFU complete'
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1163,7 +1167,7 @@ try {
|
|||||||
$osPartitionDriveLetter = $osPartition[1].DriveLetter
|
$osPartitionDriveLetter = $osPartition[1].DriveLetter
|
||||||
$WindowsPartition = $osPartitionDriveLetter + ":\"
|
$WindowsPartition = $osPartitionDriveLetter + ":\"
|
||||||
|
|
||||||
$recoveryPartition = New-RecoveryPartition -VhdxDisk $vhdxDisk -OsPartition $osPartition[1] -RecoveryPartitionSize $RecoveryPartitionSize -DataPartition $dataPartition
|
#$recoveryPartition = New-RecoveryPartition -VhdxDisk $vhdxDisk -OsPartition $osPartition[1] -RecoveryPartitionSize $RecoveryPartitionSize -DataPartition $dataPartition
|
||||||
|
|
||||||
WriteLog "All necessary partitions created."
|
WriteLog "All necessary partitions created."
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -127,26 +127,27 @@ WriteLog "Physical DeviceID is $PhysicalDeviceID"
|
|||||||
$DiskID = $PhysicalDeviceID.substring($PhysicalDeviceID.length - 1,1)
|
$DiskID = $PhysicalDeviceID.substring($PhysicalDeviceID.length - 1,1)
|
||||||
WriteLog "DiskID is $DiskID"
|
WriteLog "DiskID is $DiskID"
|
||||||
|
|
||||||
|
#COMMENT THIS WHOLE BLOCK OUT ONCE FFUPROVIDER FIX IS IN
|
||||||
#Modify diskpart answer files if DiskID not 0
|
#Modify diskpart answer files if DiskID not 0
|
||||||
# $UEFIFFUPartitions = 'x:\CreateUEFI-FFU-Partitions.txt'
|
# $UEFIFFUPartitions = 'x:\CreateUEFI-FFU-Partitions.txt'
|
||||||
# $ExtendPartition = 'x:\ExtendPartition-UEFI.txt'
|
$ExtendPartition = 'x:\ExtendPartition-UEFI.txt'
|
||||||
|
|
||||||
# If ($DiskID -ne '0'){
|
If ($DiskID -ne '0'){
|
||||||
# WriteLog 'DiskID is not 0. Need to modify diskpart answer files'
|
WriteLog 'DiskID is not 0. Need to modify diskpart answer files'
|
||||||
# try {
|
# try {
|
||||||
# Set-DiskpartAnswerFiles $UEFIFFUPartitions $DiskID
|
# Set-DiskpartAnswerFiles $UEFIFFUPartitions $DiskID
|
||||||
# }
|
# }
|
||||||
# catch {
|
# catch {
|
||||||
# WriteLog "Modifying $UEFIFFUPartitions failed with error: $_"
|
# WriteLog "Modifying $UEFIFFUPartitions failed with error: $_"
|
||||||
# }
|
# }
|
||||||
|
|
||||||
# try {
|
try {
|
||||||
# Set-DiskpartAnswerFiles $ExtendPartition $DiskID
|
Set-DiskpartAnswerFiles $ExtendPartition $DiskID
|
||||||
# }
|
}
|
||||||
# catch {
|
catch {
|
||||||
# WriteLog "Modifying $ExtendPartition failed with error: $_"
|
WriteLog "Modifying $ExtendPartition failed with error: $_"
|
||||||
# }
|
}
|
||||||
# }
|
}
|
||||||
|
|
||||||
#Find FFU Files
|
#Find FFU Files
|
||||||
[array]$FFUFiles = @(Get-ChildItem -Path $USBDrive*.ffu)
|
[array]$FFUFiles = @(Get-ChildItem -Path $USBDrive*.ffu)
|
||||||
@@ -472,18 +473,20 @@ else{
|
|||||||
# }
|
# }
|
||||||
# }
|
# }
|
||||||
|
|
||||||
#Extend Windows partition and create recovery partition
|
#COMMENT THIS WHOLE BLOCK OUT AFTER FFUPROVIDER FIX IS IN
|
||||||
# Writelog 'Extending Windows partition'
|
# Extend Windows partition and create recovery partition
|
||||||
# Invoke-Process diskpart.exe "/S $ExtendPartition"
|
Writelog 'Extending Windows partition'
|
||||||
# if($LASTEXITCODE -eq 0){
|
Invoke-Process diskpart.exe "/S $ExtendPartition"
|
||||||
# WriteLog 'Successfully extended Windows partition and created recovery partition'
|
if($LASTEXITCODE -eq 0){
|
||||||
# }
|
WriteLog 'Successfully extended Windows partition and created recovery partition'
|
||||||
# else{
|
}
|
||||||
# Writelog "Failed to extend Windows partition and/or create recovery partition - LastExitCode = $LASTEXITCODE"
|
else{
|
||||||
# }
|
Writelog "Failed to extend Windows partition and/or create recovery partition - LastExitCode = $LASTEXITCODE"
|
||||||
|
}
|
||||||
|
|
||||||
|
#UNCOMMENT THIS AFTER FFUPROVIDER FIX IS IN
|
||||||
#Set W: drive letter to Windows partition
|
#Set W: drive letter to Windows partition
|
||||||
Get-Disk | Where-Object Number -eq $DiskID | Get-Partition | Where-Object PartitionNumber -eq 3 | Set-Partition -NewDriveLetter W
|
#Get-Disk | Where-Object Number -eq $DiskID | Get-Partition | Where-Object PartitionNumber -eq 3 | Set-Partition -NewDriveLetter W
|
||||||
|
|
||||||
#Copy modified WinRE if folder exists, else copy inbox WinRE
|
#Copy modified WinRE if folder exists, else copy inbox WinRE
|
||||||
$WinRE = $USBDrive + "WinRE\winre.wim"
|
$WinRE = $USBDrive + "WinRE\winre.wim"
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
select disk 0
|
||||||
|
select partition 3
|
||||||
|
Assign letter="W"
|
||||||
|
shrink minimum=1000
|
||||||
|
create partition primary
|
||||||
|
format quick fs=ntfs label="Recovery"
|
||||||
|
assign letter="R"
|
||||||
|
set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
|
||||||
|
gpt attributes=0x8000000000000001
|
||||||
|
exit
|
||||||
Reference in New Issue
Block a user