PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : (Alpine oder CentOs)Linux Installation aus Windows per Script in EFI



Athires
29.09.23, 07:57
Hallo und danke der Aufnahme,
ich bin relativ unbewandert in der Linux Szene, auch wenn ich seit 20 Jahren immer wieder mal damit zu tun habe :D

Vieleicht kann mir jemand mit der (komplexen) aufgabe helfen, ich bin nämlich am verzweifeln.

Kurzer überblick Ist Stand:

Ich habe ein Script, das es mir erlaubt unter einer MBR Konfiguration Windows automatisiert aus Powershell zu installieren. (Siehe Anhang). Ich habe leider keine Möglichkeit das per Laufwerk zu installieren, weil die Geräte meist nicht in meinem Einfluss stehen, sondern per Paketmanagement aktualisiert werden. Dazu gibt es ein Linux Image, das standardmäßig mit Grub oder eigenem Bootloader auf die sda3 bzw. sda4 per DD kopiert werden. Als Kickoff nutzen wir Grub2.
Am Schluss fungiert das Linux als Backupsystem, welches regelmäßig das System weg sichert.

Nun werden alle neuen Geräte mit Efi ausgeliefert. Leider habe ich da nur per remote Zugriff, und kann an den Systemen kein Bootlaufwerk mounten.

Ich habe ein Image vorbereitet, welches in Efi (per Direkter Installation) installiert ist. Leider hat Alpine das dualboot Szenario verweigert (Problem mit dem deaktivierten os-finder) , weshalb wir auch ausweichweise auf Centos wechseln können. Dort konnte ich Windows mit Efi (ohne Secureboot) auf einer Virtuellen MAschine (HyperV) installieren, aber nur mit dem eigenen Bootloader von Centos. Sie VHDX Image habe ich dann als Vorlage kopiert.

Leider lässt sich das Script bei einer Efi Installation nicht übertragen. Ich muss dazu sagen, bei Bootloader bin ich leider nicht so bewandert und Linux kann ich leidlich gut konfigurieren.

Kurz zum Ablauf des Scripts unter einer MBR Konfiguration:
Im ersten schritt verkleinert Linux nach Festplattengrösse die Partitionen. Das Linux wird per DD vom Image (eine VHDX Datei) in die dementsprechenden Partitionen Übertragen. Sda3 ist die Boot/Swap Partition und Sda4 die Datenplatte.
Dann schreibt grub-install den Eintrag in den (Grub)Bootmanager. Wenn ich nun Windows neu starte, kommt die Grub Auswahl von Windows und Linux und ich kann Linux starten.

Hat jemand einen Tipp oder vielleicht auch eine Lösung für mich, wie ich das Grub nun für Efi dazu bringe, in die (Standard) Linux Partition zu wechseln.

Hier das MBR Script:


$RootScript = "C:\Linux_Installer\"
$windows_disk_no = 0
#$windows_part_no = 2
$windows_part_no = (Get-Volume -DriveLetter c | Get-Partition).PartitionNumber
$vhdx_path = join-path -path $RootScript -ChildPath "image/linuximag.vhdx"

# Paths to tool executables
$dd_path = join-path $RootScript "tools\dd\dd.exe"
$grub_path = join-path $RootScript "tools\grub\grub_for_windows\grub-install.exe"
$grub_config_path = join-path $RootScript "config\grub.cfg"
$current_partition_count = (Get-Partition).length
# set dest partition according to current partition count
if ($current_partition_count -ge 3) {
Write-Error "Either Recovery is already installed or this doesnt have the standard partition layout with one Boot and one Windows Partition."
exit 1
}
$dest_boot_part = "\\?\Device\Harddisk0\Partition3"
$dest_os_part = "\\?\Device\Harddisk0\Partition4"
#to disable uwf filter :
# uwfmgr filter disable
$UWFConfig = Get-WmiObject UWF_Filter -Namespace "root\standardcimv2\embedded" ## AuslesenÂ
if ($UWFConfig.CurrentEnabled) {
Write-Error "UWF is still enabled, aborting"
Exit 2
} else {
Write-Information "UWF is disabled, we can proceed"
}

$disk_size = (get-disk 0).Size
if ($disk_size -le 40GB ) {
Write-Error "Disk size is lower then the minimum requirement"
exit 1
}
if ($disk_size -ge 110GB ) {

$windows_target_size = 64GB #
Write-Output "Total disk size is greater or equal then 128GB, windows partition target size set to: $windows_target_size"
} else {
$windows_target_size = 32GB
Write-Output "Total Disk size is lower then 128GB, windows partition target size set to: $windows_target_size"
}

try {
Set-Service -Name defragsvc -StartupType Automatic
Start-Service defragsvc
} catch {
Write-error "Couldnt enable and start Windows Defrag service, this is needed for resizing"
Write-Error $_.exception
exit 1
}
$minsize = (Get-PartitionSupportedSize -DiskNumber 0 -PartitionNumber 2).sizemin

$currentsize = (Get-Partition -DiskNumber 0 -PartitionNumber 2).Size
Write-Output "current size of windows partition $currentsize"
Write-Output "Minimal Size of Windows partition: $minsize"
if ($windows_target_size -lt $minsize) {
Write-Error "Min. size for OS partition $minsize is lower then target size $windows_target_size"
exit 1
}
if (!($currentsize -eq $windows_target_size)) {
Write-Output "Resizing OS partition to $windows_target_size"
try {
Resize-Partition -PartitionNumber $windows_part_no -DiskNumber $windows_disk_no -Size $windows_target_size -ErrorAction Stop

} catch {
Write-Output "Could not resize partition"
exit 1
}
} else {
Write-Output "Windows partition already at target size $windows_target_size"
}

$diskpartfile = New-TemporaryFile
'RESCAN' | out-file $diskpartfile
'SELECT DISK 0' | out-file $diskpartfile -Append
'CREATE PARTITION primary size=50' | out-file $diskpartfile -Append
#'ACTIVE' | out-file $diskpartfile -Append
'create partition primary' | out-file $diskpartfile -Append
'exit' | out-file $diskpartfile -Append
cmd.exe /c "type $diskpartfile | diskpart"

$mountvhd = New-TemporaryFile
'select vdisk file="{0}"' -f $vhdx_path | Out-File $mountvhd
'attach vdisk' | Out-File $mountvhd -Append
cmd.exe /c "type $mountvhd | diskpart"
$image_disk_number = (get-disk | where-object { $_.location -eq $vhdx_path }).Number
if (!$image_disk_number) {
Write-Error "Mounting of $vhdx_path was not successfull."
exit 1
} else {
Write-Output "Succesfull mounted $vhdx_path as disk $image_disk_number"
}
# create disk names for dd
$src_boot_part = "\\?\Device\Harddisk$image_disk_number\Partition1" #vhd
$src_os_part = "\\?\Device\Harddisk$image_disk_number\Partition2"

# Boot partition
Write-Output "Apply boot partition image with dd"
$dd = Start-Process -FilePath $dd_path -ArgumentList "if=$src_boot_part of=$dest_boot_part" -NoNewWindow -Wait -PassThru
if ($dd.ExitCode -gt 0) {
Write-Error "Error applying boot image to $dest_boot_part "
exit 1
}

Write-Output "Apply root partition image with dd"
$dd = Start-Process -FilePath $dd_path -ArgumentList "if=$src_os_part of=$dest_os_part bs=16M" -NoNewWindow -Wait -PassThru
if ($dd.ExitCode -gt 0) {
Write-Error "Error applying root image to $dest_os_part "
exit 1
}


Write-Output "Install grub"
$grub = Start-Process -filepath $grub_path -ArgumentList "--boot-directory=c:\ \\.\PHYSICALDRIVE0" -NoNewWindow -Wait -PassThru
if ($grub.ExitCode -gt 0) {
Write-Error "Error installing grub to mbr"
# exit 1
}
# copy our custom grub config.
Write-Output "copy custom grub config to c:\grub\grub.cfg "
Set-Location $RootScript
copy-item $grub_config_path c:\grub\grub.cfg

# cleanup

Set-Service -Name defragsvc -StartupType Disabled
$dismountvhd = New-TemporaryFile
'select vdisk file="{0}"' -f $vhdx_path | Out-File $dismountvhd
'detach vdisk' | Out-File $dismountvhd -Append
cmd.exe /c "type $dismountvhd | diskpart"

Letzte Anmerkungen:
Ich habe verschiede Möglichkeiten versucht:

- Boot per Grub for Windows: Kernel nicht gefunden oder findet die Efiboot64.efi bzw. grub64.efi nicht.
- Boot über Windows Bootloader, findet er die Grub64.efi oder die Efiboot64.efi auf der Linux Partition nicht.
- alle möglichen Tools wie Grup2win , Lick, usw. hatten nicht den erwünschten Erfolg.

Vieleicht hat ja jemand einen Tipp, wie ich die "wiederhergestellte" Version von Linux auf SDA3 und SDA4 zum laufen bekomme, bzw. richtig ansprechen kann.

Mit besten Grüßen
Athires