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

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 3c2933e was 40ad2e8d, checked in by ramon <ramongomez@…>, 13 years ago

Versión 1.0.4, #525: Incluir modificaciones de la BD y cambios en función ogBoot.

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

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