[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 | #/** |
---|
[42669ebf] | 335 | # ogGetPartitionActive int_ndisk |
---|
[a5df9b9] | 336 | #@brief Muestra que particion de un disco esta marcada como de activa. |
---|
[b9e1a8c] | 337 | #@param int_ndisk nº de orden del disco |
---|
| 338 | #@return int_npart Nº de partición activa |
---|
[a5df9b9] | 339 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 340 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 341 | #@note Requisitos: parted |
---|
[59f9ad2] | 342 | #@todo Queda definir formato para atributos (arranque, oculta, ...). |
---|
[985bef0] | 343 | #@version 0.9 - Primera version compatible con OpenGNSys. |
---|
[a5df9b9] | 344 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
[985bef0] | 345 | #@date 2009/09/17 |
---|
[1e7eaab] | 346 | #*/ ## |
---|
[42669ebf] | 347 | function ogGetPartitionActive () |
---|
| 348 | { |
---|
[59f9ad2] | 349 | # Variables locales |
---|
[a5df9b9] | 350 | local DISK |
---|
| 351 | |
---|
[1e7eaab] | 352 | # Si se solicita, mostrar ayuda. |
---|
[aae34f6] | 353 | if [ "$*" == "help" ]; then |
---|
| 354 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "$FUNCNAME 1 => 1" |
---|
| 355 | return |
---|
| 356 | fi |
---|
[1e7eaab] | 357 | # Error si no se recibe 1 parámetro. |
---|
[aae34f6] | 358 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[a5df9b9] | 359 | |
---|
[1e7eaab] | 360 | # Comprobar que el disco existe y listar su partición activa. |
---|
[a5df9b9] | 361 | DISK="$(ogDiskToDev $1)" || return $? |
---|
| 362 | parted $DISK print 2>/dev/null | awk '/boot/ {print $1}' |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | |
---|
| 366 | #/** |
---|
[42669ebf] | 367 | # ogGetPartitionId int_ndisk int_npartition |
---|
[9f57de01] | 368 | #@brief Devuelve el mnemonico con el tipo de sistema de archivos. |
---|
[42669ebf] | 369 | #@param int_ndisk nº de orden del disco |
---|
| 370 | #@param int_npartition nº de orden de la partición |
---|
[9f57de01] | 371 | #@return Identificador de tipo de partición. |
---|
[326cec3] | 372 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
[9f57de01] | 373 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
[a5df9b9] | 374 | #@note Requisitos: sfdisk |
---|
[9f57de01] | 375 | #@version 0.9 - Primera versión compatible con OpenGNSys. |
---|
| 376 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 377 | #@date 25/03/2009 |
---|
[1e7eaab] | 378 | #*/ ## |
---|
[42669ebf] | 379 | function ogGetPartitionId () |
---|
| 380 | { |
---|
[59f9ad2] | 381 | # Variables locales. |
---|
[a5df9b9] | 382 | local DISK PART |
---|
[2e15649] | 383 | |
---|
[1e7eaab] | 384 | # Si se solicita, mostrar ayuda. |
---|
[aae34f6] | 385 | if [ "$*" == "help" ]; then |
---|
| 386 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 387 | "$FUNCNAME 1 1 => 7" |
---|
| 388 | return |
---|
| 389 | fi |
---|
[1e7eaab] | 390 | # Error si no se reciben 2 parámetros. |
---|
[aae34f6] | 391 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[2e15649] | 392 | |
---|
[1e7eaab] | 393 | # Detectar id. de tipo de particion y codificar al mnemonico. |
---|
[2e15649] | 394 | DISK=$(ogDiskToDev $1) || return $? |
---|
| 395 | PART=$(ogDiskToDev $1 $2) || return $? |
---|
| 396 | echo $(sfdisk --id $DISK $2 2>/dev/null) |
---|
[9f29ba6] | 397 | } |
---|
| 398 | |
---|
[a5df9b9] | 399 | |
---|
| 400 | #/** |
---|
[42669ebf] | 401 | # ogGetPartitionSize int_ndisk int_npartition |
---|
[a5df9b9] | 402 | #@brief Muestra el tamano en KB de una particion determinada. |
---|
[42669ebf] | 403 | #@param int_ndisk nº de orden del disco |
---|
| 404 | #@param int_npartition nº de orden de la partición |
---|
| 405 | #@return int_partsize - Tamaño en KB de la partición. |
---|
[a5df9b9] | 406 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 407 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
| 408 | #@note Requisitos: sfdisk, awk |
---|
[985bef0] | 409 | #@version 0.1 - Integracion para Opengnsys - EAC: SizePartition () en ATA.lib |
---|
| 410 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
| 411 | #@date 2008/10/27 |
---|
| 412 | #@version 0.9 - Primera version para OpenGNSys |
---|
[a5df9b9] | 413 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 414 | #@date 2009/07/24 |
---|
[1e7eaab] | 415 | #*/ ## |
---|
[42669ebf] | 416 | function ogGetPartitionSize () |
---|
| 417 | { |
---|
[59f9ad2] | 418 | # Variables locales. |
---|
[739d358] | 419 | local DISK PART |
---|
[a5df9b9] | 420 | |
---|
[1e7eaab] | 421 | # Si se solicita, mostrar ayuda. |
---|
[aae34f6] | 422 | if [ "$*" == "help" ]; then |
---|
| 423 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 424 | "$FUNCNAME 1 1 => 10000000" |
---|
| 425 | return |
---|
| 426 | fi |
---|
[1e7eaab] | 427 | # Error si no se reciben 2 parámetros. |
---|
[aae34f6] | 428 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[a5df9b9] | 429 | |
---|
[1e7eaab] | 430 | # Obtener el tamaño de la partición. |
---|
[3543b3e] | 431 | DISK="$(ogDiskToDev $1)" || return $? |
---|
[a5df9b9] | 432 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
[3543b3e] | 433 | case "$(ogGetPartitionId $1 $2)" in |
---|
| 434 | 5|f) # Procesar detección de tamaño de partición Extendida. |
---|
[55ad138c] | 435 | sfdisk -l $DISK 2>/dev/null | \ |
---|
[3543b3e] | 436 | awk -v p=$PART '{if ($1==p) {sub (/\*/,""); print $5} }' |
---|
| 437 | ;; |
---|
| 438 | *) sfdisk -s $PART |
---|
| 439 | ;; |
---|
| 440 | esac |
---|
[a5df9b9] | 441 | } |
---|
| 442 | |
---|
| 443 | |
---|
[b094c59] | 444 | #/** |
---|
[73c8417] | 445 | # ogListPartitions int_ndisk |
---|
[a5df9b9] | 446 | #@brief Lista las particiones definidas en un disco. |
---|
[42669ebf] | 447 | #@param int_ndisk nº de orden del disco |
---|
| 448 | #@return str_parttype:int_partsize ... |
---|
[a5df9b9] | 449 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 450 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
| 451 | #@note Requisitos: \c parted \c awk |
---|
[73c8417] | 452 | #@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize |
---|
[59f9ad2] | 453 | #@attention Las tuplas de valores están separadas por espacios. |
---|
[a5df9b9] | 454 | #@version 0.9 - Primera versión para OpenGNSys |
---|
| 455 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 456 | #@date 2009/07/24 |
---|
[1e7eaab] | 457 | #*/ ## |
---|
[42669ebf] | 458 | function ogListPartitions () |
---|
| 459 | { |
---|
[59f9ad2] | 460 | # Variables locales. |
---|
[55ad138c] | 461 | local DISK PART NPARTS TYPE SIZE |
---|
[aae34f6] | 462 | |
---|
[42669ebf] | 463 | # Si se solicita, mostrar ayuda. |
---|
[1a7130a] | 464 | if [ "$*" == "help" ]; then |
---|
[aae34f6] | 465 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \ |
---|
[73c8417] | 466 | "$FUNCNAME 1 => NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000" |
---|
[aae34f6] | 467 | return |
---|
| 468 | fi |
---|
[42669ebf] | 469 | # Error si no se recibe 1 parámetro. |
---|
[5dbb046] | 470 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT "$FORMAT" || return $? |
---|
[a5df9b9] | 471 | |
---|
[42669ebf] | 472 | # Procesar la salida de \c parted . |
---|
[b094c59] | 473 | DISK="$(ogDiskToDev $1)" || return $? |
---|
[3543b3e] | 474 | NPARTS=$(ogGetPartitionsNumber $1) |
---|
| 475 | for (( PART = 1; PART <= NPARTS; PART++ )); do |
---|
[55ad138c] | 476 | TYPE=$(ogGetFsType $1 $PART 2>/dev/null) |
---|
[3543b3e] | 477 | if [ $? -eq 0 ]; then |
---|
[55ad138c] | 478 | SIZE=$(ogGetPartitionSize $1 $PART 2>/dev/null) |
---|
| 479 | echo -n "$TYPE:$SIZE " |
---|
[3543b3e] | 480 | else |
---|
| 481 | echo -n "EMPTY:0 " |
---|
| 482 | fi |
---|
[a5df9b9] | 483 | done |
---|
| 484 | echo |
---|
| 485 | } |
---|
| 486 | |
---|
[326cec3] | 487 | |
---|
| 488 | #/** |
---|
[55ad138c] | 489 | # ogListPrimaryPartitions int_ndisk |
---|
| 490 | #@brief Metafunción que lista las particiones primarias no vacías definidas en un disco. |
---|
[42669ebf] | 491 | #@param int_ndisk nº de orden del disco |
---|
[55ad138c] | 492 | #@see ogListPartitions |
---|
[1e7eaab] | 493 | #*/ ## |
---|
[42669ebf] | 494 | function ogListPrimaryPartitions () |
---|
| 495 | { |
---|
[55ad138c] | 496 | # Variables locales. |
---|
| 497 | local PARTS |
---|
| 498 | |
---|
| 499 | PARTS=$(ogListPartitions "$@") || return $? |
---|
| 500 | echo $PARTS | cut -sf1-4 -d" " | sed 's/\( EMPTY:0\)*$//' |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | |
---|
| 504 | #/** |
---|
| 505 | # ogListLogicalPartitions int_ndisk |
---|
| 506 | #@brief Metafunción que lista las particiones lógicas definidas en un disco. |
---|
[42669ebf] | 507 | #@param int_ndisk nº de orden del disco |
---|
[55ad138c] | 508 | #@see ogListPartitions |
---|
[1e7eaab] | 509 | #*/ ## |
---|
[b061ad0] | 510 | function ogListLogicalPartitions () |
---|
| 511 | { |
---|
[55ad138c] | 512 | # Variables locales. |
---|
| 513 | local PARTS |
---|
| 514 | |
---|
| 515 | PARTS=$(ogListPartitions "$@") || return $? |
---|
| 516 | echo $PARTS | cut -sf5- -d" " |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | |
---|
| 520 | #/** |
---|
[42669ebf] | 521 | # ogSetPartitionActive int_ndisk int_npartition |
---|
[89403cd] | 522 | #@brief Establece cual es la partición activa de un disco. |
---|
[42669ebf] | 523 | #@param int_ndisk nº de orden del disco |
---|
| 524 | #@param int_npartition nº de orden de la partición |
---|
| 525 | #@return (nada). |
---|
[326cec3] | 526 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 527 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo. |
---|
| 528 | #@note Requisitos: parted |
---|
[985bef0] | 529 | #@version 0.1 - Integracion para Opengnsys - EAC: SetPartitionActive() en ATA.lib |
---|
| 530 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
| 531 | #@date 2008/10/27 |
---|
| 532 | #@version 0.9 - Primera version compatible con OpenGNSys. |
---|
[326cec3] | 533 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 534 | #@date 2009/09/17 |
---|
[1e7eaab] | 535 | #*/ ## |
---|
[42669ebf] | 536 | function ogSetPartitionActive () |
---|
| 537 | { |
---|
[326cec3] | 538 | # Variables locales |
---|
| 539 | local DISK PART |
---|
| 540 | |
---|
[1e7eaab] | 541 | # Si se solicita, mostrar ayuda. |
---|
[326cec3] | 542 | if [ "$*" == "help" ]; then |
---|
| 543 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 544 | "$FUNCNAME 1 1" |
---|
| 545 | return |
---|
| 546 | fi |
---|
[1e7eaab] | 547 | # Error si no se reciben 2 parámetros. |
---|
[326cec3] | 548 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 549 | |
---|
[1e7eaab] | 550 | # Comprobar que el disco existe y activar la partición indicada. |
---|
[326cec3] | 551 | DISK="$(ogDiskToDev $1)" || return $? |
---|
| 552 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
| 553 | parted -s $DISK set $2 boot on 2>/dev/null |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | |
---|
[1553fc7] | 557 | #/** |
---|
[42669ebf] | 558 | # ogSetPartitionSize int_ndisk int_npartition int_size |
---|
[2ecd096] | 559 | #@brief Muestra el tamano en KB de una particion determinada. |
---|
[42669ebf] | 560 | #@param int_ndisk nº de orden del disco |
---|
| 561 | #@param int_npartition nº de orden de la partición |
---|
| 562 | #@param int_size tamaño de la partición (en KB) |
---|
[2ecd096] | 563 | #@return (nada) |
---|
| 564 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 565 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
| 566 | #@note Requisitos: sfdisk, awk |
---|
| 567 | #@todo Compruebar que el tamaño sea numérico positivo y evitar que pueda solaparse con la siguiente partición. |
---|
| 568 | #@version 0.9 - Primera versión para OpenGNSys |
---|
| 569 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 570 | #@date 2009/07/24 |
---|
[1e7eaab] | 571 | #*/ ## |
---|
[42669ebf] | 572 | function ogSetPartitionSize () |
---|
| 573 | { |
---|
[2ecd096] | 574 | # Variables locales. |
---|
| 575 | local DISK PART SIZE |
---|
| 576 | |
---|
[1e7eaab] | 577 | # Si se solicita, mostrar ayuda. |
---|
[2ecd096] | 578 | if [ "$*" == "help" ]; then |
---|
[311532f] | 579 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_size" \ |
---|
[2ecd096] | 580 | "$FUNCNAME 1 1 10000000" |
---|
| 581 | return |
---|
| 582 | fi |
---|
[1e7eaab] | 583 | # Error si no se reciben 3 parámetros. |
---|
[2ecd096] | 584 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 585 | |
---|
[1e7eaab] | 586 | # Obtener el tamaño de la partición. |
---|
[2ecd096] | 587 | DISK="$(ogDiskToDev $1)" || return $? |
---|
| 588 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
| 589 | # Convertir tamaño en KB a sectores de 512 B. |
---|
| 590 | SIZE=$[$3*2] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[1e7eaab] | 591 | # Usar \c sfdisk para redefinir el tamaño. |
---|
[1c04494] | 592 | sfdisk -f -uS -N$2 $DISK <<< ",$SIZE" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $? |
---|
[bf1840e9] | 593 | partprobe 2>/dev/null |
---|
[2ecd096] | 594 | } |
---|
| 595 | |
---|
| 596 | |
---|
| 597 | #/** |
---|
[6cdca0c] | 598 | # ogUpdatePartitionTable |
---|
[1553fc7] | 599 | #@brief Fuerza al kernel releer la tabla de particiones de los discos duros |
---|
[42669ebf] | 600 | #@param no requiere |
---|
[1553fc7] | 601 | #@return informacion propia de la herramienta |
---|
| 602 | #@note Requisitos: \c partprobe |
---|
| 603 | #@warning pendiente estructurar la funcion a opengnsys |
---|
[985bef0] | 604 | #@version 0.1 - Integracion para Opengnsys - EAC: UpdatePartitionTable() en ATA.lib |
---|
| 605 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 606 | #@date 27/10/2008 |
---|
[1553fc7] | 607 | #*/ |
---|
| 608 | |
---|
[42669ebf] | 609 | function ogUpdatePartitionTable () |
---|
| 610 | { |
---|
[c6087b9] | 611 | for i in `ogDiskToDev` |
---|
| 612 | do |
---|
| 613 | partprobe $i |
---|
| 614 | done |
---|
[1553fc7] | 615 | } |
---|
[1a7130a] | 616 | |
---|
| 617 | |
---|
| 618 | |
---|
[24f2399] | 619 | #/** @function ogGetPartitionsNumber: @brief detecta el numero de particiones del disco duro indicado. |
---|
[42669ebf] | 620 | #@param int_numdisk (indentificado EAC del disco) |
---|
[1a7130a] | 621 | #@return devuelve el numero paritiones del disco duro indicado |
---|
| 622 | #@warning Salidas de errores no determinada |
---|
| 623 | #@attention Requisitos: parted |
---|
| 624 | #@note Notas sin especificar |
---|
[985bef0] | 625 | #@version 0.1 - Integracion para Opengnsys - EAC: DetectNumberPartition () en ATA.lib |
---|
| 626 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 627 | #@date Date: 27/10/2008 |
---|
| 628 | #@version 1.0 - Uso de sfdisk Primera version para OpenGnSys |
---|
| 629 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 630 | #@date 2009/07/24 |
---|
[1a7130a] | 631 | #*/ |
---|
[985bef0] | 632 | function ogGetPartitionsNumber () { |
---|
[55ad138c] | 633 | #local disco totalpart |
---|
| 634 | #disco=`ogDiskToDev $1` |
---|
| 635 | #totalpart=`parted $disco print | egrep ^" [0123456789] " -c` |
---|
| 636 | #echo $totalpart |
---|
| 637 | local DISK |
---|
| 638 | #/// Contar el nº de veces que aparece el disco en su lista de particiones. |
---|
| 639 | DISK=$(ogDiskToDev $1) 2>/dev/null |
---|
| 640 | sfdisk -l $DISK 2>/dev/null | grep -c "^$DISK" |
---|
[1a7130a] | 641 | } |
---|
[6cdca0c] | 642 | |
---|
| 643 | |
---|
| 644 | #/** @function ogDiskToRelativeDev: @brief Traduce los ID de discos o particiones EAC a ID Linux relativos, es decir 1 1 => sda1 |
---|
| 645 | #@param Admite 1 parametro: $1 int_numdisk |
---|
| 646 | #@param Admite 2 parametro: $1 int_numdisk $2 int_partition |
---|
| 647 | #@return Para 1 parametros traduce Discos Duros: Devuelve la ruta relativa linux del disco duro indicado con nomenclatura EAC.........ejemplo: IdPartition 1 => sda |
---|
| 648 | #@return Para 2 parametros traduce Particiones: Devuelve la ruta relativa linux de la particion indicado con nomenclatura EAC........... ejemplo: IdPartition 2 1 => sdb1 |
---|
| 649 | #@warning No definidas |
---|
| 650 | #@attention |
---|
| 651 | #@note Notas sin especificar |
---|
[985bef0] | 652 | #@version 0.1 - Integracion para Opengnsys - EAC: IdPartition en ATA.lib |
---|
| 653 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 654 | #@date 27/10/2008 |
---|
[6cdca0c] | 655 | #*/ |
---|
[985bef0] | 656 | function ogDiskToRelativeDev () { |
---|
[6cdca0c] | 657 | if [ $# = 0 ] |
---|
| 658 | then |
---|
| 659 | Msg "Info: Traduce el identificador del dispositivo EAC a dispositivo linux \n" info |
---|
| 660 | Msg "Sintaxis1: IdPartition int_disk -----------------Ejemplo1: IdPartition 1 -> sda " example |
---|
| 661 | Msg "Sintaxis2: IdPartition int_disk int_partition --Ejemplo2: IdPartition 1 2 -> sda2 " example |
---|
| 662 | |
---|
| 663 | return |
---|
| 664 | fi |
---|
| 665 | #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. |
---|
| 666 | PART=$(ogDiskToDev|cut -f$1 -d' ')$2 |
---|
| 667 | echo $PART | cut -f3 -d \/ |
---|
| 668 | } |
---|
[26c729b] | 669 | |
---|
| 670 | #/** @function ogDeletePartitionTable: @brief Borra la tabla de particiones del disco. |
---|
| 671 | #@param $1 opcion A (identificador LINUX) str_ID_linux (/dev/sda) |
---|
| 672 | #@param $1 opcion B (Identifiador EAC) int_numdiskEAC(1) |
---|
| 673 | #@return la informacion propia del fdisk |
---|
| 674 | #@warning no definidos |
---|
| 675 | #@attention |
---|
| 676 | #@note |
---|
[985bef0] | 677 | #@version 0.1 - Integracion para Opengnsys - EAC: DeletePartitionTable () en ATA.lib |
---|
| 678 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 679 | #@date 27/10/2008 |
---|
[26c729b] | 680 | #*/ |
---|
[985bef0] | 681 | function ogDeletePartitionTable () { |
---|
[26c729b] | 682 | if [ $# = 0 ] |
---|
| 683 | then |
---|
| 684 | Msg "sintaxis1: ogDeletePartitionTable int_disk" red |
---|
| 685 | Msg "sintaxis2: ogDeletePartitionTable str_/dev/sdX" red |
---|
| 686 | return |
---|
| 687 | fi |
---|
| 688 | if [ -n "${1%/dev/*}" ] |
---|
| 689 | then |
---|
| 690 | dev=`DiskToDev $1` |
---|
| 691 | else |
---|
| 692 | dev=$1 |
---|
| 693 | fi |
---|
| 694 | echo -ne "o\nw" | fdisk $dev |
---|
| 695 | } |
---|
[0df4b9f7] | 696 | |
---|
| 697 | |
---|
| 698 | #/** @function ogSetPartitionId: @brief Cambia el identificador de la particion, pero no su sistema de archivos. |
---|
| 699 | #@param $1 int_numdiskEAC |
---|
| 700 | #@param $2 int_numpartitionEAC |
---|
| 701 | #@param $3 str_tipoPartition admite EXT2 EXT3 NTFS FAT32 SWAP CACHE |
---|
| 702 | #@return la propia del fdisk |
---|
| 703 | #@warning no controla los parametros, si se introducen mal o simplemente no se introducen no muestra mensaje |
---|
| 704 | #@warning Identifica por nombre del sistema de archivos no por número |
---|
| 705 | #@attention Requisitos: fdisk |
---|
| 706 | #@note |
---|
[985bef0] | 707 | #@version 0.1 - Integracion para Opengnsys - SetPartitionType() en ATA.lib |
---|
| 708 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 709 | #@date 27/10/2008 |
---|
[0df4b9f7] | 710 | #*/ |
---|
[985bef0] | 711 | function ogSetPartitionId() { |
---|
[be81649] | 712 | # Variables locales |
---|
| 713 | local DISK PART ID |
---|
| 714 | |
---|
[42669ebf] | 715 | # Si se solicita, mostrar ayuda. |
---|
[be81649] | 716 | if [ "$*" == "help" ]; then |
---|
[311532f] | 717 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_type" \ |
---|
| 718 | "$FUNCNAME 1 1 NTFS" |
---|
[be81649] | 719 | return |
---|
[0df4b9f7] | 720 | fi |
---|
[42669ebf] | 721 | # Error si no se reciben 3 parámetros. |
---|
[be81649] | 722 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 723 | |
---|
[42669ebf] | 724 | # Sustituye nº de disco por su dispositivo. |
---|
[be81649] | 725 | DISK=`ogDiskToDev $1` || return $? |
---|
| 726 | PART=`ogDiskToDev $1 $2` || return $? |
---|
| 727 | |
---|
[42669ebf] | 728 | # Elección del tipo de partición. |
---|
| 729 | ID=$(ogFsToId "$3") |
---|
[8971dc86] | 730 | [ -n "$ID" ] || ogRaiseError $OG_ERR_PARTITION "$3" || return $? |
---|
[42669ebf] | 731 | |
---|
[be81649] | 732 | echo -ne "t\n$2\n${ID}\nw\n" | fdisk $DISK 1>/dev/null 2>&1 |
---|
[0df4b9f7] | 733 | } |
---|
[cc6ad14] | 734 | |
---|
[be81649] | 735 | |
---|
[97da528] | 736 | #/** @function ogDeletePartitionsLabels: @brief Elimina la informacion que tiene el kernel del cliente og sobre los labels de los sistemas de archivos |
---|
[cc6ad14] | 737 | #@param No requiere |
---|
| 738 | #@return Nada |
---|
| 739 | #@warning |
---|
| 740 | #@attention Requisitos: comando interno linux rm |
---|
| 741 | #@note |
---|
[985bef0] | 742 | #@version 0.1 - Integracion para Opengnsys - EAC: DeletePartitionTable() en ATA.lib |
---|
| 743 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 744 | #@date 27/10/2008 |
---|
[cc6ad14] | 745 | #*/ |
---|
[985bef0] | 746 | function ogDeletePartitionsLabels () { |
---|
[cc6ad14] | 747 | rm /dev/disk/by-label/* # */ COMENTARIO OBLIGATORIO PARA DOXYGEN |
---|
| 748 | } |
---|
| 749 | |
---|