source: client/engine/Disk.lib @ 38231e9

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 38231e9 was 1e7eaab, checked in by ramon <ramongomez@…>, 15 years ago

Installador vale para repositorio y descargable; funciones de API compatibles Doxygen.

git-svn-id: https://opengnsys.es/svn/trunk@652 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 21.7 KB
Line 
1#!/bin/bash
2#/**
3#@file    Disk.lib
4#@brief   Librería o clase Disk
5#@class   Disk
6#@brief   Funciones para gestión de discos y particiones.
7#@version 0.9
8#@warning License: GNU GPLv3+
9#*/
10
11
12#/**
13#         ogCreatePartitions ndisk parttype:partsize ...
14#@brief   Define el conjunto de particiones de un disco.
15#@arg \c  int_ndisk      nº de orden del disco
16#@arg \c  str_parttype   mnemónico del tipo de partición
17#@arg \c  int_partsize   tamaño de la partición (en KB)
18#@return  (nada, por determinar)
19#@exception OG_ERR_FORMAT   formato incorrecto.
20#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
21#@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize
22#@attention Pueden definirse particiones vacías de tipo \c EMPTY
23#@note    Requisitos: sfdisk, parted, partprobe, awk
24#@todo    Definir atributos (arranque, oculta) y tamaños en MB, GB, etc.
25#@version 0.9 - Primera versión para OpenGNSys
26#@author  Ramon Gomez, ETSII Universidad de Sevilla
27#@date    2009/09/09
28#*/ ##
29function ogCreatePartitions () {
30
31# Variables locales.
32local DISK PART SECTORS START SIZE TYPE EXTSTART EXTSIZE tmpsfdisk
33# Si se solicita, mostrar ayuda.
34if [ "$*" == "help" ]; then
35    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_parttype:int_partsize ..." \
36           "$FUNCNAME 1 NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000"
37    return
38fi
39# Error si no se reciben menos de 2 parámetros.
40[ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
41
42# Desmontar todos los sistemas de archivos del disco.
43DISK="$(ogDiskToDev $1)" || return $?
44ogUnmountAll $1
45shift
46
47# Nº total de sectores, para evitar desbordamiento
48SECTORS=$(awk -v D=${DISK#/dev/} '{if ($4==D) {print $3*2}}' /proc/partitions)
49# Sector de inicio de la particon (la 1ª empieza en el sector 63).
50START=63
51PART=1
52
53# Fichero temporal de entrada para "sfdisk"
54tmpsfdisk=/tmp/sfdisk$$
55trap "rm -f $tmpsfdisk" 1 2 3 9 15
56
57echo "unit: sectors" >$tmpsfdisk
58echo                >>$tmpsfdisk
59
60#/// Generar fichero de entrada para "sfdisk" con las particiones.
61while [ $# -gt 0 ]; do
62    #/// Leer formato de cada parámetro - Tipo:Tamaño
63    TYPE="${1%%:*}"
64    SIZE="${1#*:}"
65    [ -z "$SIZE" ] && ogRaiseError $OG_ERR_FORMAT && return $?
66    #/// Convertir en sectores de 512 B.
67    SIZE=$[SIZE*2]
68    [ $SIZE -eq 0 ] && ogRaiseError $OG_ERR_FORMAT && return $?
69    #/// Obtener identificador de tipo de partición.
70    case "$TYPE" in
71        EMPTY)      ID=0  ;;
72        EXTENDED)   ID=5
73                    [ $PART -gt 4 ] && ogRaiseError $OG_ERR_FORMAT && return $?
74                    EXTSTART=$START
75                    EXTSIZE=$SIZE
76                    ;;
77        EXT[234]|REISERFS|REISER4|XFS|JFS)
78                    ID=83 ;;
79        LINUX-SWAP) ID=82 ;;
80        LINUX-LVM)  ID=8e ;;
81        LINUX-RAID) ID=fd ;;
82        SOLARIS)    ID=bf ;;
83        NTFS|EXFAT) ID=7  ;;
84        HNTFS)      ID=17 ;;
85        FAT32)      ID=b  ;;
86        HFAT32)     ID=1b ;;
87        FAT16)      ID=6  ;;
88        HFAT16)     ID=16 ;;
89        FAT12)      ID=1  ;;
90        HFAT12)     ID=11 ;;
91        CACHE)      ID=ca ;;
92        *)          ogRaiseError $OG_ERR_PARTITION "$TYPE"
93                    return $? ;;
94    esac
95    # Incluir particiones lógicas dentro de la partición extendida.
96    if [ $PART = 5 ]; then
97        [ -z "$EXTSTART" ] && ogRaiseError $OG_ERR_FORMAT && return $?
98        START=$EXTSTART
99        SECTORS=$[EXTSTART+EXTSIZE]
100    fi
101    # Generar datos para la partición.
102    echo "$DISK$PART : start=$START, size=$SIZE, Id=$ID" >>$tmpsfdisk
103    #/// Error si se supera el nº total de sectores.
104    START=$[START+SIZE]
105    [ $START -gt $SECTORS ] && ogRaiseError $OG_ERR_FORMAT && return $?
106    PART=$[PART+1]
107    shift
108done
109# Si no se indican las 4 particiones primarias, definirlas como vacías.
110while [ $PART -le 4 ]; do
111    echo "$DISK$PART : start=0, size=0, Id=0" >>$tmpsfdisk
112    PART=$[PART+1]
113done
114# Si se define partición extendida sin lógicas, crear particion 5 vacía.
115if [ $PART = 5 -a -n "$EXTSTART" ]; then
116    echo "${DISK}5 : start=$EXTSTART, size=$EXTSIZE, Id=0" >>$tmpsfdisk
117fi
118
119# Si la tabla de particiones no es valida, volver a generarla.
120[ $(parted -s $DISK print >/dev/null) ] || fdisk $DISK <<< "w"
121# Definir particiones y notificar al kernel.
122sfdisk -f $DISK < $tmpsfdisk 2>/dev/null && sfdisk -R $DISK
123rm -f $tmpsfdisk
124}
125
126
127#/**
128#         ogDevToDisk device
129#@brief   Devuelve el nº de orden de dicso (y partición) correspondiente al nombre de fichero de dispositivo.
130#@arg \c  path_device Camino del fichero de dispositivo.
131#@return  ndisk (para dispositivo de disco)
132#@return  ndisk npartition (para dispositivo de partición).
133#@exception OG_ERR_FORMAT   Formato incorrecto.
134#@exception OG_ERR_NOTFOUND Dispositivo no detectado.
135#@note    Requisitos: awk
136#@version 0.9 - Primera versión para OpenGNSys
137#@author  Ramon Gomez, ETSII Universidad Sevilla
138#@date    2009-07-20
139#*/ ##
140function ogDevToDisk () {
141
142# Variables locales.
143local d n
144# Si se solicita, mostrar ayuda.
145if [ "$*" == "help" ]; then
146    ogHelp "$FUNCNAME" "$FUNCNAME path_device" \
147           "$FUNCNAME /dev/sda  =>  1 1"
148    return
149fi
150
151# Error si no se recibe 1 parámetro.
152[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
153#/// Error si no es fichero de bloques.
154[ -b "$1" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $?
155
156# Procesa todos los discos para devolver su nº de orden y de partición.
157n=1
158for d in $(ogDiskToDev); do
159    [ -n "$(echo $1 | grep $d)" ] && echo "$n ${1#$d}" && return
160    n=$[n+1]
161done
162ogRaiseError $OG_ERR_NOTFOUND "$1"
163return $OG_ERR_NOTFOUND
164}
165
166
167#/**
168#         ogDiskToDev [ndisk [npartition]]
169#@brief   Devuelve la equivalencia entre el nº de orden del dispositivo (dicso o partición) y el nombre de fichero de dispositivo correspondiente.
170#@arg \c  int_ndisk      nº de orden del disco
171#@arg \c  int_npartition nº de orden de la partición
172#@return  Para 0 parametros: Devuelve los nombres de ficheros  de los dispositivos sata/ata/usb linux encontrados.
173#@return  Para 1 parametros: Devuelve la ruta del disco duro indicado.
174#@return  Para 2 parametros: Devuelve la ruta de la particion indicada.
175#@exception OG_ERR_FORMAT   Formato incorrecto.
176#@exception OG_ERR_NOTFOUND Dispositivo no detectado.
177#@note    Requisitos: awk, lvm
178#@version 0.9 - Primera versión para OpenGNSys
179#@author  Ramon Gomez, ETSII Universidad Sevilla
180#@date    2009-07-20
181#*/ ##
182function ogDiskToDev () {
183
184# Variables locales
185local ALLDISKS VOLGROUPS DISK PART
186
187# Si se solicita, mostrar ayuda.
188if [ "$*" == "help" ]; then
189    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk [int_npartition]" \
190           "$FUNCNAME      =>  /dev/sda /dev/sdb" \
191           "$FUNCNAME 1    =>  /dev/sda" \
192           "$FUNCNAME 1 1  =>  /dev/sda1"
193    return
194fi
195
196# Listar dispositivo para los discos duros (tipos: 3=hd, 8=sd).
197ALLDISKS=$(awk '($1==3 || $1==8) && $4!~/[0-9]/ {printf "/dev/%s ",$4}' /proc/partitions)
198VOLGROUPS=$(vgs -a --noheadings 2>/dev/null | awk '{printf "/dev/%s ",$1}')
199ALLDISKS="$ALLDISKS $VOLGROUPS"
200
201# Mostrar salidas segun el número de parametros.
202case $# in
203    0)  # Muestra todos los discos, separados por espacios.
204        echo $ALLDISKS
205        ;;
206    1)  # Error si el parámetro no es un digito.
207        [ -z "${1/[1-9]/}" ] || ogRaiseError $OG_ERR_FORMAT || return $?
208        DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}')
209        # Error si el fichero no existe.
210        [ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $?
211        echo "$DISK"
212        ;;
213    2)  # Error si los 2 parámetros no son digitos.
214        [ -z "${1/[1-9]/}" -a -z "${2/[1-9]/}" ] || ogRaiseError $OG_ERR_FORMAT|| return $?
215        DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}')
216        [ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $?
217        PART="$DISK$2"
218        # Comprobar si es partición.
219        if [ -b "$PART" ]; then
220            echo "$PART"
221        elif [ -n "$VOLGROUPS" ]; then
222            # Comprobar si volumen lógico.
223            PART=$(lvscan -a 2>/dev/null | grep "'$DISK/" | awk -v n=$2 -F\' '{if (NR==n) print $2}')
224            [ -e "$PART" ] || ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $?
225            echo "$PART"
226        else
227            ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $?
228        fi
229        ;;
230    *)  # Formato erroneo.
231        ogRaiseError $OG_ERR_FORMAT
232        return $OG_ERR_FORMAT
233        ;;
234esac
235}
236
237
238#/**
239#         ogGetPartitionActive ndisk
240#@brief   Muestra que particion de un disco esta marcada como de activa.
241#@arg \c  int_ndisk      nº de orden del disco
242#@return  Nº de partición activa
243#@exception OG_ERR_FORMAT Formato incorrecto.
244#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
245#@note    Requisitos: parted
246#@todo    Queda definir formato para atributos (arranque, oculta, ...).
247#@version 0.9 - Primera versión compatible con OpenGNSys.
248#@author  Ramon Gomez, ETSII Universidad de Sevilla
249#@date    2009/07/24
250#*/ ##
251function ogGetPartitionActive () {
252
253# Variables locales
254local DISK
255
256# Si se solicita, mostrar ayuda.
257if [ "$*" == "help" ]; then
258    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "$FUNCNAME 1  =>  1"
259    return
260fi
261# Error si no se recibe 1 parámetro.
262[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
263
264# Comprobar que el disco existe y listar su partición activa.
265DISK="$(ogDiskToDev $1)" || return $?
266parted $DISK print 2>/dev/null | awk '/boot/ {print $1}'
267}
268
269
270#/**
271#         ogGetPartitionId ndisk npartition
272#@brief   Devuelve el mnemonico con el tipo de sistema de archivos.
273#@arg \c  int_ndisk      nº de orden del disco
274#@arg \c  int_npartition nº de orden de la partición
275#@return  Identificador de tipo de partición.
276#@exception OG_ERR_FORMAT   Formato incorrecto.
277#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
278#@note    Requisitos: sfdisk
279#@version 0.9 - Primera versión compatible con OpenGNSys.
280#@author  Ramon Gomez, ETSII Universidad de Sevilla
281#@date    25/03/2009
282#*/ ##
283function ogGetPartitionId () {
284
285# Variables locales.
286local DISK PART
287
288# Si se solicita, mostrar ayuda.
289if [ "$*" == "help" ]; then
290    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
291           "$FUNCNAME 1 1  =>  7"
292    return
293fi
294# Error si no se reciben 2 parámetros.
295[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
296
297# Detectar id. de tipo de particion y codificar al mnemonico.
298DISK=$(ogDiskToDev $1) || return $?
299PART=$(ogDiskToDev $1 $2) || return $?
300echo $(sfdisk --id $DISK $2 2>/dev/null)
301}
302
303
304#/**
305#         ogGetPartitionSize ndisk npartition
306#@brief   Muestra el tamano en KB de una particion determinada.
307#@arg \c  int_ndisk      nº de orden del disco
308#@arg \c  int_npartition nº de orden de la partición
309#@return  tamañoKB
310#@exception OG_ERR_FORMAT   formato incorrecto.
311#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
312#@note    Requisitos: sfdisk, awk
313#@version 0.9 - Primera versión para OpenGNSys
314#@author  Ramon Gomez, ETSII Universidad de Sevilla
315#@date    2009/07/24
316#*/ ##
317function ogGetPartitionSize () {
318
319# Variables locales.
320local PART
321
322# Si se solicita, mostrar ayuda.
323if [ "$*" == "help" ]; then
324    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
325           "$FUNCNAME 1 1  =>  10000000"
326    return
327fi
328# Error si no se reciben 2 parámetros.
329[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
330
331# Obtener el tamaño de la partición.
332DISK="$(ogDiskToDev $1)" || return $?
333PART="$(ogDiskToDev $1 $2)" || return $?
334case "$(ogGetPartitionId $1 $2)" in
335    5|f)  # Procesar detección de tamaño de partición Extendida.
336                # /* (comentario Doxygen)
337          sfdisk -l $DISK 2>/dev/null | \
338                    awk -v p=$PART '{if ($1==p) {sub (/\*/,""); print $5} }'
339                # (comentario Doxygen) */
340          ;;
341    *)    sfdisk -s $PART
342          ;;
343esac
344}
345
346
347#/**
348#         ogListPartitions int_ndisk
349#@brief   Lista las particiones definidas en un disco.
350#@arg \c  int_ndisk  nº de orden del disco
351#@return  tipo:tamanoKB ...
352#@exception OG_ERR_FORMAT   formato incorrecto.
353#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
354#@note    Requisitos: \c parted \c awk
355#@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize
356#@attention Las tuplas de valores están separadas por espacios.
357#@version 0.9 - Primera versión para OpenGNSys
358#@author  Ramon Gomez, ETSII Universidad de Sevilla
359#@date    2009/07/24
360#*/ ##
361function ogListPartitions () {
362
363# Variables locales.
364local DISK PART NPARTS TYPE SIZE
365
366#/// Si se solicita, mostrar ayuda.
367if [ "$*" == "help" ]; then
368    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \
369           "$FUNCNAME 1  =>  NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000"
370    return
371fi
372#/// Error si no se recibe 1 parámetro.
373[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT "$FORMAT" || return $?
374
375#/// Procesar la salida de \c parted .
376DISK="$(ogDiskToDev $1)" || return $?
377NPARTS=$(ogGetPartitionsNumber $1)
378for (( PART = 1; PART <= NPARTS; PART++ )); do
379    TYPE=$(ogGetFsType $1 $PART 2>/dev/null)
380    if [ $? -eq 0 ]; then
381        SIZE=$(ogGetPartitionSize $1 $PART 2>/dev/null)
382        echo -n "$TYPE:$SIZE "
383    else
384        echo -n "EMPTY:0 "
385    fi
386done
387echo
388}
389
390
391#/**
392#         ogListPrimaryPartitions int_ndisk
393#@brief   Metafunción que lista las particiones primarias no vacías definidas en un disco.
394#@arg \c  int_ndisk  nº de orden del disco
395#@see     ogListPartitions
396#*/ ##
397function ogListPrimaryPartitions () {
398
399# Variables locales.
400local PARTS
401
402PARTS=$(ogListPartitions "$@") || return $?
403echo $PARTS | cut -sf1-4 -d" " | sed 's/\( EMPTY:0\)*$//'
404}
405
406
407#/**
408#         ogListLogicalPartitions int_ndisk
409#@brief   Metafunción que lista las particiones lógicas definidas en un disco.
410#@arg \c  int_ndisk  nº de orden del disco
411#@see     ogListPartitions
412#*/ ##
413function ogListLogicalPartitions () {
414
415# Variables locales.
416local PARTS
417
418PARTS=$(ogListPartitions "$@") || return $?
419echo $PARTS | cut -sf5- -d" "
420}
421
422
423#/**
424#         ogSetPartitionActive ndisk npartition
425#@brief   Establece cual es la partición activa de un disco.
426#@arg \c  int_ndisk      nº de orden del disco
427#@arg \c  int_npartition nº de orden de la partición
428#@return  Nada.
429#@exception OG_ERR_FORMAT   Formato incorrecto.
430#@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo.
431#@note    Requisitos: parted
432#@version 0.9 - Primera versión compatible con OpenGNSys.
433#@author  Ramon Gomez, ETSII Universidad de Sevilla
434#@date    2009/09/17
435#*/ ##
436function ogSetPartitionActive () {
437
438# Variables locales
439local DISK PART
440
441# Si se solicita, mostrar ayuda.
442if [ "$*" == "help" ]; then
443    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
444           "$FUNCNAME 1 1"
445    return
446fi
447# Error si no se reciben 2 parámetros.
448[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
449
450# Comprobar que el disco existe y activar la partición indicada.
451DISK="$(ogDiskToDev $1)" || return $?
452PART="$(ogDiskToDev $1 $2)" || return $?
453parted -s $DISK set $2 boot on 2>/dev/null
454}
455
456
457#/**
458#         ogSetPartitionSize ndisk npartition size
459#@brief   Muestra el tamano en KB de una particion determinada.
460#@arg \c  int_ndisk      nº de orden del disco
461#@arg \c  int_npartition nº de orden de la partición
462#@arg \c  int_size       tamaño de la partición (en KB)
463#@return  (nada)
464#@exception OG_ERR_FORMAT   formato incorrecto.
465#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
466#@note    Requisitos: sfdisk, awk
467#@todo    Compruebar que el tamaño sea numérico positivo y evitar que pueda solaparse con la siguiente partición.
468#@version 0.9 - Primera versión para OpenGNSys
469#@author  Ramon Gomez, ETSII Universidad de Sevilla
470#@date    2009/07/24
471#*/ ##
472function ogSetPartitionSize () {
473
474# Variables locales.
475local DISK PART SIZE
476
477# Si se solicita, mostrar ayuda.
478if [ "$*" == "help" ]; then
479    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
480           "$FUNCNAME 1 1 10000000"
481    return
482fi
483# Error si no se reciben 3 parámetros.
484[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
485
486# Obtener el tamaño de la partición.
487DISK="$(ogDiskToDev $1)" || return $?
488PART="$(ogDiskToDev $1 $2)" || return $?
489# Convertir tamaño en KB a sectores de 512 B.
490SIZE=$[$3*2] || ogRaiseError $OG_ERR_FORMAT || return $?
491# Usar \c sfdisk para redefinir el tamaño.
492sfdisk -f -uS -N$2 $DISK <<< ",$SIZE" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
493}
494
495
496#/**
497#         ogUpdatePartitionTable
498#@brief   Fuerza al kernel releer la tabla de particiones de los discos duros
499#@arg \c  no requiere
500#@return  informacion propia de la herramienta
501#@note    Requisitos: \c partprobe
502#@warning pendiente estructurar la funcion a opengnsys
503#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
504#@note   funcion importada de EAC
505#*/
506
507function ogUpdatePartitionTable () {
508echo "Forzando al kernel la lectura de la tabla de particiones"
509list=`partprobe -s | cut -f1 -d: ` 2>/dev/null
510echo $list > /tmp/disk
511}
512
513
514
515
516function ogGetPartitionsNumber () {
517#/**  @function ogGetPartitionsNumber: @brief detecta el numero de particiones del disco duro indicado.
518#@param  int_numdisk   (indentificado EAC del disco)
519#@return  devuelve el numero paritiones del disco duro indicado
520#@warning  Salidas de errores no determinada
521#@attention Requisitos: parted
522#@note    Notas sin especificar
523#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
524#*/
525           #local disco totalpart
526           #disco=`ogDiskToDev $1`
527           #totalpart=`parted $disco print | egrep ^" [0123456789] " -c`
528           #echo $totalpart
529local DISK
530#/// Contar el nº de veces que aparece el disco en su lista de particiones.
531DISK=$(ogDiskToDev $1) 2>/dev/null
532sfdisk -l $DISK 2>/dev/null | grep -c "^$DISK"
533}
534
535
536function ogDiskToRelativeDev () {
537#/**  @function ogDiskToRelativeDev: @brief Traduce los ID de discos o particiones EAC a ID Linux relativos, es decir 1 1 => sda1
538#@param  Admite 1 parametro:   $1  int_numdisk
539#@param  Admite 2 parametro:   $1   int_numdisk                    $2  int_partition
540#@return  Para 1 parametros traduce Discos Duros: Devuelve la ruta relativa linux del disco duro indicado con nomenclatura EAC.........ejemplo: IdPartition 1 => sda
541#@return  Para 2 parametros traduce Particiones: Devuelve la ruta relativa linux de la particion indicado con nomenclatura EAC...........  ejemplo: IdPartition  2 1 => sdb1
542#@warning  No definidas
543#@attention
544#@note    Notas sin especificar
545#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
546#*/
547
548if [ $# = 0 ]
549then
550        Msg "Info: Traduce el identificador del dispositivo EAC a dispositivo linux \n" info
551        Msg "Sintaxis1: IdPartition int_disk -----------------Ejemplo1: IdPartition 1 -> sda " example
552        Msg "Sintaxis2: IdPartition int_disk int_partition  --Ejemplo2: IdPartition 1 2 -> sda2 " example
553
554return
555fi
556#PART="$(Disk|cut -f$1 -d' ')$2"    # se comenta esta linea porque doxygen no reconoce la funcion disk y no crea los enlaces y referencias correctas.
557PART=$(ogDiskToDev|cut -f$1 -d' ')$2
558echo $PART | cut -f3 -d \/
559}
560
561
562function ogDeletePartitionTable () {
563#/**  @function ogDeletePartitionTable: @brief Borra la tabla de particiones del disco.
564#@param $1 opcion A (identificador LINUX)       str_ID_linux (/dev/sda)
565#@param $1 opcion B (Identifiador EAC)                  int_numdiskEAC(1)
566#@return   la informacion propia del fdisk
567#@warning    no definidos
568#@attention
569#@note
570#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
571#*/
572if [ $# = 0 ]
573then
574        Msg "sintaxis1: ogDeletePartitionTable int_disk" red
575        Msg "sintaxis2: ogDeletePartitionTable str_/dev/sdX" red
576        return
577fi
578if [ -n "${1%/dev/*}" ]
579        then
580        dev=`DiskToDev $1`
581        else
582        dev=$1
583fi
584echo -ne "o\nw" | fdisk $dev
585}
586
587
588
589function ogSetPartitionId() {
590#/**  @function ogSetPartitionId: @brief Cambia el identificador de la particion, pero no su sistema de archivos.
591#@param  $1 int_numdiskEAC
592#@param  $2 int_numpartitionEAC
593#@param  $3 str_tipoPartition admite EXT2 EXT3 NTFS FAT32 SWAP CACHE
594#@return   la propia del fdisk
595#@warning    no controla los parametros, si se introducen mal o simplemente no se introducen no muestra mensaje
596#@warning    Identifica por nombre del sistema de archivos no por número
597#@attention Requisitos:  fdisk
598#@note
599#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
600#*/
601
602# Variables locales
603local DISK PART ID
604
605#/// Si se solicita, mostrar ayuda.
606if [ "$*" == "help" ]; then
607    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
608           "$FUNCNAME 1 1 10000000"
609    return
610fi
611#/// Error si no se reciben 3 parámetros.
612[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
613
614#/// Sustituye nº de disco por su dispositivo.
615DISK=`ogDiskToDev $1` || return $?
616PART=`ogDiskToDev $1 $2` || return $?
617
618#/// Elección del tipo de partición.
619case "$3" in
620    EMPTY)      ID=0  ;;
621    FAT12)      ID=1  ;;
622    EXTENDED)   ID=5  ;;
623    FAT16)      ID=6  ;;
624    NTFS|EXFAT) ID=7  ;;
625    FAT32)      ID=b  ;;
626    HFAT12)     ID=11 ;;
627    HFAT16)     ID=16 ;;
628    HNTFS)      ID=17 ;;
629    HFAT32)     ID=1b ;;
630    LINUX-SWAP) ID=82 ;;
631    LINUX-LVM)  ID=8e ;;
632    EXT[234]|REISERFS|REISER4|XFS|JFS)
633                ID=83 ;;
634    SOLARIS)    ID=bf ;;
635    CACHE)      ID=ca ;;
636    LINUX-RAID) ID=fd ;;
637    *)          ogRaiseError $OG_ERR_PARTITION "$TYPE"
638                return $? ;;
639esac
640echo -ne "t\n$2\n${ID}\nw\n" | fdisk $DISK 1>/dev/null 2>&1
641}
642
643
644function ogDeletePartitionsLabels () {
645#/**  @function ogDeletePartitionsLabels: @brief Elimina la informacion que tiene el kernel del cliente og sobre los labels de los sistemas de archivos
646#@param  No requiere
647#@return   Nada
648#@warning
649#@attention Requisitos:  comando interno linux rm
650#@note
651#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
652#*/
653rm /dev/disk/by-label/*    # */ COMENTARIO OBLIGATORIO PARA DOXYGEN
654}
655
Note: See TracBrowser for help on using the repository browser.