source: client/engine/Boot.lib @ 74c04a0

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 74c04a0 was e05993a, checked in by adv <adv@…>, 15 years ago

Trunk Boot.lib: ogNewMbrXP() adaptado opengnsys. ogBoot() insertado tag doxygen version 0.1

git-svn-id: https://opengnsys.es/svn/trunk@661 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 13.7 KB
RevLine 
[b094c59]1#!/bin/bash
2#/**
3#@file    Boot.lib
4#@brief   Librería o clase Boot
5#@class   Boot
6#@brief   Funciones para arranque y post-configuración de sistemas de archivos.
7#@version 0.9
8#@warning License: GNU GPLv3+
9#*/
10
11
12#/**
13#         ogBoot int_ndisk int_npartition
14#@brief   Inicia el proceso de arranque de un sistema de archivos.
[42669ebf]15#@param   int_ndisk      nº de orden del disco
16#@param   int_npartition nº de orden de la partición
[b094c59]17#@return  (activar el sistema de archivos).
18#@exception OG_ERR_FORMAT    Formato incorrecto.
19#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
20#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
21#@exception OG_ERR_NOTOS     La partición no tiene instalado un sistema operativo.
[f5432db7]22#@note    En Linux, debe arrancarse la partición del directorio \c /boot
[e05993a]23#@version 0.1 - Integración para OpenGNSys.
24#@author  Antonio J. Doblas Viso, Universidad de Málaga
25#@date    2008-10-27
[f5432db7]26#@version 0.9 - Adaptación para OpenGNSys.
[b094c59]27#@author  Ramon Gomez, ETSII Universidad de Sevilla
28#@date    2009-09-11
[1e7eaab]29#*/ ##
[42669ebf]30function ogBoot ()
31{
[b094c59]32# Variables locales.
[326cec3]33local PART TYPE MNTDIR PARAMS KERNEL INITRD APPEND FILE LOADER
[b094c59]34
[1e7eaab]35# Si se solicita, mostrar ayuda.
[b094c59]36if [ "$*" == "help" ]; then
37    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
38           "$FUNCNAME 1 1"
39    return
40fi
[1e7eaab]41# Error si no se reciben 2 parámetros.
[b094c59]42[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
43
[1e7eaab]44# Detectar tipo de sistema de archivos y montarlo.
[049eadbe]45PART=$(ogDiskToDev $1 $2) || return $?
[b094c59]46TYPE=$(ogGetFsType $1 $2) || return $?
[f5432db7]47MNTDIR=$(ogMount $1 $2) 2>/dev/null
48[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
[b094c59]49
50case "$TYPE" in
[049eadbe]51    EXT[234]|REISERFS|REISER4|JFS|XFS)
[1e7eaab]52        # Obtiene los parámetros de arranque para Linux.
[f5432db7]53        PARAMS=$(ogLinuxBootParameters $1 $2) || return $?
54        read -e KERNEL INITRD APPEND <<<"$PARAMS"
[1e7eaab]55        # Si no hay kernel, no hay sistema operativo.
[f5432db7]56        [ -z "$KERNEL" ] && ogRaiseError $OG_ERR_NOTOS && return $?
[1e7eaab]57        # Arrancar de partición distinta a la original.
[049eadbe]58        [ -e "$MNTDIR/etc" ] && APPEND=$(echo $APPEND | awk -v P="$PART " '{sub (/root=[-+=_/a-zA-Z0-9]* /,"root="P);print}')
[f5432db7]59        # Configurar kernel Linux con los parámetros leídos de su GRUB.
[049eadbe]60        kexec -l "${MNTDIR}${KERNEL}" --append="$APPEND" --initrd="${MNTDIR}${INITRD}"
[f5432db7]61        ;;
62    NTFS|HNTFS|FAT32|HFAT32)
[1e7eaab]63        # Compruebar si hay un cargador de Windows.
[f5432db7]64        for f in io.sys ntldr bootmgr; do
65            FILE="$(ogGetPath $1 $2 $f 2>/dev/null)"
[d10549b]66            [ -n "$FILE" ] && LOADER="$f"
[f5432db7]67        done
68        [ -z "$LOADER" ] && ogRaiseError $OG_ERR_NOTOS && return $?
69        # Activar la partición y copiar Grub4DOS.
70        ogSetPartitionActive $1 $2
[1e7eaab]71        cp $OGLIB/grub4dos/* $MNTDIR    # */ (Comentario Doxygen)
[d10549b]72        #kexec -l $MNTDIR/grub.exe --append=--config-file="find --set-root /$LOADER; chainloader /$LOADER; tpm --init"
73        kexec -l $MNTDIR/grub.exe --append=--config-file="root (hd$[$1-1],$[$2-1]); chainloader (hd$[$1-1],$[$2-1])/$LOADER; tpm --init"
[f5432db7]74        ;;
75    *)  ogRaiseError $OG_ERR_PARTITION "$1, $2"
[326cec3]76        return $?
[f5432db7]77        ;;
[b094c59]78esac
79
[1e7eaab]80# Arrancar.
[b094c59]81kexec -e
82}
83
84
85#/**
[3e1561d]86#         ogGetRegistryValue path_mountpoint str_registrytype str_valuename
87#@brief   Devuelve el dato de un valor del registro de Windows.
[42669ebf]88#@param   path_mountpoint  directorio donde está montado el sistema Windows
89#@param   str_registrytype tipo de registro a leer
90#@param   str_valuename    valor de registro
[3e1561d]91#@return  str_valuedata - valor de la clave.
[055adcf]92#@exception OG_ERR_FORMAT    Formato incorrecto.
[f5432db7]93#@exception OG_ERR_NOTFOUND  Disco o partición no corresponden con un dispositivo.
[055adcf]94#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
95#@note    registrytype = { default, sam, security, software, system, components }
96#@warning Requisitos: chntpw, awk
97#@warning La partición de Windows debe estar montada previamente.
[f5432db7]98#@version 0.9 - Adaptación para OpenGNSys.
[055adcf]99#@author  Ramon Gomez, ETSII Universidad de Sevilla
100#@date    2009-09-11
[1e7eaab]101#*/ ##
[42669ebf]102function ogGetRegistryValue ()
103{
[055adcf]104# Variables locales.
[50a094c]105local FILE FILENT FILEXP
[055adcf]106
[1e7eaab]107# Si se solicita, mostrar ayuda.
[055adcf]108if [ "$*" == "help" ]; then
109    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key"
110    return
111fi
[1e7eaab]112# Error si no se reciben 3 parámetros.
[055adcf]113[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
114
[1e7eaab]115# Camino del fichero de registro en NT/2000 o XP/Vista/7.
[055adcf]116FILENT=$(ogGetPath "/$1/winnt/system32/config/$2")
[945b003]117[ -f $FILENT ] && FILE="$FILENT"
[055adcf]118FILEXP=$(ogGetPath "/$1/windows/system32/config/$2")
[945b003]119[ -f $FLEHXP ] && FILE="$FILEXP"
[055adcf]120[ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $?
121
[1e7eaab]122# Devolver el dato del valor de registro.
123# /* (comentario Doxygen)
[055adcf]124chntpw $FILE << FIN 2>/dev/null | awk '/> Value/ {getline;print $0;}'
125cd ${3%\\*}
126cat ${3##*\\}
127q
128FIN
[42669ebf]129# (comentario Doxygen) */
[055adcf]130}
131
132
133#/**
[3e1561d]134#         ogGetWindowsName int_ndisk int_npartition
135#@brief   Muestra el nombre del equipo en el registro de Windows.
[42669ebf]136#@param   int_ndisk      nº de orden del disco
137#@param   int_npartition nº de orden de la partición
[3e1561d]138#@return  str_name - nombre del equipo
139#@exception OG_ERR_FORMAT    Formato incorrecto.
140#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
141#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[f5432db7]142#@version 0.9 - Adaptación para OpenGNSys.
[3e1561d]143#@author  Ramon Gomez, ETSII Universidad de Sevilla
144#@date    2009-09-23
[1e7eaab]145#*/ ##
[42669ebf]146function ogGetWindowsName ()
147{
[3e1561d]148# Variables locales.
149local PART MNTDIR
150
[1e7eaab]151# Si se solicita, mostrar ayuda.
[3e1561d]152if [ "$*" == "help" ]; then
153    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
154           "$FUNCNAME 1 1  ==>  PRACTICA-PC"
155    return
156fi
[1e7eaab]157# Error si no se reciben 2 parámetros.
[3e1561d]158[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
159
[1e7eaab]160# Montar el sistema de archivos.
[f5432db7]161MNTDIR=$(ogMount $1 $2) 2>/dev/null
162[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
[3e1561d]163
[1e7eaab]164# Obtener dato del valor de registro.
[3e1561d]165ogGetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName'
166}
167
168
169#/**
[50a094c]170#         ogListRegistryKeys path_mountpoint str_registrytype str_key
[3e1561d]171#@brief   Lista los nombres de claves de una determinada clave del registro de Windows.
[42669ebf]172#@param   path_mountpoint  directorio donde está montado el sistema Windows
173#@param   str_registrytype tipo de registro a leer
174#@param   str_key          clave de registro
175#@return  str_key ... - lista de claves de registro
[50a094c]176#@exception OG_ERR_FORMAT    Formato incorrecto.
177#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
178#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
179#@note    registrytype = { default, sam, security, software, system, components }
180#@warning Requisitos: chntpw, awk
181#@warning La partición de Windows debe estar montada previamente.
[f5432db7]182#@version 0.9 - Adaptación para OpenGNSys.
[50a094c]183#@author  Ramon Gomez, ETSII Universidad de Sevilla
184#@date    2009-09-23
[1e7eaab]185#*/ ##
[42669ebf]186function ogListRegistryKeys ()
187{
[50a094c]188# Variables locales.
189local FILE FILENT FILEXP
190
[1e7eaab]191# Si se solicita, mostrar ayuda.
[50a094c]192if [ "$*" == "help" ]; then
193    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key"
194    return
195fi
[1e7eaab]196# Error si no se reciben 3 parámetros.
[50a094c]197[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
198
[1e7eaab]199# Camino del fichero de registro en NT/2000 o XP/Vista/7.
[50a094c]200FILENT=$(ogGetPath "/$1/winnt/system32/config/$2")
[945b003]201[ -f $FILENT ] && FILE="$FILENT"
[50a094c]202FILEXP=$(ogGetPath "/$1/windows/system32/config/$2")
[945b003]203[ -f $FLEHXP ] && FILE="$FILEXP"
[50a094c]204[ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $?
205
[1e7eaab]206# Devolver la lista de claves de registro.
[50a094c]207chntpw $FILE << FIN 2>/dev/null | awk 'BEGIN {FS="[<>]"} $1~/^  $/ {print $2}'
208ls $3
209q
210FIN
211}
212
213
214#/**
[4c63eb9]215#         ogLinuxBootParameters int_ndisk int_npartition
[b094c59]216#@brief   Muestra los parámetros de arranque de un sistema de archivos Linux.
[42669ebf]217#@param   int_ndisk      nº de orden del disco
218#@param   int_npartition nº de orden de la partición
219#@return  str_kernel str_initrd str_parameters ...
[b094c59]220#@exception OG_ERR_FORMAT    Formato incorrecto.
221#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
222#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[055adcf]223#@warning Función básica usada por \c ogBoot
224#@version 0.9 - Primera adaptación para OpenGNSys.
[b094c59]225#@author  Ramon Gomez, ETSII Universidad de Sevilla
226#@date    2009-09-11
[1e7eaab]227#*/ ##
[42669ebf]228function ogLinuxBootParameters ()
229{
[b094c59]230# Variables locales.
[4c63eb9]231local MNTDIR CONF
[b094c59]232
[1e7eaab]233# Si se solicita, mostrar ayuda.
[b094c59]234if [ "$*" == "help" ]; then
235    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
236           "$FUNCNAME 1 2  ==>  ..."
237    return
238fi
[1e7eaab]239# Error si no se reciben 2 parámetros.
[b094c59]240[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
241
[1e7eaab]242# Detectar id. de tipo de partición y codificar al mnemonico.
[f5432db7]243MNTDIR=$(ogMount $1 $2) 2>/dev/null
244[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
[b094c59]245
246# Fichero de configuración de GRUB.
247CONF="$MNTDIR/boot/grub/menu.lst"
[ee4a96e]248[ ! -e $CONF ] && CONF="$MNTDIR/boot/grub/grub.cfg"
249[ ! -e $CONF ] && ogRaiseError $OG_ERR_NOTFOUND "grub.cfg" && return $?
[b094c59]250
[1e7eaab]251# Toma del fichero de configuracion los valores del kernel, initrd
[ee4a96e]252#       y parámetros de arranque usando las cláusulas por defecto
253#       ("default" en GRUB1, "set default" en GRUB2)
254#       y los formatea para que sean compatibles con \c kexec .  */
[1e7eaab]255# /* (comentario Doxygen)
[b094c59]256awk 'BEGIN {cont=-1;}
257     $1~/^default/      {sub(/=/," "); def=$2;}
[18f4bc2]258     $1~/^set/ && $2~/^default/ {gsub(/[="]/," "); def=$3;}
[ee4a96e]259     $1~/^title|^menuentry/ {cont++}
260     $1~/^kernel|^linux/ {if (def==cont) {
[b094c59]261                            kern=$2;
[1e7eaab]262                            sub($1,"");sub($1,"");sub(/^[ \t]*/,"");app=$0}  # /* (comentario Doxygen)
[b094c59]263                        }
264     $1~/^initrd/       {if (def==cont) init=$2}
265     END {if (kern!="") printf("%s %s %s", kern,init,app)}
266    ' $CONF
[1e7eaab]267# */ (comentario Doxygen)
[b094c59]268}
269
[3e1561d]270
271
272#/**
273#         ogSetRegistryValue path_mountpoint str_registrytype str_valuename str_valuedata
274#@brief   Establece el dato asociado a un valor del registro de Windows.
[42669ebf]275#@param   path_mountpoint  directorio donde está montado el sistema Windows
276#@param   str_registrytype tipo de registro
277#@param   str_valuename    nombre del valor de registro
278#@param   str_valuedata    dato del valor de registro
[3e1561d]279#@return  (nada)
280#@exception OG_ERR_FORMAT    Formato incorrecto.
[f5432db7]281#@exception OG_ERR_NOTFOUND  Disco o partición no corresponden con un dispositivo.
[3e1561d]282#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
283#@note    registrytype = { default, sam, security, software, system, components }
284#@warning Requisitos: chntpw, awk
285#@warning La partición de Windows debe estar montada previamente.
[f5432db7]286#@version 0.9 - Adaptación para OpenGNSys.
[3e1561d]287#@author  Ramon Gomez, ETSII Universidad de Sevilla
288#@date    2009-09-24
[1e7eaab]289#*/ ##
[42669ebf]290function ogSetRegistryValue ()
291{
[3e1561d]292# Variables locales.
293local FILE FILENT FILEXP
294
[42669ebf]295# Si se solicita, mostrar ayuda.
[3e1561d]296if [ "$*" == "help" ]; then
297    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key"
298    return
299fi
[42669ebf]300# Error si no se reciben 4 parámetros.
[3e1561d]301[ $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $?
302
[42669ebf]303# Camino del fichero de registro en NT/2000 o XP/Vista/7.
[3e1561d]304FILENT=$(ogGetPath "/$1/winnt/system32/config/$2")
[945b003]305[ -f $FILENT ] && FILE="$FILENT"
[3e1561d]306FILEXP=$(ogGetPath "/$1/windows/system32/config/$2")
[945b003]307[ -f $FLEHXP ] && FILE="$FILEXP"
[3e1561d]308[ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $?
309
[42669ebf]310# Cambiar el dato del valor de registro.
[f5432db7]311chntpw $FILE << FIN &>/dev/null
[3e1561d]312ed $3
313$4
314q
315y
316FIN
317}
318
319
320#/**
321#         ogSetWindowsName int_ndisk int_npartition str_name
322#@brief   Establece el nombre del equipo en el registro de Windows.
[42669ebf]323#@param   int_ndisk      nº de orden del disco
324#@param   int_npartition nº de orden de la partición
325#@param   str_name       nombre asignado
[3e1561d]326#@return  (nada)
327#@exception OG_ERR_FORMAT    Formato incorrecto.
328#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
329#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
[f5432db7]330#@version 0.9 - Adaptación a OpenGNSys.
[3e1561d]331#@author  Ramon Gomez, ETSII Universidad de Sevilla
332#@date    2009-09-24
[1e7eaab]333#*/ ##
[42669ebf]334function ogSetWindowsName ()
335{
[3e1561d]336# Variables locales.
337local PART MNTDIR NAME
338
[1e7eaab]339# Si se solicita, mostrar ayuda.
[3e1561d]340if [ "$*" == "help" ]; then
341    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
342           "$FUNCNAME 1 1 PRACTICA-PC"
343    return
344fi
[1e7eaab]345# Error si no se reciben 3 parámetros.
[3e1561d]346[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
347
[42669ebf]348# Montar el sistema de archivos.
[f5432db7]349MNTDIR=$(ogMount $1 $2) 2>/dev/null
350[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
[3e1561d]351NAME="$3"
352
[1e7eaab]353# Modificar datos de los valores de registro.
[f5432db7]354ogSetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' "$NAME"
355ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\Hostname' "$NAME"
356ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV Hostname' "$NAME"
[3e1561d]357}
358
[f5432db7]359
[38231e9]360
361#/**
362#         ogNewMbrXP int_ndisk
363#@brief   Genera un nuevo Master Boot Record en el disco duro indicado, compatible con los SO tipo Windows
[42669ebf]364#@param   int_ndisk      nº de orden del disco
[945b003]365#@return  salida del programa my-sys
[38231e9]366#@exception OG_ERR_FORMAT    Formato incorrecto.
367#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
368#@version 0.9 - Adaptación a OpenGNSys.
369#@author  Antonio J. Doblas Viso. Universidad de Málaga
370#@date    2009-09-24
371#*/ ##
372
[e05993a]373function ogNewMbrXP ()
374{
[38231e9]375# Variables locales.
376local PART
377
378# Si se solicita, mostrar ayuda.
379if [ "$*" == "help" ]; then
380    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \
381           "$FUNCNAME 1 "
382    return
[945b003]383fi
[38231e9]384# Error si no se reciben 1 parámetros.
385[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
386
[6e139c9]387PART="$(ogDiskToDev $1)" || return $?
[38231e9]388ms-sys -z -f $PART
389ms-sys -m -f $PART
[945b003]390}
[42669ebf]391
Note: See TracBrowser for help on using the repository browser.