refs #198 Adds tftpboot service and pxe protocol

pull/3/head
Luis Gerardo Romero Garcia 2024-02-02 14:56:01 +01:00
parent e96ceed4ee
commit 66e4e2d3cb
24 changed files with 609 additions and 0 deletions

View File

@ -0,0 +1,130 @@
TFTPSERV=tftp
TFTPCFGDIR=/var/lib/tftpboot
function createDirs()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local path_ogboot_base="$1"
# Crear estructura de directorios.
echoAndLog "${FUNCNAME}(): creating directory paths in $path_ogboot_base"
mkdir -p $path_ogboot_base
mkdir -p $path_ogboot_base/bin
mkdir -p $path_ogboot_base/client/{cache,images,log}
mkdir -p $path_ogboot_base/doc
mkdir -p $path_ogboot_base/etc
mkdir -p $path_ogboot_base/lib
mkdir -p $path_ogboot_base/log/clients
ln -fs $path_ogboot_base/log /var/log/ogboot
mkdir -p $TFTPCFGDIR
ln -fs $TFTPCFGDIR $path_ogboot_base/tftpboot
mkdir -p $path_ogboot_base/tftpboot/{menu.lst,grub}
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
return 1
fi
# Crear usuario ficticio.
if id -u $OPENGNSYS_CLIENT_USER &>/dev/null; then
echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENT_USER\" is already created"
else
echoAndLog "${FUNCNAME}(): creating OpenGnsys user"
useradd $OPENGNSYS_CLIENT_USER 2>/dev/null
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error creating OpenGnsys user"
return 1
fi
fi
# Mover el fichero de registro de instalación al directorio de logs.
echoAndLog "${FUNCNAME}(): moving installation log file"
mv $LOG_FILE $OGLOGFILE && LOG_FILE=$OGLOGFILE
chmod 600 $LOG_FILE
echoAndLog "${FUNCNAME}(): directory paths created"
return 0
}
# Copia ficheros de configuración y ejecutables genéricos del servidor.
function copyServerFiles ()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local path_ogboot_base="$1"
# Lista de ficheros y directorios origen y de directorios destino.
local SOURCES=( server/tftpboot \
/usr/lib/shim/shimx64.efi.signed \
/usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed \
)
local TARGETS=( tftpboot \
tftpboot \
tftpboot/grubx64.efi \
)
if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
errorAndLog "${FUNCNAME}(): inconsistent number of array items"
exit 1
fi
# Copiar ficheros.
echoAndLog "${FUNCNAME}(): copying files to server directories"
pushd $WORKDIR/ogboot
local i
for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
if [ -f "${SOURCES[$i]}" ]; then
echoAndLog "Copying ${SOURCES[$i]} to $path_ogboot_base/${TARGETS[$i]}"
cp -a "${SOURCES[$i]}" "${path_ogboot_base}/${TARGETS[$i]}"
elif [ -d "${SOURCES[$i]}" ]; then
echoAndLog "Copying content of ${SOURCES[$i]} to $path_ogboot_base/${TARGETS[$i]}"
cp -a "${SOURCES[$i]}"/* "${path_ogboot_base}/${TARGETS[$i]}"
else
warningAndLog "Unable to copy ${SOURCES[$i]} to $path_ogboot_base/${TARGETS[$i]}"
fi
done
popd
}
############################################################
### Esqueleto para el Servicio pxe y contenedor tftpboot ###
############################################################
function tftpConfigure()
{
echoAndLog "${FUNCNAME}(): Configuring TFTP service."
# Habilitar TFTP y reiniciar Inetd.
if [ -n "$TFTPSERV" ]; then
if [ -f $INETDCFGDIR/$TFTPSERV ]; then
perl -pi -e 's/disable.*/disable = no/' $INETDCFGDIR/$TFTPSERV
else
service=$TFTPSERV
$ENABLESERVICE; $STARTSERVICE
fi
fi
service=$INETDSERV
$ENABLESERVICE; $STARTSERVICE
# comprobamos el servicio tftp
sleep 1
testPxe
}
# Comprueba que haya conexión al servicio TFTP/PXE.
function testPxe ()
{
echoAndLog "${FUNCNAME}(): Checking TFTP service... please wait."
echo "test" >$TFTPCFGDIR/testpxe
tftp -v 127.0.0.1 -c get testpxe /tmp/testpxe && echoAndLog "TFTP service is OK." || errorAndLog "TFTP service is down."
rm -f $TFTPCFGDIR/testpxe /tmp/testpxe
}

View File

@ -0,0 +1,77 @@
Notas sobre arranque remoto de los clientes
===========================================
Desde la versión OpenGnsys 1.0.2 se utiliza Grub4Dos como gestor de arranque en sustitución de PXELinux.
El instalador de OpenGnsys configura por defecto el servicio DHCP para usar el fichero "grldr" como gestor PXE, incluyendo la siguiente cláusula que debe ser común a todos los equipos afectados:
filename "grldr";
En algunos equipos, puede aparecer el siguiente mensaje de error al finalizar la carga de los ficheros de arranque:
llll PXE unload fails: 1
ln este caso, debe sustituirse el fichero por defecto "grldr" por "grldr-0.4.5b", que incluye una versión más actualizado de Grub4Dos, quedando la línea de configuración de DHCP como sigue:
filename "grldr-0.4.5b";
Si se dispone distinto hardware compatible solo con uno de estos ficheros, deberá editarse el fichero de configuracińo de DHCP usando declaraciones para grupos de equipos:
group {
filename "grldr";
host ...
...
}
group {
filename "grldr-0.4.5b";
host ...
...
}
No olvidar reiniciar el servicio DHCP tras cada modificación de su fichero de configuración.
Como cambiar el arranque en red PXELinux por Grub4DOS
=====================================================
NOTA: la siguiente información está anticuada y es válido solo para versiones anteriores a OpenGnsys 1.0.2.
OpenGnsys 1.0.1 usa como gestor PXE el binario pxelinux.0, sin embargo, la actulización a OpenGnsys 1.0.2 sustituye automáticamente dicho gestor por Grub4Dos.
Realizar los siguientes pasos para sutituir "a mano" PXELinux por Grub4Dos como gestor de arranque sin usar el proceso de actualización de OpenGnsys.
Activar el grldr del grub4dos
1) modificar el dhcp, donde aparezca filename "pxelinux.0" por "grldr"
filename "grldr";
2) Reiniciamos el servicio dhcp
/etc/init.d/dhcpd restart
3) Renombrar cambiar el gestor de arranque de la web, para que use grldr.
cp /opt/opengnsys/www/principal/boot.php /opt/opengnsys/www/principal/boot.pxelinux.php
cp /opt/opengnsys/www/principal/boot.grub4dos.php /opt/opengnsys/www/principal/boot.php
cp /opt/opengnsys/www/gestores/gestor_pxe.php /opt/opengnsys/www/gestores/gestor_pxe.pxelinux.php
cp /opt/opengnsys/www/gestores/gestor_pxe_grub4dos.php /opt/opengnsys/www/gestores/gestor_pxe.php
4)
En la funcion ogBoot, de la libreria Boot.lib descomentar los comentarios del if de las líneas 71 a 85, para que quede
#FIXME: activar seguimiento inicio sesion XP con grub4dos
if `ogGetOsVersion $1 $2 | grep "Windows" > /dev/null`
then
dd if=/dev/zero of=${MNTDIR}/ogboot.me bs=1024 count=3
dd if=/dev/zero of=${MNTDIR}/ogboot.firstboot bs=1024 count=3
dd if=/dev/zero of=${MNTDIR}/ogboot.secondboot bs=1024 count=3
ogLoadHiveWindows $1 $2
ogHiveNTRunMachine "cmd /c del c:\ogboot.* " ogcleanboot
ogUpdateHiveWindows
reboot
else
cp $OGLIB/grub4dos/* $MNTDIR # */ (Comentario Doxygen)
##kexec -l $MNTDIR/grub.exe --append=--config-file="find --set-root /$LOADER; chainloader /$LOADER; tpm --init"
kexec -l $MNTDIR/grub.exe --append=--config-file="root (hd$[$1-1],$[$2-1]); chainloader (hd$[$1-1],$[$2-1])/$LOADER; tpm --init"
fi

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,74 @@
# Busca cargadores existentes por orden de prioridad y
# muestra menú con las opciones.
# Si no existe ningún cargador de arranque muestre mensaje de error.
set timeout=30
set detectado='no'
# Compruebo si existen distintos cargadores.
echo "Searching Grub"
search --file --set rootGrub /EFI/grub/Boot/grubx64.efi
if [ "$rootGrub" != "" ]; then
set detectado='si'
menuentry "Grub" {
root="$rootGrub"
chainloader /EFI/grub/Boot/grubx64.efi
}
fi
echo "Searching rEFInd"
search --file --set rootRefind /EFI/refind/shimx64.efi.signed
if [ "$rootRefind" != "" ]; then
menuentry "rEFInd" {
root="$rootRefind"
chainloader /EFI/refind/shimx64.efi.signed
}
fi
echo "Searching Part-01-02"
search --file --set rootP2 /EFI/Part-01-02/Boot/ogloader.efi
if [ "$rootP2" != "" ]; then
set detectado='si'
menuentry "Part-01-02" {
root="$rootP2"
chainloader /EFI/Part-01-02/Boot/ogloader.efi
}
fi
echo "Searching Part-01-03"
search --file --set rootP3 /EFI/Part-01-03/Boot/ogloader.efi
if [ "$rootP3" != "" ]; then
set detectado='si'
menuentry "Part-01-03" {
root="$rootP3"
chainloader /EFI/Part-01-03/Boot/ogloader.efi
}
fi
echo "Searching Microsoft"
search --file --set rootMS /EFI/Microsoft/Boot/bootmgfw.efi
if [ "$rootMS" != "" ]; then
set detectado='si'
menuentry "Microsoft" {
root="$rootMS"
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
fi
echo "Searching Ubuntu"
search --file --set rootUb /EFI/ubuntu/grubx64.efi
if [ "$rootUb" != "" ]; then
set detectado='si'
menuentry "Ubuntu"
root="$rootUb"
chainloader /EFI/ubuntu/grubx64.efi
}
fi
# Si no hay ningún sistema operativo muestro mensaje.
if [ $detectado == 'no' ]; then
menuentry "OpenGnsys no ha detectado ningún sistema operativo" {
# para evitar mensajes de error.
set root="(hd0,gpt1)"
}
fi

View File

@ -0,0 +1,4 @@
##NO-TOCAR-ESTA-LINEA refind
search --file --set root /EFI/refind/shimx64.efi.signed
chainloader /EFI/refind/shimx64.efi.signed
boot

View File

@ -0,0 +1,9 @@
# Cargo configuración PC
configfile=$prefix/01-$net_default_mac
source "$configfile"
# Si no existe anterior cargo configuracion por defecto
# Lo compruebo buscando variables más usuales
if [ "$timeout" == "" -a "$default" == "" ]; then
source "$prefix/default"
fi

View File

@ -0,0 +1,77 @@
##NO-TOCAR-ESTA-LINEA Sin-designar
#
# Arranque por defecto en OpenGnsys
# Busca cargadores existentes por orden de prioridad y
# muestra menú con las opciones
# Si no existe ningún cargador de arranque muestra mensaje de error.
set timeout=30
set detectado='no'
# Compruebo si existen distintos cargadores.
echo "Searching Grub"
search --file --set rootGrub /EFI/grub/Boot/grubx64.efi
if [ "$rootGrub" != "" ]; then
set detectado='si'
menuentry "Grub" {
root="$rootGrub"
chainloader /EFI/grub/Boot/grubx64.efi
}
fi
echo "Searching rEFInd"
search --file --set rootRefind /EFI/refind/shimx64.efi.signed
if [ "$rootRefind" != "" ]; then
menuentry "rEFInd" {
root="$rootRefind"
chainloader /EFI/refind/shimx64.efi.signed
}
fi
echo "Searching Part-01-02"
search --file --set rootP2 /EFI/Part-01-02/Boot/ogloader.efi
if [ "$rootP2" != "" ]; then
set detectado='si'
menuentry "Part-01-02" {
root="$rootP2"
chainloader /EFI/Part-01-02/Boot/ogloader.efi
}
fi
echo "Searching Part-01-03"
search --file --set rootP3 /EFI/Part-01-03/Boot/ogloader.efi
if [ "$rootP3" != "" ]; then
set detectado='si'
menuentry "Part-01-03" {
root="$rootP3"
chainloader /EFI/Part-01-03/Boot/ogloader.efi
}
fi
echo "Searching Microsoft"
search --file --set rootMS /EFI/Microsoft/Boot/bootmgfw.efi
if [ "$rootMS" != "" ]; then
set detectado='si'
menuentry "Microsoft" {
root="$rootMS"
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
}
fi
echo "Searching Ubuntu"
search --file --set rootUb /EFI/ubuntu/grubx64.efi
if [ "$rootUb" != "" ]; then
set detectado='si'
menuentry "Ubuntu"
root="$rootUb"
chainloader /EFI/ubuntu/grubx64.efi
}
fi
# Si no hay ningún sistema operativo muestro mensaje.
if [ $detectado == 'no' ]; then
menuentry "OpenGnsys no ha detectado ningún sistema operativo" {
# para evitar mensajes de error.
set root="(hd0,gpt1)"
}
fi

View File

@ -0,0 +1,4 @@
##NO-TOCAR-ESTA-LINEA 1hd
search --file --set root /EFI/grub/Boot/grubx64.efi
chainloader /EFI/grub/Boot/grubx64.efi
boot

View File

@ -0,0 +1,4 @@
##NO-TOCAR-ESTA-LINEA 1hd-1partition
search --file --set root /EFI/Part-01-01/Boot/ogloader.efi
chainloader /EFI/Part-01-01/Boot/ogloader.efi
boot

View File

@ -0,0 +1,4 @@
##NO-TOCAR-ESTA-LINEA 1hd-2partition
search --file --set root /EFI/Part-01-02/Boot/ogloader.efi
chainloader /EFI/Part-01-02/Boot/ogloader.efi
boot

View File

@ -0,0 +1,4 @@
##NO-TOCAR-ESTA-LINEA 1hd-3partition
search --file --set root /EFI/Part-01-03/Boot/ogloader.efi
chainloader /EFI/Part-01-03/Boot/ogloader.efi
boot

View File

@ -0,0 +1,22 @@
##NO-TOCAR-ESTA-LINEA ogLiveAdmin
set timeout=0
set timeout_style=hidden
set ISODIR=ogLive
set default=0;
echo "OgLive $ISODIR"
menuentry "OgLive $ISODIR" {
# Si no existe el ogLive de ISODIR en la red, inicio ogLive por defecto
for DIR in $ISODIR ogLive; do
if linux (tftp)/$DIR/ogvmlinuz ro boot=oginit quiet splash vga=788 irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=true ogdebug=true ogtmpfs=15 oglivedir=$ISODIR INFOHOST ; then
set DIR=$DIR
break
else
echo "OgLive default"
fi
done
initrd (tftp)/$DIR/oginitrd.img
boot
}

View File

@ -0,0 +1,37 @@
##NO-TOCAR-ESTA-LINEA ogLive
set timeout=0
set timeout_style=hidden
set ISODIR=ogLive
# Si existe ogLive en CACHE lo inicio, si no el de la red
set root=''
echo "OgLive CACHE"
search --file --set root /boot/$ISODIR/ogvmlinuz
if [ "$root" == "" ]; then
echo "OgLive $ISODIR"
set default=1;
else
set default=0;
fi
menuentry "OgLive CACHE" {
linux /boot/$ISODIR/ogvmlinuz ro boot=oginit quiet splash vga=788 irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=false ogdebug=false ogupdateinitrd=true ogtmpfs=15 oglivedir=$ISODIR INFOHOST
initrd /boot/$ISODIR/oginitrd.img
boot
}
menuentry "OgLive $ISODIR" {
# Si no existe el ogLive de ISODIR en la red, inicio ogLive por defecto
for DIR in $ISODIR ogLive; do
if linux (tftp)/$DIR/ogvmlinuz ro boot=oginit quiet splash vga=788 irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=false ogdebug=false ogtmpfs=15 oglivedir=$ISODIR INFOHOST ; then
set DIR=$DIR
break
else
echo "OgLive default"
fi
done
initrd (tftp)/$DIR/oginitrd.img
boot
}

View File

@ -0,0 +1,8 @@
timeout 1
title MBR
keeppxe
chainloader (hd0)+1
rootnoverify (hd0)
boot

View File

@ -0,0 +1,25 @@
color white/blue black/light-gray
timeout 330
default /default
title OGnet (network)
kernel (pd)/ogclient/linux
initrd (pd)/ogclient/initrd.gz
boot
title OGcache
find --set-root /linuz
kernel /linuz ip=dhcp ro boot=og vga=788 irqpoll acpi=on engine=testing reposerver=172.17.36.15
initrd /initrd.img
boot
title OGiso
map --mem (pd)/ogclient.iso (0xFF)
map --hook
root (0xFF)
chainloader (0xFF)
boot
title PXELinux
pxe keep
chainloader --raw (pd)/pxelinux.0

View File

@ -0,0 +1,36 @@
default saved
timeout 1
hiddenmenu
fallback 1 2 3
title firsboot
find --set-root --ignore-floppies /ogboot.me
cmp /ogboot.me /ogboot.firstboot || ls FALLBACK
write /ogboot.firstboot iniciado
chainloader /ntldr
savedefault fallback
boot
title secondboot
find --set-root --ignore-floppies /ogboot.me
cmp /ogboot.me /ogboot.secondboot || ls FALLBACK
write /ogboot.secondboot iniciado
chainloader /ntldr
savedefault fallback
boot
title OpenGnsys-CACHE
find --set-root /boot/ogvmlinuz
kernel /boot/ogvmlinuz ro boot=oginit vga=788 irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=true IP=dhcp repo=172.17.9.249
initrd /boot/oginitrd.img
savedefault fallback
boot
title OpenGnsys-NET
keeppxe
kernel (pd)/ogclient/ogvmlinuz ro boot=oginit vga=788 irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=true IP=dhcp repo=172.17.9.249
initrd (pd)/ogclient/oginitrd.img
savedefault
boot

View File

@ -0,0 +1,6 @@
##NO-TOCAR-ESTA-LINEA Sin-designar
timeout 1
title MBR
chainloader (hd0)+1
rootnoverify (hd0)
boot

View File

@ -0,0 +1,8 @@
##NO-TOCAR-ESTA-LINEA 1hd
timeout 1
title MBR
chainloader (hd0)+1
rootnoverify (hd0)
boot

View File

@ -0,0 +1,8 @@
##NO-TOCAR-ESTA-LINEA 1hd-1partition
timeout 1
title FirstDisk-FirstPartition
root (hd0,0)
chainloader (hd0,0)+1
boot

View File

@ -0,0 +1,6 @@
##NO-TOCAR-ESTA-LINEA 1hd-2partition
timeout 1
title FirstHardDisk-SecondPartition
root (hd0,1)
chainloader (hd0,1)+1
boot

View File

@ -0,0 +1,8 @@
##NO-TOCAR-ESTA-LINEA 1hd-3partition
timeout 1
title FirstDisk-ThirdPartition
root (hd0,2)
chainloader (hd0,2)+1
boot

View File

@ -0,0 +1,20 @@
##NO-TOCAR-ESTA-LINEA ogLiveAdmin
default saved
timeout 1
hiddenmenu
fallback 1 2 3
set ISODIR=ogLive
title OpenGnsys-NET
kernel (pd)/%ISODIR%/ogvmlinuz ro boot=oginit quiet splash vga=788 irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=true ogdebug=true ogupdateinitrd=true ogtmpfs=15 oglivedir=%ISODIR% INFOHOST
initrd (pd)/%ISODIR%/oginitrd.img
boot
title OpenGnsys-NET default
kernel (pd)/ogLive/ogvmlinuz ro boot=oginit vga=788 irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=true ogdebug=true ogupdateinitrd=true ogtmpfs=15 oglivedir=ogLive INFOHOST
initrd (pd)/ogLive/oginitrd.img
boot

View File

@ -0,0 +1,38 @@
##NO-TOCAR-ESTA-LINEA ogLive
default saved
timeout 1
hiddenmenu
fallback 1 2 3 4
set ISODIR=ogLive
title firsboot
find --set-root --ignore-floppies --ignore-cd /ogboot.me checkrange 0x07 parttype > nul
cmp /ogboot.me /ogboot.firstboot || ls FALLBACK
write /ogboot.firstboot iniciado
chainloader +1
boot
title secondboot
find --set-root --ignore-floppies --ignore-cd /ogboot.me checkrange 0x07 parttype > nul
cmp /ogboot.me /ogboot.secondboot || ls FALLBACK
write /ogboot.secondboot iniciado
chainloader +1
boot
title OpenGnsys-CACHE
find --set-root --ignore-floppies --ignore-cd /boot/%ISODIR%/ogvmlinuz
kernel /boot/%ISODIR%/ogvmlinuz ro boot=oginit quiet splash vga=788 irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=false ogdebug=false ogupdateinitrd=true ogtmpfs=15 oglivedir=%ISODIR% INFOHOST
initrd /boot/%ISODIR%/oginitrd.img
boot
title OpenGnsys-NET
kernel (pd)/%ISODIR%/ogvmlinuz ro boot=oginit quiet splash vga=788 irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=false ogdebug=false ogtmpfs=15 oglivedir=%ISODIR% INFOHOST
initrd (pd)/%ISODIR%/oginitrd.img
boot
title OpenGnsys-NET default
kernel (pd)/ogLive/ogvmlinuz ro boot=oginit quiet splash vga=788 irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=false ogdebug=false ogtmpfs=15 oglivedir=ogLive INFOHOST
initrd (pd)/ogLive/oginitrd.img
boot