source: client/engine/Boot.lib @ e79df1d

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 e79df1d was 4085f13, checked in by irina <irinagomez@…>, 12 years ago

#593 Optimiza inicio de sesión en winodws, se eliminan funciones obsoletas o repetidas

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

  • Property mode set to 100755
File size: 32.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 1.0.5
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        if [ "$winboot" == "kexec" ]; then
74            # Modo de arranque en caliente (con kexec).
75            cp $OGLIB/grub4dos/* $MNTDIR    # */ (Comentario Doxygen)
76            kexec -l $MNTDIR/grub.exe --append=--config-file="root (hd$[$1-1],$[$2-1]); chainloader (hd$[$1-1],$[$2-1])/$LOADER; tpm --init"
77            kexec -e &
78        else
79            # Modo de arranque por reinicio (con reboot).
80            dd if=/dev/zero of=${MNTDIR}/ogboot.me bs=1024 count=3
81            dd if=/dev/zero of=${MNTDIR}/ogboot.firstboot bs=1024 count=3
82            dd if=/dev/zero of=${MNTDIR}/ogboot.secondboot bs=1024 count=3
83            if  [ -z "$(ogGetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleannboot')" ]; then               
84            ogAddRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleanboot'
85            ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows\CurrentVersion\Run\ogcleanboot' "cmd /c del c:\ogboot.*"
86            fi
87            # Activar la partición.
88            ogSetPartitionActive $1 $2
89            reboot
90        fi
91        ;;
92    *)  ogRaiseError $OG_ERR_PARTITION "$1, $2"
93        return $?
94        ;;
95esac
96
97# Parar Browser para evitar cuelgues.
98pkill browser
99}
100
101
102#/**
103#         ogGetWindowsName int_ndisk int_npartition
104#@brief   Muestra el nombre del equipo en el registro de Windows.
105#@param   int_ndisk      nº de orden del disco
106#@param   int_npartition nº de orden de la partición
107#@return  str_name - nombre del equipo
108#@exception OG_ERR_FORMAT    Formato incorrecto.
109#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
110#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
111#@version 0.9 - Adaptación para OpenGnSys.
112#@author  Ramon Gomez, ETSII Universidad de Sevilla
113#@date    2009-09-23
114#*/ ##
115function ogGetWindowsName ()
116{
117# Variables locales.
118local PART MNTDIR
119
120# Si se solicita, mostrar ayuda.
121if [ "$*" == "help" ]; then
122    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
123           "$FUNCNAME 1 1  ==>  PRACTICA-PC"
124    return
125fi
126# Error si no se reciben 2 parámetros.
127[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
128
129# Montar el sistema de archivos.
130MNTDIR=$(ogMount $1 $2) 2>/dev/null
131[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
132
133# Obtener dato del valor de registro.
134ogGetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName'
135}
136
137
138#/**
139#         ogLinuxBootParameters int_ndisk int_npartition
140#@brief   Muestra los parámetros de arranque de un sistema de archivos Linux.
141#@param   int_ndisk      nº de orden del disco
142#@param   int_npartition nº de orden de la partición
143#@return  str_kernel str_initrd str_parameters ...
144#@exception OG_ERR_FORMAT    Formato incorrecto.
145#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
146#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
147#@warning Función básica usada por \c ogBoot
148#@version 0.9 - Primera adaptación para OpenGnSys.
149#@author  Ramon Gomez, ETSII Universidad de Sevilla
150#@date    2009-09-11
151#@version 0.9.2 - Soporta partición /boot independiente.
152#@author  Ramon Gomez, ETSII Universidad de Sevilla
153#@date    2010-07-20
154#*/ ##
155function ogLinuxBootParameters ()
156{
157# Variables locales.
158local MNTDIR CONFDIR CONFFILE
159
160# Si se solicita, mostrar ayuda.
161if [ "$*" == "help" ]; then
162    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
163           "$FUNCNAME 1 2  ==>  ..."
164    return
165fi
166# Error si no se reciben 2 parámetros.
167[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
168
169# Detectar id. de tipo de partición y codificar al mnemonico.
170MNTDIR=$(ogMount $1 $2) 2>/dev/null
171[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
172
173# Fichero de configuración de GRUB.
174CONFDIR=$MNTDIR                               # Partición de arranque /boot.
175[ -d $MNTDIR/boot ] && CONFDIR=$MNTDIR/boot   # Partición raíz con directorio boot.
176CONFFILE="$CONFDIR/grubPARTITION/boot/grub/grub.cfg"
177[ ! -e $CONFFILE ] && CONFFILE="$CONFDIR/grub/menu.lst"
178[ ! -e $CONFFILE ] && CONFFILE="$CONFDIR/grub/grub.cfg"
179[ ! -e $CONFFILE ] && ogRaiseError $OG_ERR_NOTFOUND "grub.cfg" && return $?
180
181# Toma del fichero de configuracion los valores del kernel, initrd
182#       y parámetros de arranque usando las cláusulas por defecto
183#       ("default" en GRUB1, "set default" en GRUB2)
184#       y los formatea para que sean compatibles con \c kexec .  */
185# /* (comentario Doxygen)
186awk 'BEGIN {cont=-1;}
187     $1~/^default/      {sub(/=/," "); def=$2;}
188     $1~/^set/ && $2~/^default/ {gsub(/[="]/," "); def=$3;}
189     $1~/^title|^menuentry/ {cont++}
190     $1~/^kernel|^linux/ {if (def==cont) {
191                            kern=$2;
192                            sub($1,"");sub($1,"");sub(/^[ \t]*/,"");app=$0}  # /* (comentario Doxygen)
193                        }
194     $1~/^initrd/       {if (def==cont) init=$2}
195     END {if (kern!="") printf("%s %s %s", kern,init,app)}
196    ' $CONFFILE
197# */ (comentario Doxygen)
198}
199
200
201#/**
202#         ogSetWindowsName int_ndisk int_nfilesys str_name
203#@brief   Establece el nombre del equipo en el registro de Windows.
204#@param   int_ndisk      nº de orden del disco
205#@param   int_nfilesys   nº de orden del sistema de archivos
206#@param   str_name       nombre asignado
207#@return  (nada)
208#@exception OG_ERR_FORMAT     Formato incorrecto.
209#@exception OG_ERR_NOTFOUND   Disco o particion no corresponden con un dispositivo.
210#@exception OG_ERR_PARTITION  Tipo de partición desconocido o no se puede montar.
211#@exception OG_ERR_OUTOFLIMIT Nombre Netbios con más de 15 caracteres.
212#@version 0.9 - Adaptación a OpenGnSys.
213#@author  Ramon Gomez, ETSII Universidad de Sevilla
214#@date    2009-09-24
215#@version 1.0.5 - Establecer restricción de tamaño de nombre Netbios.
216#@author  Ramon Gomez, ETSII Universidad de Sevilla
217#@date    2013-03-20
218#*/ ##
219function ogSetWindowsName ()
220{
221# Variables locales.
222local PART MNTDIR NAME
223
224# Si se solicita, mostrar ayuda.
225if [ "$*" == "help" ]; then
226    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_filesys str_name" \
227           "$FUNCNAME 1 1 PRACTICA-PC"
228    return
229fi
230# Error si no se reciben 3 parámetros.
231[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
232# Error si el nombre supera los 15 caracteres.
233[ ${#3} -le 15 ] || ogRaiseError $OG_ERR_OUTOFLIMIT "\"${3:0:15}...\"" || return $?
234
235# Montar el sistema de archivos.
236MNTDIR=$(ogMount $1 $2) 2>/dev/null
237[ -n "$MNTDIR" ] || ogRaiseError OG_ERR_PARTITION "$1, $2" || return $?
238NAME="$3"
239
240# Modificar datos de los valores de registro.
241ogSetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' "$NAME" 2>/dev/null
242ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null
243ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null
244ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null
245ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null
246}
247
248
249#/**
250#         ogSetWinlogonUser int_ndisk int_npartition str_username
251#@brief   Establece el nombre de usuario por defecto en la entrada de Windows.
252#@param   int_ndisk      nº de orden del disco
253#@param   int_npartition nº de orden de la partición
254#@param   str_username   nombre de usuario por defecto
255#@return  (nada)
256#@exception OG_ERR_FORMAT    Formato incorrecto.
257#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
258#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
259#@version 0.9.2 - Adaptación a OpenGnSys.
260#@author  Ramon Gomez, ETSII Universidad de Sevilla
261#@date    2010-07-20
262#*/ ##
263function ogSetWinlogonUser ()
264{
265# Variables locales.
266local PART MNTDIR NAME
267
268# Si se solicita, mostrar ayuda.
269if [ "$*" == "help" ]; then
270    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_username" \
271           "$FUNCNAME 1 1 USUARIO"
272    return
273fi
274# Error si no se reciben 3 parámetros.
275[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
276
277# Montar el sistema de archivos.
278MNTDIR=$(ogMount $1 $2) 2>/dev/null
279[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
280NAME="$3"
281
282# Modificar datos en el registro.
283ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName' "$3"
284}
285
286
287#/**
288#         ogBootMbrXP int_ndisk
289#@brief   Genera un nuevo Master Boot Record en el disco duro indicado, compatible con los SO tipo Windows
290#@param   int_ndisk      nº de orden del disco
291#@return  salida del programa my-sys
292#@exception OG_ERR_FORMAT    Formato incorrecto.
293#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
294#@version 0.9 - Adaptación a OpenGnSys.
295#@author  Antonio J. Doblas Viso. Universidad de Málaga
296#@date    2009-09-24
297#*/ ##
298
299function ogBootMbrXP ()
300{
301# Variables locales.
302local PART
303
304# Si se solicita, mostrar ayuda.
305if [ "$*" == "help" ]; then
306    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \
307           "$FUNCNAME 1 "
308    return
309fi
310# Error si no se reciben 1 parámetros.
311[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
312
313PART="$(ogDiskToDev $1)" || return $?
314ms-sys -z -f $PART
315ms-sys -m -f $PART
316}
317
318
319#/**
320#         ogBootMbrGeneric int_ndisk
321#@brief   Genera un nuevo Codigo de arranque en el MBR del disco indicado, compatible con los SO tipo Windows, Linux.
322#@param   int_ndisk      nº de orden del disco
323#@return  salida del programa my-sys
324#@exception OG_ERR_FORMAT    Formato incorrecto.
325#@exception OG_ERR_NOTFOUND Tipo de partición desconocido o no se puede montar.
326#@version 0.9 - Adaptación a OpenGnSys.
327#@author  Antonio J. Doblas Viso. Universidad de Málaga
328#@date    2009-09-24
329#*/ ##
330
331function ogBootMbrGeneric ()
332{
333# Variables locales.
334local PART
335
336# Si se solicita, mostrar ayuda.
337if [ "$*" == "help" ]; then
338    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \
339           "$FUNCNAME 1 "
340    return
341fi
342# Error si no se reciben 1 parámetros.
343[ $# == 1 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
344
345PART="$(ogDiskToDev $1)" || return $(ogRaiseError $OG_ERR_NOTFOUND; echo $?)
346ms-sys -z -f $PART
347ms-sys -s -f $PART
348}
349
350
351
352
353#/**
354#         ogFixBootSector int_ndisk int_parition
355#@brief   Corrige el boot sector de una particion activa para MS windows/dos -fat-ntfs
356#@param   int_ndisk      nº de orden del disco
357#@param   int_partition     nº de particion
358#@return 
359#@exception OG_ERR_FORMAT    Formato incorrecto.
360#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
361#@version 0.9 - Adaptación a OpenGnSys.
362#@author  Antonio J. Doblas Viso. Universidad de Málaga
363#@date    2009-09-24
364#*/ ##
365
366function ogFixBootSector ()
367{
368# Variables locales.
369local PARTYPE DISK PART FILE
370
371# Si se solicita, mostrar ayuda.
372if [ "$*" == "help" ]; then
373    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
374           "$FUNCNAME 1 1 "
375    return
376fi
377
378# Error si no se reciben 2 parámetros.
379[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
380
381#TODO, solo si la particion existe
382#TODO, solo si es ntfs o fat
383PARTYPE=$(ogGetPartitionId $1 $2)
384case "$PARTYPE" in
385        1|4|6|7|b|c|e|f)
386        ;;
387        *)
388        return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
389        ;;
390esac
391
392ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
393
394#Preparando instruccion
395let DISK=$1-1   
396PART=$2
397FILE=/tmp/temp$$
398cat > $FILE <<EOF
399disk=$DISK
400main_part=$PART
401fix_first_sector=yes
402EOF
403
404spartlnx.run -cui -nm -a -f $FILE &
405sleep 5
406ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
407rm -f $FILE
408}
409
410
411
412#/**
413#         ogWindowsBootParameters int_ndisk int_parition
414#@brief   Configura el gestor de arranque de windows 7 / vista / XP / 2000
415#@param   int_ndisk      nº de orden del disco
416#@param   int_partition     nº de particion
417#@return 
418#@exception OG_ERR_FORMAT    Formato incorrecto.
419#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
420#@version 0.9 - Integración desde EAC para OpenGnSys.
421#@author  Antonio J. Doblas Viso. Universidad de Málaga
422#@date    2009-09-24
423#@version 1.0.1 - Adapatacion para OpenGnsys.
424#@author  Antonio J. Doblas Viso. Universidad de Málaga
425#@date    2011-05-20
426#*/ ##
427
428
429function ogWindowsBootParameters ()
430{
431# Variables locales.
432local PART DISK FILE VERSION WINVER MOUNT
433#Preparando variables adaptadas a sintaxis windows.
434let DISK=$1-1
435PART=$2
436FILE=/tmp/temp$$
437
438# Si se solicita, mostrar ayuda.
439if [ "$*" == "help" ]; then
440    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \
441           "$FUNCNAME 1 1 "
442    return
443fi
444
445# Error si no se reciben 2 parámetros.
446[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
447
448ogDiskToDev $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
449
450VERSION=$(ogGetOsVersion $1 $2)
451
452if echo "$VERSION" | grep "Windows 7"
453then
454        WINVER="Windows 7"
455elif echo "$VERSION" | grep "Windows Seven"
456then
457        WINVER="Windows Vista"
458elif echo "$VERSION" | grep "XP"
459then
460        MOUNT=$(ogMount $1 $2)
461        [ -f ${MOUNT}/boot.ini ] || return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
462        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
463        return 0
464else
465        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
466fi
467
468ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?)
469
470
471#Preparando instruccion Windows Resume Application
472cat > $FILE <<EOF
473boot_disk=$DISK
474boot_main_part=$PART
475disk=$DISK
476main_part=$PART
477boot_entry=Windows Resume Application
478EOF
479spartlnx.run -cui -nm -w -f $FILE &
480sleep 5
481ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
482
483 
484
485#Preparando instruccion tipo windows
486cat > $FILE <<EOF
487boot_disk=$DISK
488boot_main_part=$PART
489disk=$DISK
490main_part=$PART
491boot_entry=$WINVER
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        Ramdisk Options
499cat > $FILE <<EOF
500boot_disk=$DISK
501boot_main_part=$PART
502disk=$DISK
503main_part=$PART
504boot_entry=Ramdisk Options
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 Windows Boot Manager
512cat > $FILE <<EOF
513boot_disk=$DISK
514boot_main_part=$PART
515disk=$DISK
516main_part=$PART
517boot_entry=Windows Boot Manager
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#Preparando instruccion Herramienta de diagnóstico de memoria de Windows
525cat > $FILE <<EOF
526boot_disk=$DISK
527boot_main_part=$PART
528disk=$DISK
529main_part=$PART
530boot_entry=Herramienta de diagnóstico de memoria de Windows
531EOF
532spartlnx.run -cui -nm -w -f $FILE &
533sleep 5
534ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
535
536}
537
538
539#         ogWindowsRegisterPartition int_ndisk int_partiton str_volume int_disk int_partition
540#@brief   Registra una partición en windows con un determinado volumen.
541#@param   int_ndisk      nº de orden del disco a registrar
542#@param   int_partition     nº de particion a registrar
543#@param   str_volumen      volumen a resgistar
544#@param   int_ndisk_windows      nº de orden del disco donde esta windows
545#@param   int_partition_windows     nº de particion donde esta windows
546#@return 
547#@exception OG_ERR_FORMAT    Formato incorrecto.
548#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
549#@version 0.9 - Adaptación a OpenGnSys.
550#@author  Antonio J. Doblas Viso. Universidad de Málaga
551#@date    2009-09-24
552#*/ ##
553function ogWindowsRegisterPartition ()
554{
555# Variables locales.
556local PART DISK FILE REGISTREDDISK REGISTREDPART REGISTREDVOL VERSION SYSTEMROOT
557
558# Si se solicita, mostrar ayuda.
559if [ "$*" == "help" ]; then
560    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk_TO_registre int_partition_TO_registre str_NewVolume int_disk int_parition " \
561           "$FUNCNAME 1 1 c: 1 1"
562    return
563fi
564
565# Error si no se reciben 5 parámetros.
566[ $# == 5 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
567
568REGISTREDDISK=$1
569REGISTREDPART=$2
570REGISTREDVOL=$(echo $3 | cut -c1 | tr '[:lower:]' '[:upper:]')
571DISK=$4
572PART=$5
573FILE=/tmp/temp$$
574
575ogDiskToDev $REGISTREDDISK $REGISTREDPART || return $(ogRaiseError $OG_ERR_PARTITION "particion a registrar "; echo $?)
576ogDiskToDev $DISK $PART || return $(ogRaiseError $OG_ERR_PARTITION "particion de windows"; echo $?)
577
578ogGetOsType $DISK $PART | grep "Windows" || return $(ogRaiseError $OG_ERR_NOTOS "no es windows"; echo $?)
579
580VERSION=$(ogGetOsVersion $DISK $PART)
581
582#Systemroot
583
584if ogGetPath $DISK $PART WINDOWS
585then
586        SYSTEMROOT="Windows"
587elif ogGetPath $DISK $PART WINNT
588then
589        SYSTEMROOT="winnt"
590else
591        return $(ogRaiseError $OG_ERR_NOTOS; echo $?)
592fi
593
594ogUnmount $DISK $PART
595let DISK=$DISK-1
596let REGISTREDDISK=$REGISTREDDISK-1
597#Preparando instruccion Windows Boot Manager
598cat > $FILE <<EOF
599windows_disk=$DISK
600windows_main_part=$PART
601windows_dir=$SYSTEMROOT
602disk=$REGISTREDDISK
603main_part=$REGISTREDPART
604;ext_part
605part_letter=$REGISTREDVOL
606EOF
607spartlnx.run -cui -nm -u -f $FILE &
608sleep 5
609ps aux > /dev/null | grep $! | grep -E "T|S" | kill -9 $! > /dev/null
610
611}
612
613
614#         ogGrubInstallMbr  int_disk_GRUBCFG  int_partition_GRUBCFG #@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
615#@brief   Instala y actualiza el gestor grub el el MBR del disco duro donde se encuentra el fichero grub.cfg. Admite sistemas Windows.
616#@param   int_disk_SecondStage     
617#@param   int_part_SecondStage     
618#@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
619#@return 
620#@exception OG_ERR_FORMAT    Formato incorrecto.
621#@version 1.0.2 - Primeras pruebas.
622#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
623#@date    2011-10-29
624#@version 1.0.3 - Soporte para linux de 32 y 64 bits
625#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
626#@date    2012-03-13
627#@version 1.0.3 - Ficheros de configuracion independientes segun ubicación de la primera etapa
628#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
629#@date    2012-03-13
630#*/ ##
631
632function ogGrubInstallMbr {
633
634# Variables locales.
635local PART DISK VERSION FIRSTAGE SECONSTAGE CHECKOS KERNELPARAM BACKUPNAME
636
637# Si se solicita, mostrar ayuda.
638if [ "$*" == "help" ]; then
639    ogHelp "$FUNCNAME" "$FUNCNAME  int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage   \"param param \"  " \
640           "$FUNCNAME 1 1 FALSE " \
641           "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" "
642    return
643fi 
644
645# Error si no se reciben 2 parámetros.
646[ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
647
648
649DISK=$1; PART=$2;
650CHECKOS=${3:-"FALSE"}
651KERNELPARAM=$4
652BACKUPNAME=".backup.og"
653
654#Error si no es linux.
655#TODO: comprobar si se puede utilizar la particion windows como contenedor de grub.
656#VERSION=$(ogGetOsVersion $DISK $PART)
657#echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?)
658
659#Localizar primera etapa del grub
660FIRSTSTAGE=$(ogDiskToDev $DISK)
661
662#localizar disco segunda etapa del grub
663SECONDSTAGE=$(ogMount $DISK $PART)
664
665# prepara el directorio principal de la segunda etapa
666[ -d ${SECONDSTAGE}/boot/grub/ ]  || mkdir -p ${SECONDSTAGE}/boot/grub/
667
668#Localizar directorio segunda etapa del grub   
669PREFIXSECONDSTAGE="/boot/grubMBR"
670
671# Si Reconfigurar segunda etapa (grub.cfg) == FALSE
672if [ -f ${SECONDSTAGE}/boot/grub/grub.cfg -o -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ]
673then
674    if [ "$CHECKOS" == "false" -o "$CHECKOS" == "FALSE" ]
675    then
676        # Si no se reconfigura se utiliza el grub.cfg orginal
677        [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg
678                # Si no se reconfigure se borra los ficheros previos de configuración específicos de opengnsys.
679        [ -d ${SECONDSTAGE}${PREFIXSECONDSTAGE} ] &&  rm -fr ${SECONDSTAGE}${PREFIXSECONDSTAGE}
680        # Reactivamos el grub con el grub.cfg original.
681        grub-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE
682        return $?
683    fi
684fi
685
686# SI Reconfigurar segunda etapa (grub.cfg) == TRUE
687#Configur la sintaxis grub para evitar menus de "recovery" en el OGLive
688echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub
689echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub
690
691#Evitar detectar modo recovery - mover grub.cfg original a grub.cfg.backup
692[ -f ${SECONDSTAGE}/boot/grub/grub.cfg ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME
693
694#Preparar configuración segunda etapa: crear ubicacion
695mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/
696#Preparar configuración segunda etapa: crear cabecera del fichero
697/etc/grub.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
698#Preparar configuración segunda etapa: crear entrada del sistema operativo
699grubSyntax "$KERNELPARAM" >> ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
700
701#Instalar el grub
702grub-install --force --root-directory=${SECONDSTAGE}${PREFIXSECONDSTAGE} $FIRSTSTAGE
703}
704
705
706
707#         ogGrubInstallPartition int_disk_SECONDSTAGE  int_partition_SECONDSTAGE bolean_Check_Os_installed_and_Configure_2ndStage
708#@brief   Instala y actualiza el gestor grub en el bootsector de la particion indicada
709#@param   int_disk_SecondStage     
710#@param   int_part_SecondStage     
711#@param   bolean_Check_Os_installed_and_Configure_2ndStage   true | false[default]
712#@param   str "kernel param "   
713#@return 
714#@exception OG_ERR_FORMAT    Formato incorrecto.
715#@version 1.0.2 - Primeras pruebas.
716#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
717#@date    2011-10-29
718#@version 1.0.3 - Soporte para linux de 32 y 64 bits
719#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
720#@date    2012-03-13
721#@version 1.0.3 - Ficheros de configuracion independientes segun ubicación de la priemra etapa
722#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
723#@date    2012-03-13
724#*/ ##
725
726function ogGrubInstallPartition {
727
728# Variables locales.
729local PART DISK VERSION FIRSTAGE SECONSTAGE CHECKOS KERNELPARAM BACKUPNAME
730
731# Si se solicita, mostrar ayuda.
732if [ "$*" == "help" ]; then
733    ogHelp "$FUNCNAME" "$FUNCNAME int_ndiskSecondStage int_partitionSecondStage bolean_Configure_2ndStage   \"param param \" " \
734           "$FUNCNAME 1 1 FALSE " \
735           "$FUNCNAME 1 1 TRUE \"nomodeset irqpoll pci=noacpi quiet splash \" "
736    return
737fi 
738
739# Error si no se reciben 2 parámetros.
740[ $# -ge 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
741
742DISK=$1; PART=$2;
743CHECKOS=${3:-"FALSE"}
744KERNELPARAM=$4
745BACKUPNAME=".backup.og"
746
747#error si no es linux.
748VERSION=$(ogGetOsVersion $DISK $PART)
749echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?)
750
751#Localizar primera etapa del grub
752FIRSTSTAGE=$(ogDiskToDev $DISK $PART)
753
754#localizar disco segunda etapa del grub
755SECONDSTAGE=$(ogMount $DISK $PART)
756
757#Localizar directorio segunda etapa del grub   
758PREFIXSECONDSTAGE="/boot/grubPARTITION"
759
760# Si Reconfigurar segunda etapa (grub.cfg) == FALSE
761if [ -f ${SECONDSTAGE}/boot/grub/grub.cfg -o -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ]
762then
763    if [ "$CHECKOS" == "false" -o "$CHECKOS" == "FALSE" ]
764    then
765        # Si no se reconfigura se utiliza el grub.cfg orginal
766        [ -f ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME ${SECONDSTAGE}/boot/grub/grub.cfg
767                # Si no se reconfigure se borra los ficheros previos de configuración específicos de opengnsys.
768        [ -d ${SECONDSTAGE}${PREFIXSECONDSTAGE} ] &&  rm -fr ${SECONDSTAGE}${PREFIXSECONDSTAGE}
769        # Reactivamos el grub con el grub.cfg original.
770        grub-install --force --root-directory=${SECONDSTAGE} $FIRSTSTAGE
771        return $?
772    fi
773fi
774
775# SI Reconfigurar segunda etapa (grub.cfg) == TRUE
776#Configur la sintaxis grub para evitar menus de "recovery" en el OGLive
777echo "GRUB_DISABLE_RECOVERY=\"true\"" >> /etc/default/grub
778echo "GRUB_DISABLE_LINUX_UUID=\"true\"" >> /etc/default/grub
779
780#Evitar detectar modo recovery - mover grub.cfg original a grub.cfg.backup.og
781[ -f ${SECONDSTAGE}/boot/grub/grub.cfg ] && mv ${SECONDSTAGE}/boot/grub/grub.cfg ${SECONDSTAGE}/boot/grub/grub.cfg$BACKUPNAME
782
783#Preparar configuración segunda etapa: crear ubicacion
784mkdir -p ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/
785#Preparar configuración segunda etapa: crear cabecera del fichero
786/etc/grub.d/00_header > ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
787#Preparar configuración segunda etapa: crear entrada del sistema operativo
788grubSyntax $DISK $PART "$KERNELPARAM" >> ${SECONDSTAGE}${PREFIXSECONDSTAGE}/boot/grub/grub.cfg
789
790#Instalar el grub
791grub-install --force --root-directory=${SECONDSTAGE}${PREFIXSECONDSTAGE} $FIRSTSTAGE
792}
793
794###
795#En pruebas
796##
797#/**
798#         ogConfigureFstab int_ndisk int_nfilesys
799#@brief   Establece el nombre del equipo en los ficheros hostname y hosts.
800#@param   int_ndisk      nº de orden del disco
801#@param   int_nfilesys   nº de orden del sistema de archivos
802#@return  (nada)
803#@exception OG_ERR_FORMAT    Formato incorrecto.
804#@exception OG_ERR_NOTFOUND  No se encuentra el fichero fstab a procesar.
805#@warning Puede haber un error si hay más de 1 partición swap.
806#@version 1.0.5 - Primera versión para OpenGnSys.
807#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
808#@date    2013-03-21
809#*/ ##
810function ogConfigureFstab {
811# Variables locales.
812local FSTAB DEFROOT PARTROOT DEFSWAP PARTSWAP
813
814# Si se solicita, mostrar ayuda.
815if [ "$*" == "help" ]; then
816    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
817           "$FUNCNAME 1 1"
818    return
819fi
820# Error si no se reciben 2 parámetros.
821[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
822# Error si no se encuentra un fichero  etc/fstab  en el sistema de archivos.
823FSTAB=$(ogGetPath $1 $2 /etc/fstab) 2>/dev/null
824[ -n "$FSTAB" ] || ogRaiseError $OG_ERR_NOTFOUND "$1,$2,/etc/fstab" || return $?
825
826# Hacer copia de seguridad del fichero fstab original.
827cp -a ${FSTAB} ${FSTAB}.backup
828# Dispositivo del raíz en fichero fstab: 1er campo (si no tiene "#") con 2º campo = "/".
829DEFROOT=$(awk '$1!~/#/ && $2=="/" {print $1}' ${FSTAB})
830PARTROOT=$(ogDiskToDev $1 $2)
831# Configuración de swap (para cualquier tipo de tabla de particiones).
832# AVISO: puede producirse un error si hay más de 1 partición de swap.
833swapon -a
834PARTSWAP=$(swapon -s | awk '$1~/^\// {print $1}')
835if [ -n "$PARTSWAP" ]
836then
837    # Dispositivo de swap en fichero fstab: 1er campo (si no tiene "#") con 3er campo = "swap".
838    DEFSWAP=$(awk '$1!~/#/ && $3=="swap" {print $1}' ${FSTAB})
839    if [ -n "$DEFSWAP" ]
840    then
841        echo "Hay definicion de swap en el fstab $DEFSWAP -> modificamos fichero con nuevo valor $DEFSWAP->$PARTSWAP"   # Mensaje temporal.
842        sed "s|$DEFSWAP|$PARTSWAP|g ; s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
843    else
844        echo "No hay definicion de swap y si hay partición swap -> moficamos fichero"   # Mensaje temporal.
845        sed "s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
846        echo "$PARTSWAP  none    swap    sw   0  0" >> ${FSTAB}
847    fi 
848else
849    echo "No hay partición swap -> configuramos fstba"  # Mensaje temporal.
850    sed "s|$DEFROOT|$PARTROOT|g" ${FSTAB}.backup > ${FSTAB}
851fi
852}
853
854
855###
856#En pruebas
857##
858#/**
859#         ogSetLinuxName int_ndisk int_nfilesys [str_name]
860#@brief   Establece el nombre del equipo en los ficheros hostname y hosts.
861#@param   int_ndisk      nº de orden del disco
862#@param   int_nfilesys   nº de orden del sistema de archivos
863#@param   str_name       nombre asignado (opcional)
864#@return  (nada)
865#@exception OG_ERR_FORMAT    Formato incorrecto.
866#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
867#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
868#@note    Si no se indica nombre, se asigna un valor por defecto.
869#@version 1.0.5 - Primera versión para OpenGnSys.
870#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
871#@date    2013-03-21
872#*/ ##
873function ogSetLinuxName ()
874{
875# Variables locales.
876local MNTDIR ETC NAME
877
878# Si se solicita, mostrar ayuda.
879if [ "$*" == "help" ]; then
880    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys [str_name]" \
881           "$FUNCNAME 1 1" "$FUNCNAME 1 1 practica-pc"
882    return
883fi
884# Error si no se reciben 2 o 3 parámetros.
885case $# in
886    2)   # Asignar nombre automático (por defecto, "pc").
887         NAME="$(ogGetHostname)"
888         NAME=${NAME:-"pc"} ;;
889    3)   # Asignar nombre del 3er parámetro.
890         NAME="$3" ;;
891    *)   # Formato de ejecución incorrecto.
892         ogRaiseError $OG_ERR_FORMAT
893         return $?
894esac
895
896# Montar el sistema de archivos.
897MNTDIR=$(ogMount $1 $2) 2>/dev/null
898[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
899
900ETC=$(ogGetPath $1 $2 /etc)
901
902if [ -d "$ETC" ]; then
903        #cambio de nombre en hostname
904        echo "$NAME" > $ETC/hostname
905        #Opcion A para cambio de nombre en hosts
906        #sed "/127.0.1.1/ c\127.0.1.1 \t $HOSTNAME" $ETC/hosts > /tmp/hosts && cp /tmp/hosts $ETC/ && rm /tmp/hosts
907        #Opcion B componer fichero de hosts
908        cat > $ETC/hosts <<EOF
909127.0.0.1       localhost
910127.0.1.1       $NAME
911
912# The following lines are desirable for IPv6 capable hosts
913::1     ip6-localhost ip6-loopback
914fe00::0 ip6-localnet
915ff00::0 ip6-mcastprefix
916ff02::1 ip6-allnodes
917ff02::2 ip6-allrouters
918EOF
919fi
920}
921
922
923###
924#En pruebas
925##
926#/**
927#         ogCleanLinuxDevices int_ndisk int_nfilesys
928#@brief   Limpia los dispositivos del equipo de referencia. Interfaz de red ...
929#@param   int_ndisk      nº de orden del disco
930#@param   int_nfilesys   nº de orden del sistema de archivos
931#@return  (nada)
932#@exception OG_ERR_FORMAT    Formato incorrecto.
933#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
934#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
935#@version 1.0.5 - Primera versión para OpenGnSys.
936#@author  Antonio J. Doblas Viso.   Universidad de Malaga.
937#@date    2013-03-21
938#*/ ##
939function ogCleanLinuxDevices ()
940{
941# Variables locales.
942local MNTDIR
943
944# Si se solicita, mostrar ayuda.
945if [ "$*" == "help" ]; then
946    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
947           "$FUNCNAME 1 1"
948    return
949fi
950# Error si no se reciben 2 parámetros.
951[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
952
953# Montar el sistema de archivos.
954MNTDIR=$(ogMount $1 $2) 2>/dev/null
955[ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $?
956
957# Eliminar fichero de configuración de udev para dispositivos fijos de red.
958rm -f ${MNTDIR}/etc/udev/rules.d/70-persistent-net.rules
959}
960
Note: See TracBrowser for help on using the repository browser.