source: client/engine/Boot.lib @ 2391e30

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 2391e30 was 1c69be8, checked in by adv <adv@…>, 12 years ago

#588 #484 las funciones ogGrubInstallXXX() respeta y reutiliza el fichero original incluido en la imagen si no se desea utilizar el autoconfigurador de OpenGnSys.

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

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