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