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