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