source: client/engine/Boot.lib @ 78b5dfe7

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 78b5dfe7 was 78b5dfe7, checked in by adv <adv@…>, 14 years ago

version 1.0.1 #402 Gestion completa restauracion/arranque windows en particiones distintas a la original de la imagen. Permite varios windows independientes.

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

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