source: client/engine/Disk.lib @ e834b66

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 e834b66 was 3458879, checked in by ramon <ramongomez@…>, 16 years ago

Correcciones en varias funciones; función en pruebas ogGetIpAddress.

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

  • Property mode set to 100755
File size: 20.1 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[ $# -gt 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=$(vgchange -ay &>/dev/null && vgs -a --noheadings | 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.
332PART="$(ogDiskToDev $1 $2)" || return $?
333sfdisk -s $PART
334}
335
336
337#/**
338#         ogListPartitions int_ndisk
339#@brief   Lista las particiones definidas en un disco.
340#@arg \c  int_ndisk  nº de orden del disco
341#@return  tipo:tamanoKB ...
342#@exception OG_ERR_FORMAT   formato incorrecto.
343#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
344#@note    Requisitos: \c parted \c awk
345#@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize
346#@attention Las tuplas de valores están separadas por espacios.
347#@version 0.9 - Primera versión para OpenGNSys
348#@author  Ramon Gomez, ETSII Universidad de Sevilla
349#@date    2009/07/24
350#*/
351function ogListPartitions () {
352
353# Variables locales.
354local DISK PART NPARTS
355
356#/// Si se solicita, mostrar ayuda.
357if [ "$*" == "help" ]; then
358    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \
359           "$FUNCNAME 1  =>  NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000"
360    return
361fi
362#/// Error si no se recibe 1 parámetro.
363[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT "$FORMAT" || return $?
364
365#/// Procesar la salida de \c parted .
366DISK="$(ogDiskToDev $1)" || return $?
367NPARTS=$(parted -s $DISK print | awk '$1~/^[1-9]/ {print $1}')
368for PART in $NPARTS; do
369    echo -n "$(ogGetFsType $1 $PART):$(ogGetPartitionSize $1 $PART) "
370done
371echo
372}
373
374
375#/**
376#         ogSetPartitionActive ndisk npartition
377#@brief   Establece cual es la partición activa de un disco.
378#@arg \c  int_ndisk      nº de orden del disco
379#@arg \c  int_npartition nº de orden de la partición
380#@return  Nada.
381#@exception OG_ERR_FORMAT   Formato incorrecto.
382#@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo.
383#@note    Requisitos: parted
384#@version 0.9 - Primera versión compatible con OpenGNSys.
385#@author  Ramon Gomez, ETSII Universidad de Sevilla
386#@date    2009/09/17
387#*/
388function ogSetPartitionActive () {
389
390# Variables locales
391local DISK PART
392
393#/// Si se solicita, mostrar ayuda.
394if [ "$*" == "help" ]; then
395    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
396           "$FUNCNAME 1 1"
397    return
398fi
399#/// Error si no se reciben 2 parámetros.
400[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
401
402#/// Comprobar que el disco existe y activar la partición indicada.
403DISK="$(ogDiskToDev $1)" || return $?
404PART="$(ogDiskToDev $1 $2)" || return $?
405parted -s $DISK set $2 boot on 2>/dev/null
406}
407
408
409#/**
410#         ogSetPartitionSize ndisk npartition size
411#@brief   Muestra el tamano en KB de una particion determinada.
412#@arg \c  int_ndisk      nº de orden del disco
413#@arg \c  int_npartition nº de orden de la partición
414#@arg \c  int_size       tamaño de la partición (en KB)
415#@return  (nada)
416#@exception OG_ERR_FORMAT   formato incorrecto.
417#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
418#@note    Requisitos: sfdisk, awk
419#@todo    Compruebar que el tamaño sea numérico positivo y evitar que pueda solaparse con la siguiente partición.
420#@version 0.9 - Primera versión para OpenGNSys
421#@author  Ramon Gomez, ETSII Universidad de Sevilla
422#@date    2009/07/24
423#*/
424function ogSetPartitionSize () {
425
426# Variables locales.
427local DISK PART SIZE
428
429#/// Si se solicita, mostrar ayuda.
430if [ "$*" == "help" ]; then
431    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
432           "$FUNCNAME 1 1 10000000"
433    return
434fi
435#/// Error si no se reciben 3 parámetros.
436[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
437
438#/// Obtener el tamaño de la partición.
439DISK="$(ogDiskToDev $1)" || return $?
440PART="$(ogDiskToDev $1 $2)" || return $?
441# Convertir tamaño en KB a sectores de 512 B.
442SIZE=$[$3*2] || ogRaiseError $OG_ERR_FORMAT || return $?
443#/// Usar \c sfdisk para redefinir el tamaño.
444sfdisk -f -uS -N$2 $DISK <<< ",$SIZE" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
445}
446
447
448#/**
449#         ogUpdatePartitionTable
450#@brief   Fuerza al kernel releer la tabla de particiones de los discos duros
451#@arg \c  no requiere
452#@return  informacion propia de la herramienta
453#@note    Requisitos: \c partprobe
454#@warning pendiente estructurar la funcion a opengnsys
455#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
456#@note   funcion importada de EAC
457#*/
458
459function ogUpdatePartitionTable () {
460echo "Forzando al kernel la lectura de la tabla de particiones"
461list=`partprobe -s | cut -f1 -d: ` 2>/dev/null
462echo $list > /tmp/disk
463}
464
465
466
467
468function ogGetPartitionsNumber () {
469#/**  @function ogGetPartitionsNumber: @brief detecta el numero de particiones del disco duro indicado.
470#@param  int_numdisk   (indentificado EAC del disco)
471#@return  devuelve el numero paritiones del disco duro indicado
472#@warning  Salidas de errores no determinada
473#@attention Requisitos: parted
474#@note    Notas sin especificar
475#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
476#*/
477disco=`ogDiskToDev $1`
478totalpart=`parted $disco print | egrep ^" [0123456789] " -c`
479echo $totalpart
480}
481
482
483function ogDiskToRelativeDev () {
484#/**  @function ogDiskToRelativeDev: @brief Traduce los ID de discos o particiones EAC a ID Linux relativos, es decir 1 1 => sda1
485#@param  Admite 1 parametro:   $1  int_numdisk
486#@param  Admite 2 parametro:   $1   int_numdisk                    $2  int_partition
487#@return  Para 1 parametros traduce Discos Duros: Devuelve la ruta relativa linux del disco duro indicado con nomenclatura EAC.........ejemplo: IdPartition 1 => sda
488#@return  Para 2 parametros traduce Particiones: Devuelve la ruta relativa linux de la particion indicado con nomenclatura EAC...........  ejemplo: IdPartition  2 1 => sdb1
489#@warning  No definidas
490#@attention
491#@note    Notas sin especificar
492#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
493#*/
494
495if [ $# = 0 ]
496then
497        Msg "Info: Traduce el identificador del dispositivo EAC a dispositivo linux \n" info
498        Msg "Sintaxis1: IdPartition int_disk -----------------Ejemplo1: IdPartition 1 -> sda " example
499        Msg "Sintaxis2: IdPartition int_disk int_partition  --Ejemplo2: IdPartition 1 2 -> sda2 " example
500
501return
502fi
503#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.
504PART=$(ogDiskToDev|cut -f$1 -d' ')$2
505echo $PART | cut -f3 -d \/
506}
507
508
509function ogDeletePartitionTable () {
510#/**  @function ogDeletePartitionTable: @brief Borra la tabla de particiones del disco.
511#@param $1 opcion A (identificador LINUX)       str_ID_linux (/dev/sda)
512#@param $1 opcion B (Identifiador EAC)                  int_numdiskEAC(1)
513#@return   la informacion propia del fdisk
514#@warning    no definidos
515#@attention
516#@note
517#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
518#*/
519if [ $# = 0 ]
520then
521        Msg "sintaxis1: ogDeletePartitionTable int_disk" red
522        Msg "sintaxis2: ogDeletePartitionTable str_/dev/sdX" red
523        return
524fi
525if [ -n "${1%/dev/*}" ]
526        then
527        dev=`DiskToDev $1`
528        else
529        dev=$1
530fi
531echo -ne "o\nw" | fdisk $dev
532}
533
534
535
536function ogSetPartitionId() {
537#/**  @function ogSetPartitionId: @brief Cambia el identificador de la particion, pero no su sistema de archivos.
538#@param  $1 int_numdiskEAC
539#@param  $2 int_numpartitionEAC
540#@param  $3 str_tipoPartition admite EXT2 EXT3 NTFS FAT32 SWAP CACHE
541#@return   la propia del fdisk
542#@warning    no controla los parametros, si se introducen mal o simplemente no se introducen no muestra mensaje
543#@warning    Identifica por nombre del sistema de archivos no por número
544#@attention Requisitos:  fdisk
545#@note
546#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
547#*/
548
549# Variables locales
550local DISK PART ID
551
552#/// Si se solicita, mostrar ayuda.
553if [ "$*" == "help" ]; then
554    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
555           "$FUNCNAME 1 1 10000000"
556    return
557fi
558#/// Error si no se reciben 3 parámetros.
559[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
560
561#/// Sustituye nº de disco por su dispositivo.
562DISK=`ogDiskToDev $1` || return $?
563PART=`ogDiskToDev $1 $2` || return $?
564
565#/// Elección del tipo de partición.
566case "$3" in
567    EMPTY)      ID=0  ;;
568    EXTENDED)   ID=5  ;;
569    NTFS|EXFAT) ID=7  ;;
570    FAT32)      ID=b  ;;
571    HNTFS)      ID=17 ;;
572    HFAT32)     ID=1b ;;
573    LINUX-SWAP) ID=82 ;;
574    EXT[234]|REISERFS|REISER4|XFS|JFS)
575                ID=83 ;;
576    SOLARIS)    ID=bf ;;
577    CACHE)      ID=ca ;;
578    *)          ogRaiseError $OG_ERR_PARTITION "$TYPE"
579                return $? ;;
580esac
581echo -ne "t\n$2\n${ID}\nw\n" | fdisk $DISK 1>/dev/null 2>&1
582}
583
584
585function ogDeletePartitionsLabels () {
586#/**  @function ogDeletePartitionsLabels: @brief Elimina la informacion que tiene el kernel del cliente og sobre los labels de los sistemas de archivos
587#@param  No requiere
588#@return   Nada
589#@warning
590#@attention Requisitos:  comando interno linux rm
591#@note
592#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
593#*/
594rm /dev/disk/by-label/*    # */ COMENTARIO OBLIGATORIO PARA DOXYGEN
595}
596
Note: See TracBrowser for help on using the repository browser.