source: client/engine/Boot.lib @ 3ed5a46

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 3ed5a46 was 256dee7, checked in by ramon <ramongomez@…>, 13 years ago

#501: Activar arranque de cliente para sistemas Windows.

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

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