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