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