diff --git a/Public/Functions/Disk.ps1 b/Public/Functions/Disk.ps1 index 9edf2e93d..bf73ef7f3 100644 --- a/Public/Functions/Disk.ps1 +++ b/Public/Functions/Disk.ps1 @@ -1720,7 +1720,11 @@ Author: David Segura - Recast Software [string]$BootLabel = 'USB Boot', [ValidateLength(0,32)] - [string]$DataLabel = 'USB Data' + [string]$DataLabel = 'USB Data', + + #Creates the Boot partition first (at the start of the disk) instead of last + #Lets the Data partition be extended into trailing free space later, e.g. after cloning onto a larger USB drive + [switch]$BootFirst ) #================================================= @@ -1807,11 +1811,20 @@ Author: David Segura - Recast Software Set-Disk -Number $GetUSBDisk.Number -PartitionStyle MBR -ErrorAction Stop } if ($GetUSBDisk.SizeGB -le 2000) { - Write-Verbose '$DataDisk = $GetUSBDisk | New-Partition -Size ($GetUSBDisk.Size - 2GB) -AssignDriveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel $DataLabel' - $DataDisk = $GetUSBDisk | New-Partition -Size ($GetUSBDisk.Size - 2GB) -AssignDriveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel $DataLabel -ErrorAction Stop + if ($BootFirst) { + Write-Verbose '$BootDisk = $GetUSBDisk | New-Partition -Size 2GB -IsActive -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel $BootLabel' + $BootDisk = $GetUSBDisk | New-Partition -Size 2GB -IsActive -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel $BootLabel -ErrorAction Stop - Write-Verbose '$BootDisk = $GetUSBDisk | New-Partition -UseMaximumSize -IsActive -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel $BootLabel' - $BootDisk = $GetUSBDisk | New-Partition -UseMaximumSize -IsActive -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel $BootLabel -ErrorAction Stop + Write-Verbose '$DataDisk = $GetUSBDisk | New-Partition -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel $DataLabel' + $DataDisk = $GetUSBDisk | New-Partition -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel $DataLabel -ErrorAction Stop + } + else { + Write-Verbose '$DataDisk = $GetUSBDisk | New-Partition -Size ($GetUSBDisk.Size - 2GB) -AssignDriveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel $DataLabel' + $DataDisk = $GetUSBDisk | New-Partition -Size ($GetUSBDisk.Size - 2GB) -AssignDriveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel $DataLabel -ErrorAction Stop + + Write-Verbose '$BootDisk = $GetUSBDisk | New-Partition -UseMaximumSize -IsActive -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel $BootLabel' + $BootDisk = $GetUSBDisk | New-Partition -UseMaximumSize -IsActive -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel $BootLabel -ErrorAction Stop + } } #================================================= # -ge 2TB diff --git a/Public/OSDCloud/OSDCloudUSB.ps1 b/Public/OSDCloud/OSDCloudUSB.ps1 index fad033fb0..ab4d137f0 100644 --- a/Public/OSDCloud/OSDCloudUSB.ps1 +++ b/Public/OSDCloud/OSDCloudUSB.ps1 @@ -15,6 +15,10 @@ .PARAMETER fromIsoUrl Specifies the value for fromIsoUrl. + .PARAMETER BootFirst + Switch. Creates the WinPE Boot partition first (at the start of the disk) instead of last. + Lets the Data partition be extended into trailing free space later, e.g. after cloning onto a larger USB drive. + .EXAMPLE New-OSDCloudUSB -WorkspacePath -fromIsoFile Runs New-OSDCloudUSB with common parameters. @@ -41,7 +45,11 @@ #Path to an OSDCloud ISO saved on the internet #This file will be downloaded and mounted and the contents will be copied to the OSDCloud USB [Parameter(ParameterSetName='fromIsoUrl',Mandatory)] - [System.String]$fromIsoUrl + [System.String]$fromIsoUrl, + + #Creates the WinPE Boot partition first (at the start of the disk) instead of last + #Lets the Data partition be extended into trailing free space later, e.g. after cloning onto a larger USB drive + [switch]$BootFirst ) #================================================= # Block @@ -182,18 +190,21 @@ #================================================= # New-BootableUSBDrive #================================================= - $BootableUSBDrive = New-BootableUSBDrive -BootLabel $BootLabel -DataLabel $DataLabel + $BootableUSBDrive = New-BootableUSBDrive -BootLabel $BootLabel -DataLabel $DataLabel -BootFirst:$BootFirst $BootableUSBDrive = $BootableUSBDrive | Select-Object -First 1 #================================================= # Test USB Volumes #================================================= - $WinPEPartition = Get-USBPartition | Where-Object {($_.DiskNumber -eq $BootableUSBDrive.DiskNumber) -and ($_.PartitionNumber -eq 2)} + $WinPEPartitionNumber = if ($BootFirst) { 1 } else { 2 } + $OSDCloudPartitionNumber = if ($BootFirst) { 2 } else { 1 } + + $WinPEPartition = Get-USBPartition | Where-Object {($_.DiskNumber -eq $BootableUSBDrive.DiskNumber) -and ($_.PartitionNumber -eq $WinPEPartitionNumber)} if (-NOT ($WinPEPartition)) { Write-Warning "[$(Get-Date -format s)] Unable to create OSDCloud WinPE Partition" Write-Warning "[$(Get-Date -format s)] Something went very very wrong in this process" Break } - $OSDCloudPartition = Get-USBPartition | Where-Object {($_.DiskNumber -eq $BootableUSBDrive.DiskNumber) -and ($_.PartitionNumber -eq 1)} + $OSDCloudPartition = Get-USBPartition | Where-Object {($_.DiskNumber -eq $BootableUSBDrive.DiskNumber) -and ($_.PartitionNumber -eq $OSDCloudPartitionNumber)} if (-NOT ($OSDCloudPartition)) { Write-Warning "[$(Get-Date -format s)] Unable to create OSDCloud Data Partition" Write-Warning "[$(Get-Date -format s)] Something went very very wrong in this process"