source: client/engine/Boot.lib @ 5bb4407

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 5bb4407 was 0b9c763, checked in by adv <adv@…>, 13 years ago

version 1.0.3 #466 ogBoot termina el proceso browser (framebuffer) antes de iniciar el sistema operativo.

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

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