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