refs #2146 update template to use grubx64.efi and update createbootfile to use a templateDisk to booy by disk and partition
parent
f0b2380044
commit
52b2e645fa
|
@ -1642,45 +1642,57 @@ public function createBootFile(Request $request): JsonResponse
|
|||
return new JsonResponse(['error' => 'FAILED_TO_CREATE_PXE_FILE', 'message' => 'Error al crear el archivo PXE'], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
// Sustituir en la plantilla los marcadores
|
||||
$templateCacheDir = $this->tftpbootDir . '/menu.lst';
|
||||
$templateCachePath = $templateCacheDir . '/templateCache';
|
||||
$templateCacheContent = file_get_contents($templateCachePath);
|
||||
$grubContent = str_replace(
|
||||
['__INFOHOST__', '__OGLIVE__'],
|
||||
[$kernelArgs, basename($ogLiveDir)],
|
||||
$templateCacheContent
|
||||
);
|
||||
$pxeFileName = '01-' . $mac;
|
||||
$pxeFilePath = $templateCacheDir . '/' . $pxeFileName;
|
||||
|
||||
// Nombre del archivo de arranque por cache
|
||||
$pxeFileNameCache = '01-' . $mac;
|
||||
$pxeFilePathCache = $templateCacheDir . '/' . $pxeFileNameCache;
|
||||
// Crear el archivo de arranque por cache
|
||||
if (file_put_contents($pxeFilePathCache, $grubContent) === false) {
|
||||
$httpCode = '500';
|
||||
$this->logger->error(json_encode([
|
||||
'severity' => 'ERROR',
|
||||
'operation' => $operation,
|
||||
'component' => $component,
|
||||
'http_code' => $httpCode,
|
||||
'desc' => 'Failed to create cache PXE file.'
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
return new JsonResponse(['error' => 'FAILED_TO_CREATE_CACHE_PXE_FILE', 'message' => 'Error al crear el archivo de caché PXE'], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
// Generar archivo si la plantilla es oglives cache
|
||||
if ($templateName === 'ogliveCache') {
|
||||
$templateCachePath = $templateCacheDir . '/templateCache';
|
||||
$templateCacheContent = file_get_contents($templateCachePath);
|
||||
$grubContent = str_replace(
|
||||
['__INFOHOST__', '__OGLIVE__'],
|
||||
[$kernelArgs, basename($ogLiveDir)],
|
||||
$templateCacheContent
|
||||
);
|
||||
}
|
||||
// Generar archivo si la plantilla es de tipo disco/partición
|
||||
elseif (in_array($templateName, ['firstDisk_firstPartition', 'firstDisk_secondPartition', 'firstDisk_thirdPartition'])) {
|
||||
$templateDiskPath = $templateCacheDir . '/templateDisk';
|
||||
$templateDiskContent = file_get_contents($templateDiskPath);
|
||||
|
||||
// Determinar DISK, PART y DISKPART en función del templateName
|
||||
$map = [
|
||||
'firstDisk_firstPartition' => ['disk' => '01', 'part' => '01', 'diskpart' => '(hd0,gpt1)'],
|
||||
'firstDisk_secondPartition' => ['disk' => '01', 'part' => '02', 'diskpart' => '(hd0,gpt1)'],
|
||||
'firstDisk_thirdPartition' => ['disk' => '01', 'part' => '03', 'diskpart' => '(hd0,gpt1)'],
|
||||
];
|
||||
|
||||
$diskInfo = $map[$templateName];
|
||||
|
||||
// Sustituir variables en plantilla
|
||||
$grubContent = str_replace(
|
||||
['__DISK__', '__PART__', '__DISKPART__'],
|
||||
[$diskInfo['disk'], $diskInfo['part'], $diskInfo['diskpart']],
|
||||
$templateDiskContent
|
||||
);
|
||||
}
|
||||
// En cualquier otro caso, no se hace nada
|
||||
else {
|
||||
return new JsonResponse(['success' => 'NO_TEMPLATE_ACTION', 'message' => 'No se requiere generar archivo PXE'], Response::HTTP_OK);
|
||||
}
|
||||
|
||||
|
||||
// Creación de fichero de arranque por cache
|
||||
$cacheFilePath = $this->tftpbootDir . '/menu.lst/' . $pxeFileName;
|
||||
if (file_put_contents($cacheFilePath, $grubContent) === false) {
|
||||
// Escribir el archivo PXE final (común a ambos casos)
|
||||
if (file_put_contents($pxeFilePath, $grubContent) === false) {
|
||||
$httpCode = '500';
|
||||
$this->logger->error(json_encode([
|
||||
'severity' => 'ERROR',
|
||||
'operation' => $operation,
|
||||
'component' => $component,
|
||||
'http_code' => $httpCode,
|
||||
'desc' => 'Failed to create cache PXE file.'
|
||||
'desc' => 'Failed to create PXE boot file.'
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
return new JsonResponse(['error' => 'FAILED_TO_CREATE_CACHE_PXE_FILE', 'message' => 'Error al crear el archivo de caché PXE'], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
return new JsonResponse(['error' => 'FAILED_TO_CREATE_PXE_FILE', 'message' => 'Error al crear el archivo de arranque PXE'], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,6 @@ exit
|
|||
|
||||
:uefi_boot
|
||||
echo "Running in UEFI mode - Booting first disk, first partition"
|
||||
sanboot --no-describe --drive 0 --filename \EFI\Part-01-01\Boot\ogloader.efi || echo "Failed to boot in UEFI mode"
|
||||
chain http://__SERVERIP__/tftpboot/grubx64.efi
|
||||
exit
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ exit
|
|||
|
||||
:uefi_boot
|
||||
echo "Running in UEFI mode - Booting first disk, second partition"
|
||||
sanboot --no-describe --drive 0 --filename \EFI\Part-01-02\Boot\ogloader.efi || echo "Failed to boot in UEFI mode"
|
||||
chain http://__SERVERIP__/tftpboot/grubx64.efi
|
||||
exit
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ exit
|
|||
|
||||
:uefi_boot
|
||||
echo "Running in UEFI mode - Booting first disk, third partition"
|
||||
sanboot --no-describe --drive 0 --filename \EFI\Part-01-03\Boot\ogloader.efi || echo "Failed to boot in UEFI mode"
|
||||
chain http://__SERVERIP__/tftpboot/grubx64.efi
|
||||
exit
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue