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