source: client/engine/Boot.lib @ ad1f809

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 ad1f809 was 250742d, checked in by adv <adv@…>, 14 years ago

version 1.0.1 #405 ogWindowsBootParameters para evitar problemas de acceso al registro, no modifica las opciones de ramdisk ni el diagnostico de memoria. No son necearios para iniciar un windows restaurado en una particion distinta a la original.

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

  • Property mode set to 100755
File size: 22.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 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.
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|HNTFS|FAT32|HFAT32)
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        #FIXME: activar seguimiento inicio sesion XP con grub4dos
72                #if `ogGetOsVersion $1 $2 | grep "XP" > /dev/null`
73        #then
74        #       dd if=/dev/zero of=${MNTDIR}/ogboot.me  bs=1024 count=3
75        #       dd if=/dev/zero of=${MNTDIR}/ogboot.firstboot  bs=1024 count=3
76        #       dd if=/dev/zero of=${MNTDIR}/ogboot.secondboot  bs=1024 count=3         
77        #       ogLoadHiveWindows $1 $2
78                #       ogHiveNTRunMachine "cmd /c del c:\ogboot.* "  ogcleanboot
79                #       ogUpdateHiveWindows
80                #       reboot
81        #else       
82                cp $OGLIB/grub4dos/* $MNTDIR    # */ (Comentario Doxygen)
83                ##kexec -l $MNTDIR/grub.exe --append=--config-file="find --set-root /$LOADER; chainloader /$LOADER; tpm --init"
84                kexec -l $MNTDIR/grub.exe --append=--config-file="root (hd$[$1-1],$[$2-1]); chainloader (hd$[$1-1],$[$2-1])/$LOADER; tpm --init"
85                #fi
86        ;;
87    *)  ogRaiseError $OG_ERR_PARTITION "$1, $2"
88        return $?
89        ;;
90esac
91
92# Arrancar.
93kexec -e
94}
95
96
97#/**
98#         ogGetRegistryValue path_mountpoint str_registrytype str_valuename
99#@brief   Devuelve el dato de un valor del registro de Windows.
100#@param   path_mountpoint  directorio donde está montado el sistema Windows
101#@param   str_registrytype tipo de registro a leer
102#@param   str_valuename    valor de registro
103#@return  str_valuedata - valor de la clave.
104#@exception OG_ERR_FORMAT    Formato incorrecto.
105#@exception OG_ERR_NOTFOUND  Disco o partición no corresponden con un dispositivo.
106#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
107#@note    registrytype = { default, sam, security, software, system, components }
108#@warning Requisitos: chntpw, awk
109#@warning La partición de Windows debe estar montada previamente.
110#@version 0.9 - Adaptación para OpenGNSys.
111#@author  Ramon Gomez, ETSII Universidad de Sevilla
112#@date    2009-09-11
113#*/ ##
114function ogGetRegistryValue ()
115{
116# Variables locales.
117local FILE FILENT FILEXP
118
119# Si se solicita, mostrar ayuda.
120if [ "$*" == "help" ]; then
121    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key"
122    return
123fi
124# Error si no se reciben 3 parámetros.
125[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
126
127# Camino del fichero de registro en NT/2000 o XP/Vista/7.
128FILENT=$(ogGetPath "/$1/winnt/system32/config/$2")
129[ -f $FILENT ] && FILE="$FILENT"
130FILEXP=$(ogGetPath "/$1/windows/system32/config/$2")
131[ -f $FLEHXP ] && FILE="$FILEXP"
132[ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $?
133
134# Devolver el dato del valor de registro.
135# /* (comentario Doxygen)
136chntpw $FILE << FIN 2>/dev/null | awk '/> Value/ {getline;print $0;}'
137cd ${3%\\*}
138cat ${3##*\\}
139q
140FIN
141# (comentario Doxygen) */
142}
143
144
145#/**
146#         ogGetWindowsName int_ndisk int_npartition
147#@brief   Muestra el nombre del equipo en el registro de Windows.
148#@param   int_ndisk      nº de orden del disco
149#@param   int_npartition nº de orden de la partición
150#@return  str_name - nombre del equipo
151#@exception OG_ERR_FORMAT    Formato incorrecto.
152#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
153#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
154#@version 0.9 - Adaptación para OpenGNSys.
155#@author  Ramon Gomez, ETSII Universidad de Sevilla
156#@date    2009-09-23
157#*/ ##
158function ogGetWindowsName ()
159{
160# Variables locales.
161local PART MNTDIR
162
163# Si se solicita, mostrar ayuda.
164if [ "$*" == "help" ]; then
165    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
166           "$FUNCNAME 1 1  ==>  PRACTICA-PC"
167    return
168fi
169# Error si no se reciben 2 parámetros.
170[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
171
172# Montar el sistema de archivos.
173MNTDIR=$(ogMount $1 $2) 2>/dev/null
174[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
175
176# Obtener dato del valor de registro.
177ogGetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName'
178}
179
180
181#/**
182#         ogListRegistryKeys path_mountpoint str_registrytype str_key
183#@brief   Lista los nombres de claves de una determinada clave del registro de Windows.
184#@param   path_mountpoint  directorio donde está montado el sistema Windows
185#@param   str_registrytype tipo de registro a leer
186#@param   str_key          clave de registro
187#@return  str_key ... - lista de claves de registro
188#@exception OG_ERR_FORMAT    Formato incorrecto.
189#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
190#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
191#@note    registrytype = { default, sam, security, software, system, components }
192#@warning Requisitos: chntpw, awk
193#@warning La partición de Windows debe estar montada previamente.
194#@version 0.9 - Adaptación para OpenGNSys.
195#@author  Ramon Gomez, ETSII Universidad de Sevilla
196#@date    2009-09-23
197#*/ ##
198function ogListRegistryKeys ()
199{
200# Variables locales.
201local FILE FILENT FILEXP
202
203# Si se solicita, mostrar ayuda.
204if [ "$*" == "help" ]; then
205    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key"
206    return
207fi
208# Error si no se reciben 3 parámetros.
209[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
210
211# Camino del fichero de registro en NT/2000 o XP/Vista/7.
212FILENT=$(ogGetPath "/$1/winnt/system32/config/$2")
213[ -f $FILENT ] && FILE="$FILENT"
214FILEXP=$(ogGetPath "/$1/windows/system32/config/$2")
215[ -f $FLEHXP ] && FILE="$FILEXP"
216[ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $?
217
218# Devolver la lista de claves de registro.
219chntpw $FILE << FIN 2>/dev/null | awk 'BEGIN {FS="[<>]"} $1~/^  $/ {print $2}'
220ls $3
221q
222FIN
223}
224
225
226#/**
227#         ogLinuxBootParameters int_ndisk int_npartition
228#@brief   Muestra los parámetros de arranque de un sistema de archivos Linux.
229#@param   int_ndisk      nº de orden del disco
230#@param   int_npartition nº de orden de la partición
231#@return  str_kernel str_initrd str_parameters ...
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#@warning Función básica usada por \c ogBoot
236#@version 0.9 - Primera adaptación para OpenGNSys.
237#@author  Ramon Gomez, ETSII Universidad de Sevilla
238#@date    2009-09-11
239#@version 0.9.2 - Soporta partición /boot independiente.
240#@author  Ramon Gomez, ETSII Universidad de Sevilla
241#@date    2010-07-20
242#*/ ##
243function ogLinuxBootParameters ()
244{
245# Variables locales.
246local MNTDIR CONFDIR CONFFILE
247
248# Si se solicita, mostrar ayuda.
249if [ "$*" == "help" ]; then
250    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
251           "$FUNCNAME 1 2  ==>  ..."
252    return
253fi
254# Error si no se reciben 2 parámetros.
255[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
256
257# Detectar id. de tipo de partición y codificar al mnemonico.
258MNTDIR=$(ogMount $1 $2) 2>/dev/null
259[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
260
261# Fichero de configuración de GRUB.
262CONFDIR=$MNTDIR                               # Partición de arranque /boot.
263[ -d $MNTDIR/boot ] && CONFDIR=$MNTDIR/boot   # Partición raíz con directorio boot.
264CONFFILE="$CONFDIR/grub/menu.lst"
265[ ! -e $CONFFILE ] && CONFFILE="$CONFDIR/grub/grub.cfg"
266[ ! -e $CONFFILE ] && ogRaiseError $OG_ERR_NOTFOUND "grub.cfg" && return $?
267
268# Toma del fichero de configuracion los valores del kernel, initrd
269#       y parámetros de arranque usando las cláusulas por defecto
270#       ("default" en GRUB1, "set default" en GRUB2)
271#       y los formatea para que sean compatibles con \c kexec .  */
272# /* (comentario Doxygen)
273awk 'BEGIN {cont=-1;}
274     $1~/^default/      {sub(/=/," "); def=$2;}
275     $1~/^set/ && $2~/^default/ {gsub(/[="]/," "); def=$3;}
276     $1~/^title|^menuentry/ {cont++}
277     $1~/^kernel|^linux/ {if (def==cont) {
278                            kern=$2;
279                            sub($1,"");sub($1,"");sub(/^[ \t]*/,"");app=$0}  # /* (comentario Doxygen)
280                        }
281     $1~/^initrd/       {if (def==cont) init=$2}
282     END {if (kern!="") printf("%s %s %s", kern,init,app)}
283    ' $CONFFILE
284# */ (comentario Doxygen)
285}
286
287
288
289#/**
290#         ogSetRegistryValue path_mountpoint str_registrytype str_valuename str_valuedata
291#@brief   Establece el dato asociado a un valor del registro de Windows.
292#@param   path_mountpoint  directorio donde está montado el sistema Windows
293#@param   str_registrytype tipo de registro
294#@param   str_valuename    nombre del valor de registro
295#@param   str_valuedata    dato del valor de registro
296#@return  (nada)
297#@exception OG_ERR_FORMAT    Formato incorrecto.
298#@exception OG_ERR_NOTFOUND  Disco o partición no corresponden con un dispositivo.
299#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
300#@note    registrytype = { default, sam, security, software, system, components }
301#@warning Requisitos: chntpw, awk
302#@warning La partición de Windows debe estar montada previamente.
303#@version 0.9 - Adaptación para OpenGNSys.
304#@author  Ramon Gomez, ETSII Universidad de Sevilla
305#@date    2009-09-24
306#*/ ##
307function ogSetRegistryValue ()
308{
309# Variables locales.
310local FILE FILENT FILEXP
311
312# Si se solicita, mostrar ayuda.
313if [ "$*" == "help" ]; then
314    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key"
315    return
316fi
317# Error si no se reciben 4 parámetros.
318[ $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $?
319
320# Camino del fichero de registro en NT/2000 o XP/Vista/7.
321FILENT=$(ogGetPath "/$1/winnt/system32/config/$2")
322[ -f $FILENT ] && FILE="$FILENT"
323FILEXP=$(ogGetPath "/$1/windows/system32/config/$2")
324[ -f $FLEHXP ] && FILE="$FILEXP"
325[ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $?
326
327# Cambiar el dato del valor de registro.
328chntpw $FILE << FIN &>/dev/null
329ed $3
330$4
331q
332y
333FIN
334}
335
336
337#/**
338#         ogSetWindowsName int_ndisk int_npartition str_name
339#@brief   Establece el nombre del equipo en el registro de Windows.
340#@param   int_ndisk      nº de orden del disco
341#@param   int_npartition nº de orden de la partición
342#@param   str_name       nombre asignado
343#@return  (nada)
344#@exception OG_ERR_FORMAT    Formato incorrecto.
345#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
346#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
347#@version 0.9 - Adaptación a OpenGNSys.
348#@author  Ramon Gomez, ETSII Universidad de Sevilla
349#@date    2009-09-24
350#*/ ##
351function ogSetWindowsName ()
352{
353# Variables locales.
354local PART MNTDIR NAME
355
356# Si se solicita, mostrar ayuda.
357if [ "$*" == "help" ]; then
358    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_name" \
359           "$FUNCNAME 1 1 PRACTICA-PC"
360    return
361fi
362# Error si no se reciben 3 parámetros.
363[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
364
365# Montar el sistema de archivos.
366MNTDIR=$(ogMount $1 $2) 2>/dev/null
367[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
368NAME="$3"
369
370# Modificar datos de los valores de registro.
371ogSetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' "$NAME" 2>/dev/null
372ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null
373ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null
374ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null
375ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null
376}
377
378
379#/**
380#         ogSetWinlogonUser int_ndisk int_npartition str_username
381#@brief   Establece el nombre de usuario por defecto en la entrada de Windows.
382#@param   int_ndisk      nº de orden del disco
383#@param   int_npartition nº de orden de la partición
384#@param   str_username   nombre de usuario por defecto
385#@return  (nada)
386#@exception OG_ERR_FORMAT    Formato incorrecto.
387#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
388#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
389#@version 0.9.2 - Adaptación a OpenGNSys.
390#@author  Ramon Gomez, ETSII Universidad de Sevilla
391#@date    2010-07-20
392#*/ ##
393function ogSetWinlogonUser ()
394{
395# Variables locales.
396local PART MNTDIR NAME
397
398# Si se solicita, mostrar ayuda.
399if [ "$*" == "help" ]; then
400    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_username" \
401           "$FUNCNAME 1 1 USUARIO"
402    return
403fi
404# Error si no se reciben 3 parámetros.
405[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
406
407# Montar el sistema de archivos.
408MNTDIR=$(ogMount $1 $2) 2>/dev/null
409[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
410NAME="$3"
411
412# Modificar datos en el registro.
413ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName' "$3"
414}
415
416
417#/**
418#         ogNewMbrXP int_ndisk
419#@brief   Genera un nuevo Master Boot Record en el disco duro indicado, compatible con los SO tipo Windows
420#@param   int_ndisk      nº de orden del disco
421#@return  salida del programa my-sys
422#@exception OG_ERR_FORMAT    Formato incorrecto.
423#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
424#@version 0.9 - Adaptación a OpenGNSys.
425#@author  Antonio J. Doblas Viso. Universidad de Málaga
426#@date    2009-09-24
427#*/ ##
428
429function ogNewMbrXP ()
430{
431# Variables locales.
432local PART
433
434# Si se solicita, mostrar ayuda.
435if [ "$*" == "help" ]; then
436    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \
437           "$FUNCNAME 1 "
438    return
439fi
440# Error si no se reciben 1 parámetros.
441[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
442
443PART="$(ogDiskToDev $1)" || return $?
444ms-sys -z -f $PART
445ms-sys -m -f $PART
446}
447
448
449
450#/**
451#         ogFixBootSector int_ndisk int_parition
452#@brief   Corrige el boot sector de una particion activa para MS windows/dos -fat-ntfs
453#@param   int_ndisk      nº de orden del disco
454#@param   int_partition     nº de particion
455#@return 
456#@exception OG_ERR_FORMAT    Formato incorrecto.
457#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
458#@version 0.9 - Adaptación a OpenGNSys.
459#@author  Antonio J. Doblas Viso. Universidad de Málaga
460#@date    2009-09-24
461#*/ ##
462
463function ogFixBootSector ()
464{
465# Variables locales.
466local PART DISK FILE
467
468# Si se solicita, mostrar ayuda.
469if [ "$*" == "help" ]; then
470    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
471           "$FUNCNAME 1 1 "
472    return
473fi
474
475# Error si no se reciben 2 parámetros.
476[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
477
478#TODO, solo si la particion existe
479#TODO, solo si es ntfs o fat
480PARTYPE=$(ogGetPartitionId $1 $2)
481case $PARTYPE in
482        1|4|6|7|b|c|e|f)
483        ;;
484        *)
485        return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
486        ;;
487esac
488
489ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
490
491#Preparando instruccion
492let DISK=$1-1   
493PART=$2
494FILE=/tmp/temporal
495cat > $FILE <<EOF
496disk=$DISK
497main_part=$PART
498fix_first_sector=yes
499EOF
500
501spartlnx.run -cui -nm -a -f $FILE
502
503}
504
505
506
507#/**
508#         ogWindowsBootParameters int_ndisk int_parition
509#@brief   Configura el gestor de arranque de windows 7 / vista / XP / 2000
510#@param   int_ndisk      nº de orden del disco
511#@param   int_partition     nº de particion
512#@return 
513#@exception OG_ERR_FORMAT    Formato incorrecto.
514#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
515#@version 0.9 - Integración desde EAC para OpenGNSys.
516#@author  Antonio J. Doblas Viso. Universidad de Málaga
517#@date    2009-09-24
518#@version 1.0.1 - Adapatacion para OpenGnsys.
519#@author  Antonio J. Doblas Viso. Universidad de Málaga
520#@date    2011-05-20
521#*/ ##
522
523
524function ogWindowsBootParameters ()
525{
526# Variables locales.
527local PART DISK FILE
528#Preparando variables adaptadas a sintaxis windows.
529let DISK=$1-1
530PART=$2
531FILE=/tmp/temporal
532
533# Si se solicita, mostrar ayuda.
534if [ "$*" == "help" ]; then
535    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
536           "$FUNCNAME 1 1 "
537    return
538fi
539
540# Error si no se reciben 2 parámetros.
541[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
542
543ogDiskToDev $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
544
545VERSION=$(ogGetOsVersion $1 $2)
546
547if echo "$VERSION" | grep "Windows 7"
548then
549        WINVER="Windows 7"
550elif echo "$VERSION" | grep "Windows Seven"
551then
552        WINVER="Windows Vista"
553elif echo "$VERSION" | grep "XP"
554then
555        MOUNT=$(ogMount $1 $2)
556        [ -f ${MOUNT}/boot.ini ] || return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
557        cat ${MOUNT}/boot.ini | sed s/partition\([0-9]\)/partition\($PART\)/g | sed s/rdisk\([0-9]\)/rdisk\($DISK\)/g > ${MOUNT}/tmp.boot.ini; mv ${MOUNT}/tmp.boot.ini ${MOUNT}/boot.ini
558        return 0
559else
560        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
561fi
562
563ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
564
565
566#Preparando instruccion Windows Resume Application
567cat > $FILE <<EOF
568boot_disk=$DISK
569boot_main_part=$PART
570disk=$DISK
571main_part=$PART
572boot_entry=Windows Resume Application
573EOF
574spartlnx.run -cui -nm -w -f $FILE
575
576#Preparando instruccion tipo windows
577cat > $FILE <<EOF
578boot_disk=$DISK
579boot_main_part=$PART
580disk=$DISK
581main_part=$PART
582boot_entry=$WINVER
583EOF
584spartlnx.run -cui -nm -w -f $FILE
585
586##Preparando instruccion        Ramdisk Options
587#cat > $FILE <<EOF
588#boot_disk=$DISK
589#boot_main_part=$PART
590#disk=$DISK
591#main_part=$PART
592#boot_entry=Ramdisk Options
593#EOF
594#spartlnx.run -cui -nm -w -f $FILE
595
596#Preparando instruccion Windows Boot Manager
597cat > $FILE <<EOF
598boot_disk=$DISK
599boot_main_part=$PART
600disk=$DISK
601main_part=$PART
602boot_entry=Windows Boot Manager
603EOF
604spartlnx.run -cui -nm -w -f $FILE
605
606#Preparando instruccion Herramienta de diagnóstico de memoria de Windows
607#cat > $FILE <<EOF
608#boot_disk=$DISK
609#boot_main_part=$PART
610#disk=$DISK
611#main_part=$PART
612#boot_entry=Herramienta de diagnóstico de memoria de Windows
613#EOF
614#spartlnx.run -cui -nm -w -f $FILE
615
616}
617       
618
619#         ogWindowsRegisterPartition int_ndisk int_partiton str_volume int_disk int_partition
620#@brief   Registra una partición en windows con un determinado volumen.
621#@param   int_ndisk      nº de orden del disco a registrar
622#@param   int_partition     nº de particion a registrar
623#@param   str_volumen      volumen a resgistar
624#@param   int_ndisk_windows      nº de orden del disco donde esta windows
625#@param   int_partition_windows     nº de particion donde esta windows
626#@return 
627#@exception OG_ERR_FORMAT    Formato incorrecto.
628#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
629#@version 0.9 - Adaptación a OpenGNSys.
630#@author  Antonio J. Doblas Viso. Universidad de Málaga
631#@date    2009-09-24
632#*/ ##
633
634
635function ogWindowsRegisterPartition ()
636{       
637# Variables locales.
638local PART DISK FILE
639
640# Si se solicita, mostrar ayuda.
641if [ "$*" == "help" ]; then
642    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk_TO_registre int_partition_TO_registre str_NewVolume int_disk int_parition " \
643           "$FUNCNAME 1 1 c: 1 1"
644    return
645fi
646
647# Error si no se reciben 5 parámetros.
648[ $# == 5 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
649
650REGISTREDDISK=$1
651REGISTREDPART=$2
652REGISTREDVOL=$(echo $3 | cut -c1 | tr '[:lower:]' '[:upper:]')
653DISK=$4
654PART=$5
655FILE=/tmp/temporal
656
657ogDiskToDev $REGISTREDDISK $REGISTREDPART || return $(ogRaiseError $OG_ERR_PARTITION "particion a registrar "; echo $?)
658ogDiskToDev $DISK $PART || return $(ogRaiseError $OG_ERR_PARTITION "particion de windows"; echo $?)
659
660ogGetOsType $DISK $PART | grep "Windows" || return $(ogRaiseError $OG_ERR_NOTOS "no es windows"; echo $?)
661
662VERSION=$(ogGetOsVersion $DISK $PART)
663
664#Systemroot
665
666if ogGetPath $DISK $PART WINDOWS
667then
668        SYSTEMROOT="Windows"
669elif ogGetPath $DISK $PART WINNT
670then
671        SYSTEMROOT="winnt"
672else
673        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
674fi
675
676ogUnmount $DISK $PART
677let DISK=$DISK-1
678let REGISTREDDISK=$REGISTREDDISK-1
679#Preparando instruccion Windows Boot Manager
680cat > $FILE <<EOF
681windows_disk=$DISK
682windows_main_part=$PART
683windows_dir=$SYSTEMROOT
684disk=$REGISTREDDISK
685main_part=$REGISTREDPART
686;ext_part
687part_letter=$REGISTREDVOL
688EOF
689spartlnx.run -cui -nm -u -f $FILE
690}
Note: See TracBrowser for help on using the repository browser.