30 lines
875 B
PowerShell
30 lines
875 B
PowerShell
param(
|
||
[Parameter(Mandatory=$true)][int]$Disk,
|
||
[Parameter(Mandatory=$true)][string]$File
|
||
)
|
||
|
||
$ErrorActionPreference = 'Stop'
|
||
|
||
$data = [IO.File]::ReadAllBytes($File)
|
||
if ($data.Length -lt 513) { throw "Bad GRUB2 MBR image: $File" }
|
||
|
||
$path = "\\.\PhysicalDrive$Disk"
|
||
$fs = [IO.File]::Open($path, [IO.FileMode]::Open, [IO.FileAccess]::ReadWrite, [IO.FileShare]::ReadWrite)
|
||
try {
|
||
$mbr = New-Object byte[] 512
|
||
$fs.Read($mbr, 0, 512) | Out-Null
|
||
|
||
# boot code 0..439; partition table/disk signature 440..511 остаются от целевого диска
|
||
[Array]::Copy($data, 0, $mbr, 0, 440)
|
||
$fs.Position = 0
|
||
$fs.Write($mbr, 0, 512)
|
||
|
||
# core.img (уже с Reed-Solomon, как в рабочем MBR) — сразу после MBR
|
||
$fs.Position = 512
|
||
$fs.Write($data, 512, $data.Length - 512)
|
||
$fs.Flush()
|
||
}
|
||
finally {
|
||
$fs.Close()
|
||
}
|