source: client/engine/Boot.lib.testing @ 22542c6

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 22542c6 was 1b804cc, checked in by ramon <ramongomez@…>, 14 years ago

versión 1.0.2: plantillas para crear nuevas funciones para gestión del registro de Windows.

git-svn-id: https://opengnsys.es/svn/branches/version1.0@1991 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 16.3 KB
Line 
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 1.0.1
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.
15#@param   int_ndisk      nº de orden del disco
16#@param   int_npartition nº de orden de la partición
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.
22#@note    En Linux, debe arrancarse la partición del directorio \c /boot
23#@version 0.1 - Integracion para OpenGNSys. - EAC: HDboot(); BootLinuxEX() en Boot.lib 
24#@author  Antonio J. Doblas Viso, Universidad de Malaga
25#@date    2008-10-27
26#@version 0.9 - Adaptacion para OpenGNSys.
27#@author  Ramon Gomez, ETSII Universidad de Sevilla
28#@date    2009-09-11
29#*/ ##
30function ogBoot ()
31{
32# Variables locales.
33local PART TYPE MNTDIR PARAMS KERNEL INITRD APPEND FILE LOADER
34
35# Si se solicita, mostrar ayuda.
36if [ "$*" == "help" ]; then
37    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
38           "$FUNCNAME 1 1"
39    return
40fi
41# Error si no se reciben 2 parámetros.
42[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
43
44# Detectar tipo de sistema de archivos y montarlo.
45PART=$(ogDiskToDev $1 $2) || return $?
46TYPE=$(ogGetFsType $1 $2) || return $?
47MNTDIR=$(ogMount $1 $2) 2>/dev/null
48[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
49
50case "$TYPE" in
51    EXT[234]|REISERFS|REISER4|JFS|XFS)
52        # Obtiene los parámetros de arranque para Linux.
53        PARAMS=$(ogLinuxBootParameters $1 $2) || return $?
54        read -e KERNEL INITRD APPEND <<<"$PARAMS"
55        # Si no hay kernel, no hay sistema operativo.
56        [ -z "$KERNEL" ] && ogRaiseError $OG_ERR_NOTOS && return $?
57        # Arrancar de partición distinta a la original.
58        [ -e "$MNTDIR/etc" ] && APPEND=$(echo $APPEND | awk -v P="$PART " '{sub (/root=[-+=_/a-zA-Z0-9]* /,"root="P);print}')
59        # Configurar kernel Linux con los parámetros leídos de su GRUB.
60        kexec -l "${MNTDIR}${KERNEL}" --append="$APPEND" --initrd="${MNTDIR}${INITRD}"
61        ;;
62    NTFS|FAT32)
63        # Compruebar si hay un cargador de Windows.
64        for f in io.sys ntldr bootmgr; do
65            FILE="$(ogGetPath $1 $2 $f 2>/dev/null)"
66            [ -n "$FILE" ] && LOADER="$f"
67        done
68        [ -z "$LOADER" ] && ogRaiseError $OG_ERR_NOTOS && return $?
69        # Activar la partición y copiar Grub4DOS.
70        ogSetPartitionActive $1 $2
71        cp $OGLIB/grub4dos/* $MNTDIR    # */ (Comentario Doxygen)
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"
74        ;;
75    *)  ogRaiseError $OG_ERR_PARTITION "$1, $2"
76        return $?
77        ;;
78esac
79
80# Arrancar.
81kexec -e
82}
83
84
85#/**
86#         ogGetWindowsName int_ndisk int_npartition
87#@brief   Muestra el nombre del equipo en el registro de Windows.
88#@param   int_ndisk      nº de orden del disco
89#@param   int_npartition nº de orden de la partición
90#@return  str_name - nombre del equipo
91#@exception OG_ERR_FORMAT    Formato incorrecto.
92#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
93#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
94#@version 0.9 - Adaptación para OpenGNSys.
95#@author  Ramon Gomez, ETSII Universidad de Sevilla
96#@date    2009-09-23
97#*/ ##
98function ogGetWindowsName ()
99{
100# Variables locales.
101local PART MNTDIR
102
103# Si se solicita, mostrar ayuda.
104if [ "$*" == "help" ]; then
105    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
106           "$FUNCNAME 1 1  ==>  PRACTICA-PC"
107    return
108fi
109# Error si no se reciben 2 parámetros.
110[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
111
112# Montar el sistema de archivos.
113MNTDIR=$(ogMount $1 $2) 2>/dev/null
114[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
115
116# Obtener dato del valor de registro.
117ogGetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName'
118}
119
120
121#/**
122#         ogLinuxBootParameters int_ndisk int_npartition
123#@brief   Muestra los parámetros de arranque de un sistema de archivos Linux.
124#@param   int_ndisk      nº de orden del disco
125#@param   int_npartition nº de orden de la partición
126#@return  str_kernel str_initrd str_parameters ...
127#@exception OG_ERR_FORMAT    Formato incorrecto.
128#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
129#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
130#@warning Función básica usada por \c ogBoot
131#@version 0.9 - Primera adaptación para OpenGNSys.
132#@author  Ramon Gomez, ETSII Universidad de Sevilla
133#@date    2009-09-11
134#@version 0.9.2 - Soporta partición /boot independiente.
135#@author  Ramon Gomez, ETSII Universidad de Sevilla
136#@date    2010-07-20
137#*/ ##
138function ogLinuxBootParameters ()
139{
140# Variables locales.
141local MNTDIR CONFDIR CONFFILE
142
143# Si se solicita, mostrar ayuda.
144if [ "$*" == "help" ]; then
145    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
146           "$FUNCNAME 1 2  ==>  ..."
147    return
148fi
149# Error si no se reciben 2 parámetros.
150[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
151
152# Detectar id. de tipo de partición y codificar al mnemonico.
153MNTDIR=$(ogMount $1 $2) 2>/dev/null
154[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
155
156# Fichero de configuración de GRUB.
157CONFDIR=$MNTDIR                               # Partición de arranque /boot.
158[ -d $MNTDIR/boot ] && CONFDIR=$MNTDIR/boot   # Partición raíz con directorio boot.
159CONFFILE="$CONFDIR/grub/menu.lst"
160[ ! -e $CONFFILE ] && CONFFILE="$CONFDIR/grub/grub.cfg"
161[ ! -e $CONFFILE ] && ogRaiseError $OG_ERR_NOTFOUND "grub.cfg" && return $?
162
163# Toma del fichero de configuracion los valores del kernel, initrd
164#       y parámetros de arranque usando las cláusulas por defecto
165#       ("default" en GRUB1, "set default" en GRUB2)
166#       y los formatea para que sean compatibles con \c kexec .  */
167# /* (comentario Doxygen)
168awk 'BEGIN {cont=-1;}
169     $1~/^default/      {sub(/=/," "); def=$2;}
170     $1~/^set/ && $2~/^default/ {gsub(/[="]/," "); def=$3;}
171     $1~/^title|^menuentry/ {cont++}
172     $1~/^kernel|^linux/ {if (def==cont) {
173                            kern=$2;
174                            sub($1,"");sub($1,"");sub(/^[ \t]*/,"");app=$0}  # /* (comentario Doxygen)
175                        }
176     $1~/^initrd/       {if (def==cont) init=$2}
177     END {if (kern!="") printf("%s %s %s", kern,init,app)}
178    ' $CONFFILE
179# */ (comentario Doxygen)
180}
181
182
183#/**
184#         ogSetWindowsName int_ndisk int_npartition str_name
185#@brief   Establece el nombre del equipo en el registro de Windows.
186#@param   int_ndisk      nº de orden del disco
187#@param   int_npartition nº de orden de la partición
188#@param   str_name       nombre asignado
189#@return  (nada)
190#@exception OG_ERR_FORMAT    Formato incorrecto.
191#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
192#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
193#@version 0.9 - Adaptación a OpenGNSys.
194#@author  Ramon Gomez, ETSII Universidad de Sevilla
195#@date    2009-09-24
196#*/ ##
197function ogSetWindowsName ()
198{
199# Variables locales.
200local PART MNTDIR NAME
201
202# Si se solicita, mostrar ayuda.
203if [ "$*" == "help" ]; then
204    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_name" \
205           "$FUNCNAME 1 1 PRACTICA-PC"
206    return
207fi
208# Error si no se reciben 3 parámetros.
209[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
210
211# Montar el sistema de archivos.
212MNTDIR=$(ogMount $1 $2) 2>/dev/null
213[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
214NAME="$3"
215
216# Modificar datos de los valores de registro.
217ogSetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' "$NAME" 2>/dev/null
218ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null
219ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null
220ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null
221ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null
222}
223
224
225#/**
226#         ogSetWinlogonUser int_ndisk int_npartition str_username
227#@brief   Establece el nombre de usuario por defecto en la entrada de Windows.
228#@param   int_ndisk      nº de orden del disco
229#@param   int_npartition nº de orden de la partición
230#@param   str_username   nombre de usuario por defecto
231#@return  (nada)
232#@exception OG_ERR_FORMAT    Formato incorrecto.
233#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
234#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
235#@version 0.9.2 - Adaptación a OpenGNSys.
236#@author  Ramon Gomez, ETSII Universidad de Sevilla
237#@date    2010-07-20
238#*/ ##
239function ogSetWinlogonUser ()
240{
241# Variables locales.
242local PART MNTDIR NAME
243
244# Si se solicita, mostrar ayuda.
245if [ "$*" == "help" ]; then
246    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_username" \
247           "$FUNCNAME 1 1 USUARIO"
248    return
249fi
250# Error si no se reciben 3 parámetros.
251[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
252
253# Montar el sistema de archivos.
254MNTDIR=$(ogMount $1 $2) 2>/dev/null
255[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
256NAME="$3"
257
258# Modificar datos en el registro.
259ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName' "$3"
260}
261
262
263#/**
264#         ogNewMbrXP int_ndisk
265#@brief   Genera un nuevo Master Boot Record en el disco duro indicado, compatible con los SO tipo Windows
266#@param   int_ndisk      nº de orden del disco
267#@return  salida del programa my-sys
268#@exception OG_ERR_FORMAT    Formato incorrecto.
269#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
270#@version 0.9 - Adaptación a OpenGNSys.
271#@author  Antonio J. Doblas Viso. Universidad de Málaga
272#@date    2009-09-24
273#*/ ##
274
275function ogNewMbrXP ()
276{
277# Variables locales.
278local PART
279
280# Si se solicita, mostrar ayuda.
281if [ "$*" == "help" ]; then
282    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \
283           "$FUNCNAME 1 "
284    return
285fi
286# Error si no se reciben 1 parámetros.
287[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
288
289PART="$(ogDiskToDev $1)" || return $?
290ms-sys -z -f $PART
291ms-sys -m -f $PART
292}
293
294
295#/**
296#         ogFixBootSector int_ndisk int_parition
297#@brief   Corrige el boot sector de una particion activa para MS windows/dos -fat-ntfs
298#@param   int_ndisk      nº de orden del disco
299#@param   int_partition     nº de particion
300#@return 
301#@exception OG_ERR_FORMAT    Formato incorrecto.
302#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
303#@version 0.9 - Adaptación a OpenGNSys.
304#@author  Antonio J. Doblas Viso. Universidad de Málaga
305#@date    2009-09-24
306#*/ ##
307
308function ogFixBootSector ()
309{
310# Variables locales.
311local PART DISK FILE
312
313# Si se solicita, mostrar ayuda.
314if [ "$*" == "help" ]; then
315    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
316           "$FUNCNAME 1 1 "
317    return
318fi
319
320# Error si no se reciben 2 parámetros.
321[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
322
323#TODO, solo si la particion existe
324#TODO, solo si es ntfs o fat
325PARTYPE=$(ogGetPartitionId $1 $2)
326case $PARTYPE in
327        1|4|6|7|b|c|e|f)
328        ;;
329        *)
330        return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
331        ;;
332esac
333
334ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
335
336#Preparando instruccion
337let DISK=$1-1   
338PART=$2
339FILE=/tmp/temporal
340cat > $FILE <<EOF
341disk=$DISK
342main_part=$PART
343fix_first_sector=yes
344EOF
345
346spartlnx.run -cui -nm -a -f $FILE
347
348}
349
350
351
352#/**
353#         ogWindowsBootParameters int_ndisk int_parition
354#@brief   Configura el gestor de arranque de windows 7 / vista
355#@param   int_ndisk      nº de orden del disco
356#@param   int_partition     nº de particion
357#@return 
358#@exception OG_ERR_FORMAT    Formato incorrecto.
359#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
360#@version 0.9 - Adaptación a OpenGNSys.
361#@author  Antonio J. Doblas Viso. Universidad de Málaga
362#@date    2009-09-24
363#*/ ##
364
365
366function ogWindowsBootParameters ()
367{
368# Variables locales.
369local PART DISK FILE
370
371# Si se solicita, mostrar ayuda.
372if [ "$*" == "help" ]; then
373    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
374           "$FUNCNAME 1 1 "
375    return
376fi
377
378# Error si no se reciben 2 parámetros.
379[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
380
381ogDiskToDev $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
382
383VERSION=$(ogGetOsVersion $1 $2)
384
385if echo $VERSION | grep "Windows 7"
386then
387        WINVER="Windows 7"
388elif echo $VERSION | grep "Windows Seven"
389then
390        WINVER="Windows Vista"
391else
392        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
393fi
394
395ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
396#Preparando instruccion
397let DISK=$1-1
398PART=$2
399FILE=/tmp/temporal
400
401#Preparando instruccion Windows Resume Application
402cat > $FILE <<EOF
403boot_disk=$DISK
404boot_main_part=$PART
405disk=$DISK
406main_part=$PART
407boot_entry=Windows Resume Application
408EOF
409spartlnx.run -cui -nm -w -f $FILE
410
411#Preparando instruccion tipo windows
412cat > $FILE <<EOF
413boot_disk=$DISK
414boot_main_part=$PART
415disk=$DISK
416main_part=$PART
417boot_entry=$WINVER
418EOF
419spartlnx.run -cui -nm -w -f $FILE
420
421#Preparando instruccion Ramdisk Options
422cat > $FILE <<EOF
423boot_disk=$DISK
424boot_main_part=$PART
425disk=$DISK
426main_part=$PART
427boot_entry=Ramdisk Options
428EOF
429spartlnx.run -cui -nm -w -f $FILE
430
431#Preparando instruccion Windows Boot Manager
432cat > $FILE <<EOF
433boot_disk=$DISK
434boot_main_part=$PART
435disk=$DISK
436main_part=$PART
437boot_entry=Windows Boot Manager
438EOF
439spartlnx.run -cui -nm -w -f $FILE
440
441#Preparando instruccion Herramienta de diagnóstico de memoria de Windows
442#cat > $FILE <<EOF
443#boot_disk=$DISK
444#boot_main_part=$PART
445#disk=$DISK
446#main_part=$PART
447#boot_entry=Herramienta de diagnóstico de memoria de Windows
448#EOF
449#spartlnx.run -cui -nm -w -f $FILE
450
451}
452       
453
454#         ogWinRegistrePartition int_ndisk int_partiton str_volume int_disk int_partition
455#@brief   Registra una partición en windows con un determinado volumen.
456#@param   int_ndisk      nº de orden del disco a registrar
457#@param   int_partition     nº de particion a registrar
458#@param   str_volumen      volumen a resgistar
459#@param   int_ndisk_windows      nº de orden del disco donde esta windows
460#@param   int_partition_windows     nº de particion donde esta windows
461#@return 
462#@exception OG_ERR_FORMAT    Formato incorrecto.
463#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
464#@version 0.9 - Adaptación a OpenGNSys.
465#@author  Antonio J. Doblas Viso. Universidad de Málaga
466#@date    2009-09-24
467#*/ ##
468
469
470function ogWinRegistrePartition ()
471{       
472# Variables locales.
473local PART DISK FILE
474
475# Si se solicita, mostrar ayuda.
476if [ "$*" == "help" ]; then
477    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk_TO_registre int_partition_TO_registre str_NewVolume int_disk int_parition " \
478           "$FUNCNAME 1 1 c: 1 1"
479    return
480fi
481
482# Error si no se reciben 5 parámetros.
483[ $# == 5 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
484
485REGISTREDDISK=$1
486REGISTREDPART=$2
487REGISTREDVOL=$(echo $3 | cut -c1 | tr '[:lower:]' '[:upper:]')
488DISK=$4
489PART=$5
490FILE=/tmp/temporal
491
492ogDiskToDev $REGISTREDDISK $REGISTREDPART || return $(ogRaiseError $OG_ERR_PARTITION "particion a registrar "; echo $?)
493ogDiskToDev $DISK $PART || return $(ogRaiseError $OG_ERR_PARTITION "particion de windows"; echo $?)
494
495ogGetOsType $DISK $PART | grep "Windows" || return $(ogRaiseError $OG_ERR_NOTOS "no es windows"; echo $?)
496
497VERSION=$(ogGetOsVersion $DISK $PART)
498
499#Systemroot
500
501if ogGetPath $DISK $PART WINDOWS
502then
503        SYSTEMROOT="Windows"
504elif ogGetPath $DISK $PART WINNT
505then
506        SYSTEMROOT="winnt"
507else
508        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
509fi
510
511ogUnmount $DISK $PART
512let DISK=$DISK-1
513let REGISTREDDISK=$REGISTREDDISK-1
514#Preparando instruccion Windows Boot Manager
515cat > $FILE <<EOF
516windows_disk=$DISK
517windows_main_part=$PART
518windows_dir=$SYSTEMROOT
519disk=$REGISTREDDISK
520main_part=$REGISTREDPART
521;ext_part
522part_letter=$REGISTREDVOL
523EOF
524spartlnx.run -cui -nm -u -f $FILE
525}
Note: See TracBrowser for help on using the repository browser.