[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. |
---|
[0d6e7222] | 7 | #@version 1.1.0 |
---|
[9f29ba6] | 8 | #@warning License: GNU GPLv3+ |
---|
| 9 | #*/ |
---|
| 10 | |
---|
[5dbb046] | 11 | |
---|
[be48687] | 12 | # Función ficticia para lanzar parted con timeout, evitando cuelgues del programa. |
---|
| 13 | function parted () |
---|
| 14 | { |
---|
| 15 | timeout -k 5s -s KILL 3s $(which parted) "$@" |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | |
---|
[5dbb046] | 19 | #/** |
---|
[42669ebf] | 20 | # ogCreatePartitions int_ndisk str_parttype:int_partsize ... |
---|
[b094c59] | 21 | #@brief Define el conjunto de particiones de un disco. |
---|
[42669ebf] | 22 | #@param int_ndisk nº de orden del disco |
---|
| 23 | #@param str_parttype mnemónico del tipo de partición |
---|
| 24 | #@param int_partsize tamaño de la partición (en KB) |
---|
[73c8417] | 25 | #@return (nada, por determinar) |
---|
[73488c9] | 26 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 27 | #@exception OG_ERR_NOTFOUND disco o partición no detectado (no es un dispositivo). |
---|
| 28 | #@exception OG_ERR_PARTITION error en partición o en tabla de particiones. |
---|
[73c8417] | 29 | #@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize |
---|
| 30 | #@attention Pueden definirse particiones vacías de tipo \c EMPTY |
---|
[16f7627] | 31 | #@attention No puede definirse partición de cache y no se modifica si existe. |
---|
[73c8417] | 32 | #@note Requisitos: sfdisk, parted, partprobe, awk |
---|
| 33 | #@todo Definir atributos (arranque, oculta) y tamaños en MB, GB, etc. |
---|
[afc1e74] | 34 | #@version 0.9 - Primera versión para OpenGnSys |
---|
[73c8417] | 35 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 36 | #@date 2009/09/09 |
---|
[bc7dfe7] | 37 | #@version 0.9.1 - Corrección del redondeo del tamaño del disco. |
---|
[4b45aff] | 38 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 39 | #@date 2010/03/09 |
---|
[73488c9] | 40 | #@version 1.0.4 - Llamada a función específica para tablas GPT. |
---|
| 41 | #@author Universidad de Huelva |
---|
| 42 | #@date 2012/03/30 |
---|
[1e7eaab] | 43 | #*/ ## |
---|
[42669ebf] | 44 | function ogCreatePartitions () |
---|
| 45 | { |
---|
[73c8417] | 46 | # Variables locales. |
---|
[0cea822] | 47 | local ND DISK PTTYPE PART SECTORS START SIZE TYPE CACHEPART CACHESIZE EXTSTART EXTSIZE tmpsfdisk |
---|
[1e7eaab] | 48 | # Si se solicita, mostrar ayuda. |
---|
[1a7130a] | 49 | if [ "$*" == "help" ]; then |
---|
[73c8417] | 50 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_parttype:int_partsize ..." \ |
---|
| 51 | "$FUNCNAME 1 NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000" |
---|
| 52 | return |
---|
| 53 | fi |
---|
[a73649d] | 54 | # Error si no se reciben al menos 2 parámetros. |
---|
[55ad138c] | 55 | [ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[73c8417] | 56 | |
---|
[4b45aff] | 57 | # Nº total de sectores, para evitar desbordamiento (evitar redondeo). |
---|
[6d3f526] | 58 | ND="$1" |
---|
| 59 | DISK=$(ogDiskToDev "$ND") || return $? |
---|
[73488c9] | 60 | PTTYPE=$(ogGetPartitionTableType $1) |
---|
[a06ac2d] | 61 | PTTYPE=${PTTYPE:-"MSDOS"} # Por defecto para discos vacíos. |
---|
[73488c9] | 62 | case "$PTTYPE" in |
---|
| 63 | GPT) ogCreateGptPartitions "$@" |
---|
| 64 | return $? ;; |
---|
[0cea822] | 65 | MSDOS) ;; |
---|
[73488c9] | 66 | *) ogRaiseError $OG_ERR_PARTITION "$PTTYPE" |
---|
| 67 | return $? ;; |
---|
| 68 | esac |
---|
[0cea822] | 69 | SECTORS=$(ogGetLastSector $1) |
---|
[16f7627] | 70 | # Se recalcula el nº de sectores del disco 1, si existe partición de caché. |
---|
[d7c35ad] | 71 | CACHEPART=$(ogFindCache 2>/dev/null) |
---|
[6d3f526] | 72 | [ "$ND" = "${CACHEPART% *}" ] && CACHESIZE=$(ogGetCacheSize 2>/dev/null | awk '{print $0*2}') |
---|
[d7c35ad] | 73 | [ -n "$CACHESIZE" ] && SECTORS=$[SECTORS-CACHESIZE] |
---|
[16f7627] | 74 | # Sector de inicio (la partición 1 empieza en el sector 63). |
---|
[73c8417] | 75 | START=63 |
---|
| 76 | PART=1 |
---|
| 77 | |
---|
[b094c59] | 78 | # Fichero temporal de entrada para "sfdisk" |
---|
[73c8417] | 79 | tmpsfdisk=/tmp/sfdisk$$ |
---|
| 80 | trap "rm -f $tmpsfdisk" 1 2 3 9 15 |
---|
| 81 | |
---|
| 82 | echo "unit: sectors" >$tmpsfdisk |
---|
| 83 | echo >>$tmpsfdisk |
---|
| 84 | |
---|
[42669ebf] | 85 | # Generar fichero de entrada para "sfdisk" con las particiones. |
---|
[16f7627] | 86 | shift |
---|
[73c8417] | 87 | while [ $# -gt 0 ]; do |
---|
[16f7627] | 88 | # Conservar los datos de la partición de caché. |
---|
[6d3f526] | 89 | if [ "$ND $PART" == "$CACHEPART" -a -n "$CACHESIZE" ]; then |
---|
[16f7627] | 90 | echo "$DISK$PART : start=$[SECTORS+1], size=$CACHESIZE, Id=ca" >>$tmpsfdisk |
---|
| 91 | PART=$[PART+1] |
---|
| 92 | fi |
---|
[42669ebf] | 93 | # Leer formato de cada parámetro - Tipo:Tamaño |
---|
[73c8417] | 94 | TYPE="${1%%:*}" |
---|
| 95 | SIZE="${1#*:}" |
---|
[42e31fd] | 96 | # Obtener identificador de tipo de partición válido. |
---|
[5af5d5f] | 97 | ID=$(ogTypeToId "$TYPE" MSDOS) |
---|
[42e31fd] | 98 | [ "$TYPE" != "CACHE" -a -n "$ID" ] || ogRaiseError $OG_ERR_PARTITION "$TYPE" || return $? |
---|
| 99 | # Comprobar tamaño numérico y convertir en sectores de 512 B. |
---|
| 100 | [[ "$SIZE" == *([0-9]) ]] || ogRaiseError $OG_ERR_FORMAT "$SIZE" || return $? |
---|
| 101 | SIZE=$[SIZE*2] |
---|
[42669ebf] | 102 | # Comprobar si la partición es extendida. |
---|
| 103 | if [ $ID = 5 ]; then |
---|
[6bde19d] | 104 | [ $PART -le 4 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[42669ebf] | 105 | EXTSTART=$START |
---|
| 106 | EXTSIZE=$SIZE |
---|
| 107 | fi |
---|
[1e7eaab] | 108 | # Incluir particiones lógicas dentro de la partición extendida. |
---|
[73c8417] | 109 | if [ $PART = 5 ]; then |
---|
[6bde19d] | 110 | [ -n "$EXTSTART" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[73c8417] | 111 | START=$EXTSTART |
---|
| 112 | SECTORS=$[EXTSTART+EXTSIZE] |
---|
| 113 | fi |
---|
[1e7eaab] | 114 | # Generar datos para la partición. |
---|
[73c8417] | 115 | echo "$DISK$PART : start=$START, size=$SIZE, Id=$ID" >>$tmpsfdisk |
---|
[42669ebf] | 116 | # Error si se supera el nº total de sectores. |
---|
[73c8417] | 117 | START=$[START+SIZE] |
---|
[16f7627] | 118 | [ $START -le $SECTORS ] || ogRaiseError $OG_ERR_FORMAT "$[START/2] > $[SECTORS/2]" || return $? |
---|
[73c8417] | 119 | PART=$[PART+1] |
---|
| 120 | shift |
---|
| 121 | done |
---|
[16f7627] | 122 | # Si no se indican las 4 particiones primarias, definirlas como vacías, conservando la partición de caché. |
---|
[73c8417] | 123 | while [ $PART -le 4 ]; do |
---|
[6d3f526] | 124 | if [ "$ND $PART" == "$CACHEPART" -a -n "$CACHESIZE" ]; then |
---|
[16f7627] | 125 | echo "$DISK$PART : start=$[SECTORS+1], size=$CACHESIZE, Id=ca" >>$tmpsfdisk |
---|
| 126 | else |
---|
| 127 | echo "$DISK$PART : start=0, size=0, Id=0" >>$tmpsfdisk |
---|
| 128 | fi |
---|
[73c8417] | 129 | PART=$[PART+1] |
---|
| 130 | done |
---|
[b094c59] | 131 | # Si se define partición extendida sin lógicas, crear particion 5 vacía. |
---|
[73c8417] | 132 | if [ $PART = 5 -a -n "$EXTSTART" ]; then |
---|
| 133 | echo "${DISK}5 : start=$EXTSTART, size=$EXTSIZE, Id=0" >>$tmpsfdisk |
---|
| 134 | fi |
---|
| 135 | |
---|
[7510561] | 136 | # Desmontar los sistemas de archivos del disco antes de realizar las operaciones. |
---|
[6d3f526] | 137 | ogUnmountAll $ND 2>/dev/null |
---|
| 138 | [ -n "$CACHESIZE" ] && ogUnmountCache 2>/dev/null |
---|
[7510561] | 139 | |
---|
[73c8417] | 140 | # Si la tabla de particiones no es valida, volver a generarla. |
---|
[0cea822] | 141 | ogCreatePartitionTable $ND |
---|
[1e7eaab] | 142 | # Definir particiones y notificar al kernel. |
---|
[c6087b9] | 143 | sfdisk -f $DISK < $tmpsfdisk 2>/dev/null && partprobe $DISK |
---|
[73c8417] | 144 | rm -f $tmpsfdisk |
---|
[6d3f526] | 145 | [ -n "$CACHESIZE" ] && ogMountCache 2>/dev/null |
---|
[73c8417] | 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | #/** |
---|
[73488c9] | 150 | # ogCreateGptPartitions int_ndisk str_parttype:int_partsize ... |
---|
| 151 | #@brief Define el conjunto de particiones de un disco GPT |
---|
| 152 | #@param int_ndisk nº de orden del disco |
---|
| 153 | #@param str_parttype mnemónico del tipo de partición |
---|
| 154 | #@param int_partsize tamaño de la partición (en KB) |
---|
| 155 | #@return (nada, por determinar) |
---|
| 156 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 157 | #@exception OG_ERR_NOTFOUND disco o partición no detectado (no es un dispositivo). |
---|
| 158 | #@exception OG_ERR_PARTITION error en partición o en tabla de particiones. |
---|
| 159 | #@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize |
---|
| 160 | #@attention Pueden definirse particiones vacías de tipo \c EMPTY |
---|
| 161 | #@attention No puede definirse partición de caché y no se modifica si existe. |
---|
| 162 | #@note Requisitos: sfdisk, parted, partprobe, awk |
---|
| 163 | #@todo Definir atributos (arranque, oculta) y tamaños en MB, GB, etc. |
---|
| 164 | #@version 1.0.4 - Primera versión para OpenGnSys |
---|
| 165 | #@author Universidad de Huelva |
---|
| 166 | #@date 2012/03/30 |
---|
| 167 | #*/ ## |
---|
| 168 | function ogCreateGptPartitions () |
---|
| 169 | { |
---|
| 170 | # Variables locales. |
---|
[0cea822] | 171 | local ND DISK PART SECTORS ALIGN START SIZE TYPE CACHEPART CACHESIZE DELOPTIONS OPTIONS |
---|
[73488c9] | 172 | # Si se solicita, mostrar ayuda. |
---|
| 173 | if [ "$*" == "help" ]; then |
---|
| 174 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_parttype:int_partsize ..." \ |
---|
| 175 | "$FUNCNAME 1 NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000" |
---|
| 176 | return |
---|
| 177 | fi |
---|
| 178 | # Error si no se reciben menos de 2 parámetros. |
---|
| 179 | [ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 180 | |
---|
| 181 | # Nº total de sectores, para evitar desbordamiento (evitar redondeo). |
---|
| 182 | ND="$1" |
---|
| 183 | DISK=$(ogDiskToDev "$ND") || return $? |
---|
| 184 | # Se calcula el ultimo sector del disco (total de sectores usables) |
---|
[0cea822] | 185 | SECTORS=$(ogGetLastSector $1) |
---|
[e3f557f] | 186 | # Se recalcula el nº de sectores del disco si existe partición de caché. |
---|
| 187 | CACHEPART=$(ogFindCache 2>/dev/null) |
---|
[0cea822] | 188 | [ "$ND" = "${CACHEPART% *}" ] && CACHESIZE=$(ogGetCacheSize 2>/dev/null | awk '{print $0*2}') |
---|
| 189 | [ -n "$CACHESIZE" ] && SECTORS=$[SECTORS-CACHESIZE] |
---|
| 190 | # Si el disco es GPT empieza en el sector 2048 por defecto, pero podria cambiarse |
---|
[499bf46] | 191 | ALIGN=$(sgdisk -D $DISK 2>/dev/null) |
---|
[0cea822] | 192 | START=$ALIGN |
---|
| 193 | PART=1 |
---|
[73488c9] | 194 | |
---|
[0cea822] | 195 | # Leer parámetros con definición de particionado. |
---|
| 196 | shift |
---|
| 197 | |
---|
| 198 | while [ $# -gt 0 ]; do |
---|
| 199 | # Si PART es la cache, nos la saltamos y seguimos con el siguiente numero para conservar los datos de la partición de caché. |
---|
| 200 | if [ "$ND $PART" == "$CACHEPART" -a -n "$CACHESIZE" ]; then |
---|
| 201 | PART=$[PART+1] |
---|
| 202 | fi |
---|
| 203 | # Leer formato de cada parámetro - Tipo:Tamaño |
---|
| 204 | TYPE="${1%%:*}" |
---|
| 205 | SIZE="${1#*:}" |
---|
| 206 | # Error si la partición es extendida (no válida en discos GPT). |
---|
[499bf46] | 207 | if [ "$TYPE" == "EXTENDED" ]; then |
---|
| 208 | ogRaiseError $OG_ERR_PARTITION "EXTENDED" |
---|
| 209 | return $? |
---|
| 210 | fi |
---|
[0cea822] | 211 | # Comprobar si existe la particion actual, capturamos su tamaño para ver si cambio o no |
---|
[499bf46] | 212 | PARTSIZE=$(ogGetPartitionSize $ND $PART 2>/dev/null) |
---|
[0cea822] | 213 | # En sgdisk no se pueden redimensionar las particiones, es necesario borrarlas y volver a crealas |
---|
| 214 | [ $PARTSIZE ] && DELOPTIONS="$DELOPTIONS -d$PART" |
---|
| 215 | # Creamos la particion |
---|
| 216 | # Obtener identificador de tipo de partición válido. |
---|
[5af5d5f] | 217 | ID=$(ogTypeToId "$TYPE" GPT) |
---|
[0cea822] | 218 | [ "$TYPE" != "CACHE" -a -n "$ID" ] || ogRaiseError $OG_ERR_PARTITION "$TYPE" || return $? |
---|
| 219 | # Comprobar tamaño numérico y convertir en sectores de 512 B. |
---|
| 220 | [[ "$SIZE" == *([0-9]) ]] || ogRaiseError $OG_ERR_FORMAT "$SIZE" || return $? |
---|
| 221 | SIZE=$[SIZE*2] |
---|
| 222 | # SIZE debe ser múltiplo de ALIGN, si no gdisk lo mueve automáticamente. |
---|
| 223 | DIV=$[$SIZE/$ALIGN] |
---|
| 224 | SIZE=$[$DIV*$ALIGN] |
---|
| 225 | # En el caso de que la partición sea EMPTY no se crea nada |
---|
| 226 | if [ "$TYPE" != "EMPTY" ]; then |
---|
| 227 | OPTIONS="$OPTIONS -n$PART:$START:+$SIZE -t$PART:$ID " |
---|
| 228 | fi |
---|
| 229 | START=$[START+SIZE] |
---|
| 230 | # Error si se supera el nº total de sectores. |
---|
| 231 | [ $START -le $SECTORS ] || ogRaiseError $OG_ERR_FORMAT "$[START/2] > $[SECTORS/2]" || return $? |
---|
| 232 | PART=$[PART+1] |
---|
| 233 | shift |
---|
| 234 | done |
---|
| 235 | |
---|
| 236 | # Desmontar los sistemas de archivos del disco antes de realizar las operaciones. |
---|
| 237 | ogUnmountAll $ND 2>/dev/null |
---|
| 238 | [ -n "$CACHESIZE" ] && ogUnmountCache 2>/dev/null |
---|
| 239 | |
---|
| 240 | # Si la tabla de particiones no es valida, volver a generarla. |
---|
| 241 | ogCreatePartitionTable $ND |
---|
| 242 | # Definir particiones y notificar al kernel. |
---|
| 243 | # Borramos primero las particiones y luego creamos las nuevas |
---|
[499bf46] | 244 | sgdisk $DELOPTIONS $OPTIONS $DISK 2>/dev/null && partprobe $DISK |
---|
[0cea822] | 245 | [ -n "$CACHESIZE" ] && ogMountCache 2>/dev/null |
---|
[73488c9] | 246 | } |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | #/** |
---|
[942dfd7] | 250 | # ogCreatePartitionTable int_ndisk [str_tabletype] |
---|
[f2c8049] | 251 | #@brief Genera una tabla de particiones en caso de que no sea valida, si es valida no hace nada. |
---|
[942dfd7] | 252 | #@param int_ndisk nº de orden del disco |
---|
| 253 | #@param str_tabletype tipo de tabla de particiones (opcional) |
---|
| 254 | #@return (por determinar) |
---|
| 255 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
[f2c8049] | 256 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
[942dfd7] | 257 | #@note tabletype: { MSDOS, GPT } |
---|
| 258 | #@note Requisitos: sfdisk, sgdisk |
---|
[afc1e74] | 259 | #@version 1.0.4 - Primera versión compatible con OpenGnSys. |
---|
[942dfd7] | 260 | #@author Universidad de Huelva |
---|
| 261 | #@date 2012/03/06 |
---|
| 262 | #*/ ## |
---|
[6e390b1] | 263 | function ogCreatePartitionTable () |
---|
[942dfd7] | 264 | { |
---|
| 265 | # Variables locales. |
---|
| 266 | local DISK PTTYPE CREATE CREATEPTT |
---|
| 267 | |
---|
| 268 | # Si se solicita, mostrar ayuda. |
---|
| 269 | if [ "$*" == "help" ]; then |
---|
| 270 | ogHelp "$FUNCNAME int_ndisk [str_partype]" \ |
---|
| 271 | "$FUNCNAME 1 GPT" "$FUNCNAME 1" |
---|
| 272 | return |
---|
| 273 | fi |
---|
| 274 | # Error si no se reciben 1 o 2 parámetros. |
---|
| 275 | case $# in |
---|
[f2c8049] | 276 | 1) CREATEPTT="" ;; |
---|
| 277 | 2) CREATEPTT="$2" ;; |
---|
| 278 | *) ogRaiseError $OG_ERR_FORMAT |
---|
| 279 | return $? ;; |
---|
[942dfd7] | 280 | esac |
---|
| 281 | |
---|
| 282 | # Capturamos el tipo de tabla de particiones actual |
---|
| 283 | DISK=$(ogDiskToDev $1) || return $? |
---|
| 284 | PTTYPE=$(ogGetPartitionTableType $1) |
---|
[a06ac2d] | 285 | PTTYPE=${PTTYPE:-"MSDOS"} # Por defecto para discos vacíos. |
---|
[942dfd7] | 286 | CREATEPTT=${CREATEPTT:-"$PTTYPE"} |
---|
| 287 | |
---|
[a06ac2d] | 288 | # Si la tabla actual y la que se indica son iguales, se comprueba si hay que regenerarla. |
---|
[942dfd7] | 289 | if [ "$CREATEPTT" == "$PTTYPE" ]; then |
---|
| 290 | case "$PTTYPE" in |
---|
| 291 | GPT) [ ! $(sgdisk -p $DISK 2>&1 >/dev/null) ] || CREATE="GPT" ;; |
---|
| 292 | MSDOS) [ $(parted -s $DISK print >/dev/null) ] || CREATE="MSDOS" ;; |
---|
| 293 | esac |
---|
| 294 | else |
---|
| 295 | CREATE="$CREATEPTT" |
---|
| 296 | fi |
---|
| 297 | # Dependiendo del valor de CREATE, creamos la tabla de particiones en cada caso. |
---|
| 298 | case "$CREATE" in |
---|
| 299 | GPT) |
---|
| 300 | # Si es necesario crear una tabla GPT pero la actual es MSDOS |
---|
| 301 | if [ "$PTTYPE" == "MSDOS" ]; then |
---|
| 302 | sgdisk -g $DISK |
---|
| 303 | else |
---|
| 304 | echo -e "2\nw\nY\n" | gdisk $DISK |
---|
| 305 | fi |
---|
| 306 | partprobe $DISK 2>/dev/null |
---|
| 307 | ;; |
---|
| 308 | MSDOS) |
---|
| 309 | # Si es necesario crear una tabla MSDOS pero la actual es GPT |
---|
| 310 | if [ "$PTTYPE" == "GPT" ]; then |
---|
[2ba98be] | 311 | sgdisk -Z $DISK |
---|
[942dfd7] | 312 | fi |
---|
[2ba98be] | 313 | fdisk $DISK <<< "w" |
---|
[942dfd7] | 314 | partprobe $DISK 2>/dev/null |
---|
| 315 | ;; |
---|
| 316 | esac |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | |
---|
| 320 | #/** |
---|
[43892687] | 321 | # ogDeletePartitionTable ndisk |
---|
| 322 | #@brief Borra la tabla de particiones del disco. |
---|
| 323 | #@param int_ndisk nº de orden del disco |
---|
| 324 | #@return la informacion propia del fdisk |
---|
| 325 | #@version 0.1 - Integracion para OpenGnSys |
---|
| 326 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
[942dfd7] | 327 | #@date 2008/10/27 |
---|
[43892687] | 328 | #@version 1.0.4 - Adaptado para su uso con discos GPT |
---|
| 329 | #@author Universidad de Huelva |
---|
| 330 | #@date 2012/03/13 |
---|
| 331 | #*/ ## |
---|
| 332 | function ogDeletePartitionTable () |
---|
| 333 | { |
---|
| 334 | # Variables locales. |
---|
| 335 | local DISK |
---|
| 336 | |
---|
| 337 | # Si se solicita, mostrar ayuda. |
---|
| 338 | if [ "$*" == "help" ]; then |
---|
| 339 | ogHelp "$FUNCNAME int_ndisk" "$FUNCNAME 1" |
---|
| 340 | return |
---|
| 341 | fi |
---|
| 342 | # Error si no se reciben 1 parámetros. |
---|
| 343 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 344 | |
---|
| 345 | # Obteniendo Identificador linux del disco. |
---|
| 346 | DISK=$(ogDiskToDev $1) || return $? |
---|
| 347 | # Crear una tabla de particiones vacía. |
---|
| 348 | case "$(ogGetPartitionTableType $1)" in |
---|
| 349 | GPT) sgdisk -o $DISK ;; |
---|
| 350 | MSDOS) echo -ne "o\nw" | fdisk $DISK ;; |
---|
| 351 | esac |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | |
---|
| 355 | #/** |
---|
[95e9664] | 356 | # ogDevToDisk path_device | LABEL="str_label" | UUID="str_uuid" |
---|
| 357 | #@brief Devuelve el nº de orden de dicso (y partición) correspondiente al nombre de fichero de dispositivo o a la etiqueta o UUID del sistema de archivos asociado. |
---|
| 358 | #@param path_device Camino del fichero de dispositivo. |
---|
| 359 | #@param str_label etiqueta de sistema de archivos. |
---|
| 360 | #@param str_uuid UUID de sistema de archivos. |
---|
[42669ebf] | 361 | #@return int_ndisk (para dispositivo de disco) |
---|
| 362 | #@return int_ndisk int_npartition (para dispositivo de partición). |
---|
[5dbb046] | 363 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 364 | #@exception OG_ERR_NOTFOUND Dispositivo no detectado. |
---|
[95e9664] | 365 | #@note Solo se acepta en cada llamada 1 de los 3 tipos de parámetros. |
---|
[985bef0] | 366 | #@version 0.1 - Integracion para Opengnsys - EAC: DiskEAC() en ATA.lib |
---|
| 367 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
| 368 | #@date 2008/10/27 |
---|
[afc1e74] | 369 | #@version 0.9 - Primera version para OpenGnSys |
---|
[5dbb046] | 370 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
[985bef0] | 371 | #@date 2009/07/20 |
---|
[95e9664] | 372 | #@version 1.0.6 - Soporta parámetro con UIID o etiqueta. |
---|
| 373 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 374 | #@date 2014/07/13 |
---|
[1e7eaab] | 375 | #*/ ## |
---|
[42669ebf] | 376 | function ogDevToDisk () |
---|
| 377 | { |
---|
[73c8417] | 378 | # Variables locales. |
---|
[95e9664] | 379 | local DEV d n |
---|
[1e7eaab] | 380 | # Si se solicita, mostrar ayuda. |
---|
[1a7130a] | 381 | if [ "$*" == "help" ]; then |
---|
[95e9664] | 382 | ogHelp "$FUNCNAME" "$FUNCNAME path_device | LABEL=str_label | UUID=str_uuid" \ |
---|
| 383 | "$FUNCNAME /dev/sda => 1" \ |
---|
| 384 | "$FUNCNAME /dev/sda1 => 1 1" \ |
---|
| 385 | "$FUNCNAME LABEL=CACHE => 1 4" |
---|
[5dbb046] | 386 | return |
---|
| 387 | fi |
---|
| 388 | |
---|
[1e7eaab] | 389 | # Error si no se recibe 1 parámetro. |
---|
[5dbb046] | 390 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[95e9664] | 391 | |
---|
| 392 | # Obtener dispositivo a partir de camino, etiqueta o UUID. |
---|
| 393 | DEV="$1" |
---|
| 394 | case "$DEV" in |
---|
| 395 | LABEL=*) DEV=$(blkid -L "${1#*=}") ;; |
---|
| 396 | UUID=*) DEV=$(blkid -U "${1#*=}") ;; |
---|
| 397 | esac |
---|
| 398 | |
---|
[42669ebf] | 399 | # Error si no es fichero de bloques. |
---|
[95e9664] | 400 | [ -b "$DEV" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
[5dbb046] | 401 | |
---|
[1e7eaab] | 402 | # Procesa todos los discos para devolver su nº de orden y de partición. |
---|
[5dbb046] | 403 | n=1 |
---|
| 404 | for d in $(ogDiskToDev); do |
---|
[95e9664] | 405 | [ -n "$(echo $DEV | grep $d)" ] && echo "$n ${DEV#$d}" && return |
---|
[5dbb046] | 406 | n=$[n+1] |
---|
| 407 | done |
---|
| 408 | ogRaiseError $OG_ERR_NOTFOUND "$1" |
---|
| 409 | return $OG_ERR_NOTFOUND |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | |
---|
[9f29ba6] | 413 | #/** |
---|
[42669ebf] | 414 | # ogDiskToDev [int_ndisk [int_npartition]] |
---|
[9f57de01] | 415 | #@brief Devuelve la equivalencia entre el nº de orden del dispositivo (dicso o partición) y el nombre de fichero de dispositivo correspondiente. |
---|
[42669ebf] | 416 | #@param int_ndisk nº de orden del disco |
---|
| 417 | #@param int_npartition nº de orden de la partición |
---|
[9f57de01] | 418 | #@return Para 0 parametros: Devuelve los nombres de ficheros de los dispositivos sata/ata/usb linux encontrados. |
---|
| 419 | #@return Para 1 parametros: Devuelve la ruta del disco duro indicado. |
---|
| 420 | #@return Para 2 parametros: Devuelve la ruta de la particion indicada. |
---|
| 421 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 422 | #@exception OG_ERR_NOTFOUND Dispositivo no detectado. |
---|
[2717297] | 423 | #@note Requisitos: awk, lvm |
---|
[985bef0] | 424 | #@version 0.1 - Integracion para Opengnsys - EAC: Disk() en ATA.lib; HIDRA: DetectarDiscos.sh |
---|
| 425 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 426 | #@Date 2008/06/19 |
---|
| 427 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
| 428 | #@date 2008/10/27 |
---|
[afc1e74] | 429 | #@version 0.9 - Primera version para OpenGnSys |
---|
[9f57de01] | 430 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 431 | #@date 2009-07-20 |
---|
[19b1a2f] | 432 | #@version 1.0.5 - Comprobación correcta de parámetros para soportar valores > 9. |
---|
| 433 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 434 | #@date 2013-05-07 |
---|
[0d6e7222] | 435 | #@version 1.0.6 - Soportar RAID hardware y Multipath. |
---|
[fd1846f] | 436 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 437 | #@date 2014-09-23 |
---|
[0d6e7222] | 438 | #@version 1.1.0 - Soportar pool de volúmenes ZFS. |
---|
| 439 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 440 | #@date 2014-11-14 |
---|
[1e7eaab] | 441 | #*/ ## |
---|
[42669ebf] | 442 | function ogDiskToDev () |
---|
| 443 | { |
---|
[59f9ad2] | 444 | # Variables locales |
---|
[0d6e7222] | 445 | local ALLDISKS MPATH VOLGROUPS ZFSVOLS DISK PART ZPOOL i |
---|
[9f29ba6] | 446 | |
---|
[1e7eaab] | 447 | # Si se solicita, mostrar ayuda. |
---|
[1a7130a] | 448 | if [ "$*" == "help" ]; then |
---|
[aae34f6] | 449 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk [int_npartition]" \ |
---|
| 450 | "$FUNCNAME => /dev/sda /dev/sdb" \ |
---|
| 451 | "$FUNCNAME 1 => /dev/sda" \ |
---|
| 452 | "$FUNCNAME 1 1 => /dev/sda1" |
---|
| 453 | return |
---|
| 454 | fi |
---|
| 455 | |
---|
[fd1846f] | 456 | # Listar dispositivos de discos duros. |
---|
| 457 | ALLDISKS=$(lsblk -n | awk '$6~/^disk$/ {gsub(/!/,"/"); printf "/dev/%s ",$1}') |
---|
| 458 | |
---|
| 459 | # Listar volúmenes lógicos. |
---|
[13ccdf5] | 460 | VOLGROUPS=$(vgs -a --noheadings 2>/dev/null | awk '{printf "/dev/%s ",$1}') |
---|
[2717297] | 461 | ALLDISKS="$ALLDISKS $VOLGROUPS" |
---|
[9f29ba6] | 462 | |
---|
[fd1846f] | 463 | # Detectar caminos múltiples (ignorar mensaje si no está configurado Multipath). |
---|
| 464 | if MPATH=$(multipath -l -v 1 2>/dev/null | awk '{printf "/dev/mapper/%s ",$1}'; exit ${PIPESTATUS[0]}); then |
---|
| 465 | # Quitar de la lista los discos que forman parte de Multipath. |
---|
| 466 | for i in $(multipath -ll | awk '$6=="ready" {printf "/dev/%s ",$3}'); do |
---|
| 467 | ALLDISKS="${ALLDISKS//$i/}" |
---|
| 468 | done |
---|
| 469 | # Añadir caminos múltiples a los discos detectados. |
---|
| 470 | ALLDISKS="$ALLDISKS $MPATH" |
---|
| 471 | fi |
---|
| 472 | |
---|
[0d6e7222] | 473 | # Detectar volúmenes ZFS. |
---|
| 474 | ZFSVOLS=$(blkid | awk -F: '/zfs/ {print $1}') |
---|
| 475 | ALLDISKS="$ALLDISKS $ZFSVOLS" |
---|
| 476 | |
---|
[1e7eaab] | 477 | # Mostrar salidas segun el número de parametros. |
---|
[9f29ba6] | 478 | case $# in |
---|
[2717297] | 479 | 0) # Muestra todos los discos, separados por espacios. |
---|
| 480 | echo $ALLDISKS |
---|
| 481 | ;; |
---|
[19b1a2f] | 482 | 1) # Error si el parámetro no es un número positivo. |
---|
| 483 | [[ "$1" =~ ^[1-9][0-9]*$ ]] || ogRaiseError $OG_ERR_FORMAT "$1" || return $? |
---|
[2717297] | 484 | DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}') |
---|
| 485 | # Error si el fichero no existe. |
---|
| 486 | [ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
| 487 | echo "$DISK" |
---|
| 488 | ;; |
---|
[19b1a2f] | 489 | 2) # Error si los 2 parámetros no son números positivos. |
---|
| 490 | [[ "$1" =~ ^[1-9][0-9]*$ ]] && [[ "$2" =~ ^[1-9][0-9]*$ ]] || ogRaiseError $OG_ERR_FORMAT "$1 $2" || return $? |
---|
[2717297] | 491 | DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}') |
---|
| 492 | [ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
| 493 | PART="$DISK$2" |
---|
[1e7eaab] | 494 | # Comprobar si es partición. |
---|
[2717297] | 495 | if [ -b "$PART" ]; then |
---|
| 496 | echo "$PART" |
---|
| 497 | else |
---|
[fd1846f] | 498 | # Comprobar si RAID o Multipath (tener en cuenta enlace simbólico). |
---|
| 499 | PART="${DISK}p$2" |
---|
| 500 | if [ "$(stat -L -c "%A" "$PART" 2>/dev/null | cut -c1)" == "b" ]; then |
---|
| 501 | echo "$PART" |
---|
| 502 | else |
---|
[0d6e7222] | 503 | PART="" |
---|
| 504 | # Comprobar si volumen lógico. /* (comentario Doxygen) |
---|
| 505 | if ogCheckStringInGroup "$DISK" "$VOLGROUPS"; then |
---|
| 506 | PART=$(lvscan -a 2>/dev/null | \ |
---|
| 507 | awk -F\' -v n=$2 "\$2~/^${DISK//\//\\/}\// {if (NR==n) print \$2}") |
---|
| 508 | [ -e "$PART" ] || ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $? |
---|
| 509 | # (comentario Doxygen) */ |
---|
| 510 | fi |
---|
| 511 | # Comprobar si volumen ZFS que puede ser montado. |
---|
| 512 | if ogCheckStringInGroup "$DISK" "$ZFSVOLS"; then |
---|
| 513 | zpool import -f -R /mnt -N -a 2>/dev/null |
---|
| 514 | ZPOOL=$(blkid -s LABEL -o value $DISK) |
---|
| 515 | PART=$(zfs list -Hp -o name,canmount,mountpoint -r $ZPOOL | \ |
---|
| 516 | awk -v n=$2 '$2=="on" && $3!="none" {c++; if (c==n) print $1}') |
---|
| 517 | fi |
---|
| 518 | # Salir si no se encuentra dispositivo. |
---|
| 519 | [ -n "$PART" ] || ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $? |
---|
| 520 | # Devolver camino al dispositivo. |
---|
| 521 | echo "$PART" |
---|
[fd1846f] | 522 | fi |
---|
[2717297] | 523 | fi |
---|
| 524 | ;; |
---|
| 525 | *) # Formato erroneo. |
---|
| 526 | ogRaiseError $OG_ERR_FORMAT |
---|
[aae34f6] | 527 | return $OG_ERR_FORMAT |
---|
| 528 | ;; |
---|
[9f29ba6] | 529 | esac |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | |
---|
| 533 | #/** |
---|
[739d358] | 534 | # ogGetDiskSize int_ndisk |
---|
| 535 | #@brief Muestra el tamaño en KB de un disco. |
---|
| 536 | #@param int_ndisk nº de orden del disco |
---|
| 537 | #@return int_size - Tamaño en KB del disco. |
---|
| 538 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
[be0a5cf] | 539 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
[739d358] | 540 | #@note Requisitos: sfdisk, awk |
---|
| 541 | #@version 0.9.2 - Primera version para OpenGnSys |
---|
| 542 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 543 | #@date 2010/09/15 |
---|
[95e9664] | 544 | #@version 1.0.6 - Soportar LVM. |
---|
| 545 | #@author Universidad de Huelva |
---|
| 546 | #@date 2014/09/04 |
---|
[739d358] | 547 | #*/ ## |
---|
| 548 | function ogGetDiskSize () |
---|
| 549 | { |
---|
| 550 | # Variables locales. |
---|
[95e9664] | 551 | local DISK SIZE |
---|
[739d358] | 552 | |
---|
| 553 | # Si se solicita, mostrar ayuda. |
---|
| 554 | if [ "$*" == "help" ]; then |
---|
[cbbb046] | 555 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "$FUNCNAME 1 => 244198584" |
---|
[739d358] | 556 | return |
---|
| 557 | fi |
---|
| 558 | # Error si no se recibe 1 parámetro. |
---|
| 559 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 560 | |
---|
[43892687] | 561 | # Obtener el tamaño del disco. |
---|
[739d358] | 562 | DISK="$(ogDiskToDev $1)" || return $? |
---|
[95e9664] | 563 | SIZE=$(awk -v D=${DISK#/dev/} '{if ($4==D) {print $3}}' /proc/partitions) |
---|
| 564 | # Si no, obtener tamaño del grupo de volúmenes. |
---|
| 565 | [ -z "$SIZE" ] && SIZE=$(vgs --noheadings --units=B -o dev_size $DISK 2>/dev/null | \ |
---|
| 566 | awk '{print $1/1024}') |
---|
| 567 | |
---|
| 568 | # Mostrar salida. |
---|
| 569 | [ -n "$SIZE" ] && echo "$SIZE" |
---|
[739d358] | 570 | } |
---|
| 571 | |
---|
| 572 | |
---|
[d7c35ad] | 573 | #/** |
---|
[b994bc73] | 574 | # ogGetDiskType path_device |
---|
| 575 | #@brief Muestra el tipo de disco (real, RAID, meta-disco, etc.). |
---|
| 576 | #@warning Función en pruebas |
---|
| 577 | #*/ ## |
---|
| 578 | function ogGetDiskType () |
---|
| 579 | { |
---|
| 580 | local DEV MAJOR TYPE |
---|
| 581 | |
---|
| 582 | # Obtener el driver del dispositivo de bloques. |
---|
| 583 | [ -b "$1" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 584 | DEV=${1#/dev/} |
---|
| 585 | MAJOR=$(awk -v D="$DEV" '{if ($4==D) print $1;}' /proc/partitions) |
---|
| 586 | TYPE=$(awk -v D=$MAJOR '/Block/ {bl=1} {if ($1==D&&bl) print toupper($2)}' /proc/devices) |
---|
| 587 | # Devolver mnemónico del driver de dispositivo. |
---|
| 588 | case "$TYPE" in |
---|
| 589 | SD) TYPE="DISK" ;; |
---|
| 590 | SR|IDE*) TYPE="CDROM" ;; # FIXME Comprobar discos IDE. |
---|
| 591 | MD|CCISS*) TYPE="RAID" ;; |
---|
| 592 | DEVICE-MAPPER) TYPE="MAPPER" ;; # FIXME Comprobar LVM y RAID. |
---|
| 593 | esac |
---|
| 594 | echo $TYPE |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | |
---|
| 598 | #/** |
---|
[73488c9] | 599 | # ogGetLastSector int_ndisk [int_npart] |
---|
[6e390b1] | 600 | #@brief Devuelve el último sector usable del disco o de una partición. |
---|
[73488c9] | 601 | #@param int_ndisk nº de orden del disco |
---|
| 602 | #@param int_npart nº de orden de la partición (opcional) |
---|
| 603 | #@return Último sector usable. |
---|
| 604 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 605 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponde con un dispositivo. |
---|
| 606 | #@note Requisitos: sfdisk, sgdisk |
---|
| 607 | #@version 1.0.4 - Primera versión compatible con OpenGnSys. |
---|
| 608 | #@author Universidad de Huelva |
---|
| 609 | #@date 2012/06/03 |
---|
| 610 | #*/ ## |
---|
| 611 | |
---|
| 612 | function ogGetLastSector () |
---|
| 613 | { |
---|
| 614 | # Variables locales |
---|
| 615 | local DISK PART PTTYPE LASTSECTOR SECTORS CYLS |
---|
| 616 | # Si se solicita, mostrar ayuda. |
---|
| 617 | if [ "$*" == "help" ]; then |
---|
| 618 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk [int_npart]" \ |
---|
| 619 | "$FUNCNAME 1 => 488392064" \ |
---|
| 620 | "$FUNCNAME 1 1 => 102400062" |
---|
| 621 | return |
---|
| 622 | fi |
---|
| 623 | # Error si no se reciben 1 o 2 parámetros. |
---|
| 624 | case $# in |
---|
| 625 | 1) DISK=$(ogDiskToDev $1) || return $? |
---|
| 626 | ;; |
---|
| 627 | 2) DISK=$(ogDiskToDev $1) || return $? |
---|
| 628 | PART=$(ogDiskToDev $1 $2) || return $? |
---|
| 629 | ;; |
---|
| 630 | *) ogRaiseError $OG_ERR_FORMAT |
---|
| 631 | return $? ;; |
---|
| 632 | esac |
---|
| 633 | |
---|
| 634 | # Hay que comprobar si el disco es GPT |
---|
| 635 | PTTYPE=$(ogGetPartitionTableType $1) |
---|
[a06ac2d] | 636 | PTTYPE=${PTTYPE:-"MSDOS"} # Por defecto para discos vacíos. |
---|
[73488c9] | 637 | case "$PTTYPE" in |
---|
| 638 | GPT) |
---|
| 639 | if [ $# == 1 ]; then |
---|
| 640 | LASTSECTOR=$(LANG=C sgdisk -p $DISK | awk '/last usable sector/ {print($(NF))}') |
---|
| 641 | else |
---|
| 642 | LASTSECTOR=$(LANG=C sgdisk -p $DISK | awk -v P="$2" '{if ($1==P) print $3}') |
---|
| 643 | fi |
---|
| 644 | ;; |
---|
| 645 | MSDOS) |
---|
| 646 | if [ $# == 1 ]; then |
---|
| 647 | SECTORS=$(awk -v D=${DISK#/dev/} '{if ($4==D) {print $3*2}}' /proc/partitions) |
---|
| 648 | CYLS=$(sfdisk -g $DISK | cut -f2 -d" ") |
---|
| 649 | LASTSECTOR=$[SECTORS/CYLS*CYLS-1] |
---|
| 650 | else |
---|
[b1f1311] | 651 | LASTSECTOR=$(sfdisk -uS -l $DISK 2>/dev/null | \ |
---|
[73488c9] | 652 | awk -v P="$PART" '{if ($1==P) {if ($2=="*") print $4; else print $3} }') |
---|
| 653 | fi |
---|
| 654 | ;; |
---|
| 655 | esac |
---|
| 656 | echo $LASTSECTOR |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | |
---|
| 660 | #/** |
---|
[42669ebf] | 661 | # ogGetPartitionActive int_ndisk |
---|
[a5df9b9] | 662 | #@brief Muestra que particion de un disco esta marcada como de activa. |
---|
[b9e1a8c] | 663 | #@param int_ndisk nº de orden del disco |
---|
| 664 | #@return int_npart Nº de partición activa |
---|
[a5df9b9] | 665 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 666 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 667 | #@note Requisitos: parted |
---|
[59f9ad2] | 668 | #@todo Queda definir formato para atributos (arranque, oculta, ...). |
---|
[afc1e74] | 669 | #@version 0.9 - Primera version compatible con OpenGnSys. |
---|
[a5df9b9] | 670 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
[985bef0] | 671 | #@date 2009/09/17 |
---|
[1e7eaab] | 672 | #*/ ## |
---|
[42669ebf] | 673 | function ogGetPartitionActive () |
---|
| 674 | { |
---|
[59f9ad2] | 675 | # Variables locales |
---|
[a5df9b9] | 676 | local DISK |
---|
| 677 | |
---|
[1e7eaab] | 678 | # Si se solicita, mostrar ayuda. |
---|
[aae34f6] | 679 | if [ "$*" == "help" ]; then |
---|
| 680 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "$FUNCNAME 1 => 1" |
---|
| 681 | return |
---|
| 682 | fi |
---|
[1e7eaab] | 683 | # Error si no se recibe 1 parámetro. |
---|
[aae34f6] | 684 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[a5df9b9] | 685 | |
---|
[1e7eaab] | 686 | # Comprobar que el disco existe y listar su partición activa. |
---|
[a5df9b9] | 687 | DISK="$(ogDiskToDev $1)" || return $? |
---|
[9ca55ab] | 688 | LANG=C parted -sm $DISK print 2>/dev/null | awk -F: '$7~/boot/ {print $1}' |
---|
[a5df9b9] | 689 | } |
---|
| 690 | |
---|
| 691 | |
---|
| 692 | #/** |
---|
[42669ebf] | 693 | # ogGetPartitionId int_ndisk int_npartition |
---|
[7dada73] | 694 | #@brief Devuelve el mnemónico con el tipo de partición. |
---|
[42669ebf] | 695 | #@param int_ndisk nº de orden del disco |
---|
| 696 | #@param int_npartition nº de orden de la partición |
---|
[9f57de01] | 697 | #@return Identificador de tipo de partición. |
---|
[326cec3] | 698 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
[7dada73] | 699 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponde con un dispositivo. |
---|
[a5df9b9] | 700 | #@note Requisitos: sfdisk |
---|
[7dada73] | 701 | #@version 0.9 - Primera versión compatible con OpenGnSys. |
---|
[9f57de01] | 702 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
[0d6e7222] | 703 | #@date 2009-03-25 |
---|
[7dada73] | 704 | #@version 1.0.2 - Detectar partición vacía. |
---|
| 705 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
[0d6e7222] | 706 | #@date 2011-12-23 |
---|
| 707 | #@version 1.0.6 - Soportar LVM. |
---|
| 708 | #@author Universidad de Huelva |
---|
| 709 | #@date 2014-09-04 |
---|
| 710 | #@version 1.1.0 - Soportar pool de volúmenes ZFS. |
---|
| 711 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 712 | #@date 2014-11-14 |
---|
[1e7eaab] | 713 | #*/ ## |
---|
[42669ebf] | 714 | function ogGetPartitionId () |
---|
| 715 | { |
---|
[59f9ad2] | 716 | # Variables locales. |
---|
[ad3f531] | 717 | local DISK PART ID |
---|
[2e15649] | 718 | |
---|
[1e7eaab] | 719 | # Si se solicita, mostrar ayuda. |
---|
[aae34f6] | 720 | if [ "$*" == "help" ]; then |
---|
| 721 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 722 | "$FUNCNAME 1 1 => 7" |
---|
| 723 | return |
---|
| 724 | fi |
---|
[1e7eaab] | 725 | # Error si no se reciben 2 parámetros. |
---|
[aae34f6] | 726 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[2e15649] | 727 | |
---|
[7dada73] | 728 | # Detectar id. de tipo de partición y codificar al mnemónico. |
---|
[2e15649] | 729 | DISK=$(ogDiskToDev $1) || return $? |
---|
[ad3f531] | 730 | PART=$(ogDiskToDev $1 $2) || return $? |
---|
[8baebd4] | 731 | case "$(ogGetPartitionTableType $1)" in |
---|
| 732 | GPT) ID=$(sgdisk -p $DISK 2>/dev/null | awk -v p="$2" '{if ($1==p) print $6;}') || ogRaiseError $OG_ERR_NOTFOUND "$1,$2" || return $? |
---|
[f12cc5d] | 733 | [ "$ID" == "8301" -a "$1 $2" == "$(ogFindCache)" ] && ID=CA00 |
---|
[8baebd4] | 734 | ;; |
---|
| 735 | MSDOS) ID=$(sfdisk --id $DISK $2 2>/dev/null) || ogRaiseError $OG_ERR_NOTFOUND "$1,$2" || return $? ;; |
---|
[0d6e7222] | 736 | LVM) ID=10000 ;; |
---|
| 737 | ZPOOL) ID=10010 ;; |
---|
[8baebd4] | 738 | esac |
---|
[7dada73] | 739 | echo $ID |
---|
[9f29ba6] | 740 | } |
---|
| 741 | |
---|
[a5df9b9] | 742 | |
---|
| 743 | #/** |
---|
[42669ebf] | 744 | # ogGetPartitionSize int_ndisk int_npartition |
---|
[a5df9b9] | 745 | #@brief Muestra el tamano en KB de una particion determinada. |
---|
[42669ebf] | 746 | #@param int_ndisk nº de orden del disco |
---|
| 747 | #@param int_npartition nº de orden de la partición |
---|
| 748 | #@return int_partsize - Tamaño en KB de la partición. |
---|
[a5df9b9] | 749 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 750 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
| 751 | #@note Requisitos: sfdisk, awk |
---|
[985bef0] | 752 | #@version 0.1 - Integracion para Opengnsys - EAC: SizePartition () en ATA.lib |
---|
| 753 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
| 754 | #@date 2008/10/27 |
---|
[afc1e74] | 755 | #@version 0.9 - Primera version para OpenGnSys |
---|
[a5df9b9] | 756 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 757 | #@date 2009/07/24 |
---|
[1e7eaab] | 758 | #*/ ## |
---|
[42669ebf] | 759 | function ogGetPartitionSize () |
---|
| 760 | { |
---|
[59f9ad2] | 761 | # Variables locales. |
---|
[739d358] | 762 | local DISK PART |
---|
[a5df9b9] | 763 | |
---|
[1e7eaab] | 764 | # Si se solicita, mostrar ayuda. |
---|
[aae34f6] | 765 | if [ "$*" == "help" ]; then |
---|
| 766 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 767 | "$FUNCNAME 1 1 => 10000000" |
---|
| 768 | return |
---|
| 769 | fi |
---|
[1e7eaab] | 770 | # Error si no se reciben 2 parámetros. |
---|
[aae34f6] | 771 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[a5df9b9] | 772 | |
---|
[1e7eaab] | 773 | # Obtener el tamaño de la partición. |
---|
[3543b3e] | 774 | DISK="$(ogDiskToDev $1)" || return $? |
---|
[a5df9b9] | 775 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
[3543b3e] | 776 | case "$(ogGetPartitionId $1 $2)" in |
---|
| 777 | 5|f) # Procesar detección de tamaño de partición Extendida. |
---|
[55ad138c] | 778 | sfdisk -l $DISK 2>/dev/null | \ |
---|
[c438bd3] | 779 | awk -v p=$PART '{if ($1==p) {sub (/[^0-9]+/,"",$5); print $5} }' |
---|
[3543b3e] | 780 | ;; |
---|
[0d6e7222] | 781 | *) # Devolver tamaño de partición o del sistema de archivos (para ZFS). |
---|
| 782 | sfdisk -s $PART 2>/dev/null || ogGetFsSize $1 $2 |
---|
[3543b3e] | 783 | ;; |
---|
| 784 | esac |
---|
[a5df9b9] | 785 | } |
---|
| 786 | |
---|
| 787 | |
---|
[b094c59] | 788 | #/** |
---|
[73488c9] | 789 | # ogGetPartitionsNumber int_ndisk |
---|
| 790 | #@brief Detecta el numero de particiones del disco duro indicado. |
---|
| 791 | #@param int_ndisk nº de orden del disco |
---|
| 792 | #@return Devuelve el numero paritiones del disco duro indicado |
---|
| 793 | #@warning Salidas de errores no determinada |
---|
| 794 | #@attention Requisitos: parted |
---|
| 795 | #@note Notas sin especificar |
---|
| 796 | #@version 0.1 - Integracion para Opengnsys - EAC: DetectNumberPartition () en ATA.lib |
---|
| 797 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 798 | #@date Date: 27/10/2008 |
---|
| 799 | #@version 1.0 - Uso de sfdisk Primera version para OpenGnSys |
---|
| 800 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
[0d6e7222] | 801 | #@date 2009-07-24 |
---|
[73488c9] | 802 | #@version 1.0.4 - Uso de /proc/partitions para detectar el numero de particiones |
---|
| 803 | #@author Universidad de Huelva |
---|
[0d6e7222] | 804 | #@date 2012-03-28 |
---|
[95e9664] | 805 | #@version 1.0.6 - Soportar LVM. |
---|
| 806 | #@author Universidad de Huelva |
---|
[0d6e7222] | 807 | #@date 2014-09-04 |
---|
| 808 | #@version 1.1.0 - Soportar ZFS. |
---|
| 809 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 810 | #@date 2014-11-14 |
---|
[73488c9] | 811 | #*/ ## |
---|
| 812 | function ogGetPartitionsNumber () |
---|
| 813 | { |
---|
| 814 | # Variables locales. |
---|
| 815 | local DISK |
---|
| 816 | # Si se solicita, mostrar ayuda. |
---|
| 817 | if [ "$*" == "help" ]; then |
---|
| 818 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \ |
---|
| 819 | "$FUNCNAME 1 => 3" |
---|
| 820 | return |
---|
| 821 | fi |
---|
| 822 | # Error si no se recibe 1 parámetro. |
---|
| 823 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 824 | |
---|
| 825 | # Contar el nº de veces que aparece el disco en su lista de particiones. |
---|
| 826 | DISK=$(ogDiskToDev $1) 2>/dev/null |
---|
[5de6fb0] | 827 | case "$(ogGetPartitionTableType $1)" in |
---|
| 828 | GPT) grep -c "${DISK#/dev/}." /proc/partitions ;; |
---|
| 829 | MSDOS) sfdisk -l $DISK 2>/dev/null | grep -c "^$DISK" ;; |
---|
[95e9664] | 830 | LVM) lvs --noheadings $DISK 2>/dev/null | wc -l ;; |
---|
[9ca55ab] | 831 | ZPOOL) zpool list &>/dev/null || modprobe zfs |
---|
| 832 | zpool import -f -R /mnt -N -a 2>/dev/null |
---|
[0d6e7222] | 833 | zfs list -Hp -o name,canmount,mountpoint -r $(blkid -s LABEL -o value $DISK) | \ |
---|
| 834 | awk '$2=="on" && $3!="none" {c++} |
---|
| 835 | END {print c}' |
---|
| 836 | ;; |
---|
[5de6fb0] | 837 | esac |
---|
[73488c9] | 838 | } |
---|
| 839 | |
---|
| 840 | |
---|
| 841 | #/** |
---|
[60fc799] | 842 | # ogGetPartitionTableType int_ndisk |
---|
| 843 | #@brief Devuelve el tipo de tabla de particiones del disco (GPT o MSDOS) |
---|
| 844 | #@param int_ndisk nº de orden del disco |
---|
| 845 | #@return str_tabletype - Tipo de tabla de paritiones |
---|
| 846 | #@warning Salidas de errores no determinada |
---|
[6e390b1] | 847 | #@note tabletype = { MSDOS, GPT } |
---|
[60fc799] | 848 | #@note Requisitos: parted |
---|
| 849 | #@version 1.0.4 - Primera versión para OpenGnSys |
---|
| 850 | #@author Universidad de Huelva |
---|
| 851 | #@date 2012/03/01 |
---|
[95e9664] | 852 | #@version 1.0.6 - Soportar LVM. |
---|
| 853 | #@author Universidad de Huelva |
---|
[0d6e7222] | 854 | #@date 2014-09-04 |
---|
| 855 | #@version 1.1.0 - Soportar ZFS. |
---|
| 856 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 857 | #@date 2014-11-14 |
---|
[6e390b1] | 858 | #*/ ## |
---|
[60fc799] | 859 | function ogGetPartitionTableType () |
---|
| 860 | { |
---|
| 861 | # Variables locales. |
---|
[95e9664] | 862 | local DISK TYPE |
---|
[60fc799] | 863 | |
---|
| 864 | # Si se solicita, mostrar ayuda. |
---|
| 865 | if [ "$*" == "help" ]; then |
---|
| 866 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \ |
---|
[6e390b1] | 867 | "$FUNCNAME 1 => MSDOS" |
---|
[60fc799] | 868 | return |
---|
| 869 | fi |
---|
| 870 | # Error si no se recibe 1 parámetro. |
---|
| 871 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 872 | |
---|
| 873 | # Sustituye n de disco por su dispositivo. |
---|
[95e9664] | 874 | DISK=$(ogDiskToDev $1) || return $? |
---|
| 875 | |
---|
| 876 | # Comprobar tabla de particiones. |
---|
[9ca55ab] | 877 | [ -b $DISK ] && TYPE=$(parted -sm $DISK print 2>/dev/null | awk -F: -v D=$DISK '{ if($1 == D) print toupper($6)}') |
---|
[0d6e7222] | 878 | # Comprobar si es volumen lógico. |
---|
[95e9664] | 879 | [ -d $DISK ] && vgs $DISK &>/dev/null && TYPE="LVM" |
---|
[0d6e7222] | 880 | # Comprobar si es pool de ZFS. |
---|
[9ca55ab] | 881 | [ -z "$TYPE" -o "$TYPE" == "UNKNOWN" ] && [ -n "$(blkid -s TYPE $DISK | grep zfs)" ] && TYPE="ZPOOL" |
---|
[95e9664] | 882 | |
---|
| 883 | # Mostrar salida. |
---|
| 884 | [ -n "$TYPE" ] && echo "$TYPE" |
---|
[60fc799] | 885 | } |
---|
| 886 | |
---|
| 887 | |
---|
| 888 | #/** |
---|
[344d6e7] | 889 | # ogGetPartitionType int_ndisk int_npartition |
---|
[5804229] | 890 | #@brief Devuelve el mnemonico con el tipo de partición. |
---|
| 891 | #@param int_ndisk nº de orden del disco |
---|
| 892 | #@param int_npartition nº de orden de la partición |
---|
| 893 | #@return Mnemonico |
---|
[be48687] | 894 | #@note Mnemonico: valor devuelto por ogIdToType. |
---|
[5804229] | 895 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
[824b0dd] | 896 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 897 | #@version 0.1 - Integracion para Opengnsys - EAC: TypeFS() en ATA.lib |
---|
[5804229] | 898 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 899 | #@date 2008-10-27 |
---|
| 900 | #@version 0.9 - Primera adaptacion para OpenGnSys. |
---|
| 901 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 902 | #@date 2009-07-21 |
---|
| 903 | #@version 1.0.3 - Código trasladado de antigua función ogGetFsType. |
---|
| 904 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 905 | #@date 2011-12-01 |
---|
[be48687] | 906 | #@version 1.0.5 - Usar función ogIdToType para hacer la conversión id. a tipo. |
---|
| 907 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 908 | #@date 2013-09-19 |
---|
[344d6e7] | 909 | #*/ ## |
---|
| 910 | function ogGetPartitionType () |
---|
| 911 | { |
---|
[5804229] | 912 | # Variables locales. |
---|
| 913 | local ID TYPE |
---|
| 914 | |
---|
| 915 | # Si se solicita, mostrar ayuda. |
---|
| 916 | if [ "$*" == "help" ]; then |
---|
| 917 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 918 | "$FUNCNAME 1 1 => NTFS" |
---|
| 919 | return |
---|
| 920 | fi |
---|
| 921 | # Error si no se reciben 2 parámetros. |
---|
| 922 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 923 | |
---|
| 924 | # Detectar id. de tipo de partición y codificar al mnemonico. |
---|
| 925 | ID=$(ogGetPartitionId "$1" "$2") || return $? |
---|
[b663655] | 926 | TYPE=$(ogIdToType "$ID") |
---|
[5804229] | 927 | echo "$TYPE" |
---|
[344d6e7] | 928 | } |
---|
| 929 | |
---|
| 930 | |
---|
| 931 | #/** |
---|
[b09d0fa] | 932 | # ogHidePartition int_ndisk int_npartition |
---|
| 933 | #@brief Oculta un apartición visible. |
---|
| 934 | #@param int_ndisk nº de orden del disco |
---|
| 935 | #@param int_npartition nº de orden de la partición |
---|
| 936 | #@return (nada) |
---|
| 937 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
[053993f] | 938 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
[b09d0fa] | 939 | #@exception OG_ERR_PARTITION tipo de partición no reconocido. |
---|
| 940 | #@version 1.0 - Versión en pruebas. |
---|
| 941 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 942 | #@date 2010/01/12 |
---|
| 943 | #*/ ## |
---|
| 944 | function ogHidePartition () |
---|
| 945 | { |
---|
| 946 | # Variables locales. |
---|
| 947 | local PART TYPE NEWTYPE |
---|
| 948 | # Si se solicita, mostrar ayuda. |
---|
| 949 | if [ "$*" == "help" ]; then |
---|
| 950 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 951 | "$FUNCNAME 1 1" |
---|
| 952 | return |
---|
| 953 | fi |
---|
| 954 | # Error si no se reciben 2 parámetros. |
---|
| 955 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 956 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
| 957 | |
---|
| 958 | # Obtener tipo de partición. |
---|
| 959 | TYPE=$(ogGetPartitionType "$1" "$2") |
---|
| 960 | case "$TYPE" in |
---|
| 961 | NTFS) NEWTYPE="HNTFS" ;; |
---|
| 962 | FAT32) NEWTYPE="HFAT32" ;; |
---|
| 963 | FAT16) NEWTYPE="HFAT16" ;; |
---|
| 964 | FAT12) NEWTYPE="HFAT12" ;; |
---|
| 965 | *) ogRaiseError $OG_ERR_PARTITION "$TYPE" |
---|
| 966 | return $? ;; |
---|
| 967 | esac |
---|
| 968 | # Cambiar tipo de partición. |
---|
[ec6de25] | 969 | ogSetPartitionType $1 $2 $NEWTYPE |
---|
[b09d0fa] | 970 | } |
---|
| 971 | |
---|
| 972 | |
---|
| 973 | #/** |
---|
[afc1e74] | 974 | # ogIdToType int_idpart |
---|
| 975 | #@brief Devuelve el identificador correspondiente a un tipo de partición. |
---|
| 976 | #@param int_idpart identificador de tipo de partición. |
---|
| 977 | #@return str_parttype mnemónico de tipo de partición. |
---|
| 978 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 979 | #@version 1.0.5 - Primera version para OpenGnSys |
---|
| 980 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 981 | #@date 2013-02-07 |
---|
| 982 | #*/ ## |
---|
| 983 | function ogIdToType () |
---|
| 984 | { |
---|
| 985 | # Variables locales |
---|
| 986 | local ID TYPE |
---|
| 987 | |
---|
| 988 | # Si se solicita, mostrar ayuda. |
---|
| 989 | if [ "$*" == "help" ]; then |
---|
| 990 | ogHelp "$FUNCNAME" "$FUNCNAME int_idpart" \ |
---|
| 991 | "$FUNCNAME 83 => LINUX" |
---|
| 992 | return |
---|
| 993 | fi |
---|
| 994 | # Error si no se recibe 1 parámetro. |
---|
| 995 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 996 | |
---|
| 997 | # Obtener valor hexadecimal de 4 caracteres rellenado con 0 por delante. |
---|
| 998 | ID=$(printf "%4s" "$1" | tr ' ' '0') |
---|
| 999 | case "${ID,,}" in |
---|
| 1000 | 0000) TYPE="EMPTY" ;; |
---|
| 1001 | 0001) TYPE="FAT12" ;; |
---|
| 1002 | 0005|000f) TYPE="EXTENDED" ;; |
---|
| 1003 | 0006|000e) TYPE="FAT16" ;; |
---|
| 1004 | 0007) TYPE="NTFS" ;; |
---|
| 1005 | 000b|000c) TYPE="FAT32" ;; |
---|
| 1006 | 0011) TYPE="HFAT12" ;; |
---|
| 1007 | 0012) TYPE="COMPAQDIAG" ;; |
---|
| 1008 | 0016|001e) TYPE="HFAT16" ;; |
---|
| 1009 | 0017) TYPE="HNTFS" ;; |
---|
| 1010 | 001b|001c) TYPE="HFAT32" ;; |
---|
| 1011 | 0042) TYPE="WIN-DYNAMIC" ;; |
---|
| 1012 | 0082|8200) TYPE="LINUX-SWAP" ;; |
---|
| 1013 | 0083|8300) TYPE="LINUX" ;; |
---|
| 1014 | 008e|8E00) TYPE="LINUX-LVM" ;; |
---|
[b663655] | 1015 | 00a5|a503) TYPE="FREEBSD" ;; |
---|
[afc1e74] | 1016 | 00a6) TYPE="OPENBSD" ;; |
---|
| 1017 | 00a7) TYPE="CACHE" ;; # (compatibilidad con Brutalix) |
---|
| 1018 | 00af|af00) TYPE="HFS" ;; |
---|
| 1019 | 00be|be00) TYPE="SOLARIS-BOOT" ;; |
---|
| 1020 | 00bf|bf0[0145]) TYPE="SOLARIS" ;; |
---|
| 1021 | 00ca|ca00) TYPE="CACHE" ;; |
---|
| 1022 | 00da) TYPE="DATA" ;; |
---|
| 1023 | 00ee) TYPE="GPT" ;; |
---|
| 1024 | 00ef|ef00) TYPE="EFI" ;; |
---|
| 1025 | 00fb) TYPE="VMFS" ;; |
---|
| 1026 | 00fd|fd00) TYPE="LINUX-RAID" ;; |
---|
| 1027 | 0700) TYPE="WINDOWS" ;; |
---|
| 1028 | 0c01) TYPE="WIN-RESERV" ;; |
---|
| 1029 | 7f00) TYPE="CHROMEOS-KRN" ;; |
---|
| 1030 | 7f01) TYPE="CHROMEOS" ;; |
---|
| 1031 | 7f02) TYPE="CHROMEOS-RESERV" ;; |
---|
| 1032 | 8301) TYPE="LINUX-RESERV" ;; |
---|
| 1033 | a500) TYPE="FREEBSD-DISK" ;; |
---|
| 1034 | a501) TYPE="FREEBSD-BOOT" ;; |
---|
| 1035 | a502) TYPE="FREEBSD-SWAP" ;; |
---|
[b663655] | 1036 | ab00) TYPE="HFS-BOOT" ;; |
---|
[afc1e74] | 1037 | af01) TYPE="HFS-RAID" ;; |
---|
| 1038 | bf02) TYPE="SOLARIS-SWAP" ;; |
---|
| 1039 | bf03) TYPE="SOLARIS-DISK" ;; |
---|
| 1040 | ef01) TYPE="MBR" ;; |
---|
| 1041 | ef02) TYPE="BIOS-BOOT" ;; |
---|
| 1042 | *) TYPE="UNKNOWN" ;; |
---|
| 1043 | esac |
---|
| 1044 | echo "$TYPE" |
---|
| 1045 | } |
---|
| 1046 | |
---|
| 1047 | |
---|
| 1048 | #/** |
---|
[73c8417] | 1049 | # ogListPartitions int_ndisk |
---|
[a5df9b9] | 1050 | #@brief Lista las particiones definidas en un disco. |
---|
[42669ebf] | 1051 | #@param int_ndisk nº de orden del disco |
---|
| 1052 | #@return str_parttype:int_partsize ... |
---|
[a5df9b9] | 1053 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 1054 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
| 1055 | #@note Requisitos: \c parted \c awk |
---|
[73c8417] | 1056 | #@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize |
---|
[59f9ad2] | 1057 | #@attention Las tuplas de valores están separadas por espacios. |
---|
[afc1e74] | 1058 | #@version 0.9 - Primera versión para OpenGnSys |
---|
[a5df9b9] | 1059 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 1060 | #@date 2009/07/24 |
---|
[1e7eaab] | 1061 | #*/ ## |
---|
[42669ebf] | 1062 | function ogListPartitions () |
---|
| 1063 | { |
---|
[59f9ad2] | 1064 | # Variables locales. |
---|
[55ad138c] | 1065 | local DISK PART NPARTS TYPE SIZE |
---|
[aae34f6] | 1066 | |
---|
[42669ebf] | 1067 | # Si se solicita, mostrar ayuda. |
---|
[1a7130a] | 1068 | if [ "$*" == "help" ]; then |
---|
[aae34f6] | 1069 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \ |
---|
[73c8417] | 1070 | "$FUNCNAME 1 => NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000" |
---|
[aae34f6] | 1071 | return |
---|
| 1072 | fi |
---|
[42669ebf] | 1073 | # Error si no se recibe 1 parámetro. |
---|
[5dbb046] | 1074 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT "$FORMAT" || return $? |
---|
[a5df9b9] | 1075 | |
---|
[42669ebf] | 1076 | # Procesar la salida de \c parted . |
---|
[b094c59] | 1077 | DISK="$(ogDiskToDev $1)" || return $? |
---|
[3543b3e] | 1078 | NPARTS=$(ogGetPartitionsNumber $1) |
---|
| 1079 | for (( PART = 1; PART <= NPARTS; PART++ )); do |
---|
[5804229] | 1080 | TYPE=$(ogGetPartitionType $1 $PART 2>/dev/null) |
---|
[3543b3e] | 1081 | if [ $? -eq 0 ]; then |
---|
[55ad138c] | 1082 | SIZE=$(ogGetPartitionSize $1 $PART 2>/dev/null) |
---|
| 1083 | echo -n "$TYPE:$SIZE " |
---|
[3543b3e] | 1084 | else |
---|
| 1085 | echo -n "EMPTY:0 " |
---|
| 1086 | fi |
---|
[a5df9b9] | 1087 | done |
---|
| 1088 | echo |
---|
| 1089 | } |
---|
| 1090 | |
---|
[326cec3] | 1091 | |
---|
| 1092 | #/** |
---|
[55ad138c] | 1093 | # ogListPrimaryPartitions int_ndisk |
---|
[942dfd7] | 1094 | #@brief Metafunción que lista las particiones primarias no vacías de un disco. |
---|
[42669ebf] | 1095 | #@param int_ndisk nº de orden del disco |
---|
[55ad138c] | 1096 | #@see ogListPartitions |
---|
[1e7eaab] | 1097 | #*/ ## |
---|
[42669ebf] | 1098 | function ogListPrimaryPartitions () |
---|
| 1099 | { |
---|
[55ad138c] | 1100 | # Variables locales. |
---|
[942dfd7] | 1101 | local PTTYPE PARTS |
---|
[55ad138c] | 1102 | |
---|
[942dfd7] | 1103 | PTTYPE=$(ogGetPartitionTableType $1) || return $? |
---|
[55ad138c] | 1104 | PARTS=$(ogListPartitions "$@") || return $? |
---|
[942dfd7] | 1105 | case "$PTTYPE" in |
---|
| 1106 | GPT) echo $PARTS | sed 's/\( EMPTY:0\)*$//' ;; |
---|
| 1107 | MSDOS) echo $PARTS | cut -sf1-4 -d" " | sed 's/\( EMPTY:0\)*$//' ;; |
---|
| 1108 | esac |
---|
[55ad138c] | 1109 | } |
---|
| 1110 | |
---|
| 1111 | |
---|
| 1112 | #/** |
---|
| 1113 | # ogListLogicalPartitions int_ndisk |
---|
[942dfd7] | 1114 | #@brief Metafunción que lista las particiones lógicas de una tabla tipo MSDOS. |
---|
[42669ebf] | 1115 | #@param int_ndisk nº de orden del disco |
---|
[55ad138c] | 1116 | #@see ogListPartitions |
---|
[1e7eaab] | 1117 | #*/ ## |
---|
[b061ad0] | 1118 | function ogListLogicalPartitions () |
---|
| 1119 | { |
---|
[55ad138c] | 1120 | # Variables locales. |
---|
[942dfd7] | 1121 | local PTTYPE PARTS |
---|
[55ad138c] | 1122 | |
---|
[942dfd7] | 1123 | PTTYPE=$(ogGetPartitionTableType $1) || return $? |
---|
| 1124 | [ "$PTTYPE" == "MSDOS" ] || ogRaiseError $OG_ERR_PARTITION "" || return $? |
---|
[55ad138c] | 1125 | PARTS=$(ogListPartitions "$@") || return $? |
---|
| 1126 | echo $PARTS | cut -sf5- -d" " |
---|
| 1127 | } |
---|
| 1128 | |
---|
| 1129 | |
---|
| 1130 | #/** |
---|
[42669ebf] | 1131 | # ogSetPartitionActive int_ndisk int_npartition |
---|
[89403cd] | 1132 | #@brief Establece cual es la partición activa de un disco. |
---|
[42669ebf] | 1133 | #@param int_ndisk nº de orden del disco |
---|
| 1134 | #@param int_npartition nº de orden de la partición |
---|
| 1135 | #@return (nada). |
---|
[326cec3] | 1136 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 1137 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo. |
---|
| 1138 | #@note Requisitos: parted |
---|
[985bef0] | 1139 | #@version 0.1 - Integracion para Opengnsys - EAC: SetPartitionActive() en ATA.lib |
---|
| 1140 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
| 1141 | #@date 2008/10/27 |
---|
[afc1e74] | 1142 | #@version 0.9 - Primera version compatible con OpenGnSys. |
---|
[326cec3] | 1143 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 1144 | #@date 2009/09/17 |
---|
[1e7eaab] | 1145 | #*/ ## |
---|
[42669ebf] | 1146 | function ogSetPartitionActive () |
---|
| 1147 | { |
---|
[326cec3] | 1148 | # Variables locales |
---|
| 1149 | local DISK PART |
---|
| 1150 | |
---|
[1e7eaab] | 1151 | # Si se solicita, mostrar ayuda. |
---|
[326cec3] | 1152 | if [ "$*" == "help" ]; then |
---|
| 1153 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 1154 | "$FUNCNAME 1 1" |
---|
| 1155 | return |
---|
| 1156 | fi |
---|
[1e7eaab] | 1157 | # Error si no se reciben 2 parámetros. |
---|
[326cec3] | 1158 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 1159 | |
---|
[1e7eaab] | 1160 | # Comprobar que el disco existe y activar la partición indicada. |
---|
[326cec3] | 1161 | DISK="$(ogDiskToDev $1)" || return $? |
---|
| 1162 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
| 1163 | parted -s $DISK set $2 boot on 2>/dev/null |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | |
---|
[1553fc7] | 1167 | #/** |
---|
[ec6de25] | 1168 | # ogSetPartitionId int_ndisk int_npartition hex_partid |
---|
[5af5d5f] | 1169 | #@brief Cambia el identificador de la partición. |
---|
| 1170 | #@param int_ndisk nº de orden del disco |
---|
| 1171 | #@param int_npartition nº de orden de la partición |
---|
[ec6de25] | 1172 | #@param hex_partid identificador de tipo de partición |
---|
[5af5d5f] | 1173 | #@return (nada) |
---|
[ec6de25] | 1174 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 1175 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo. |
---|
| 1176 | #@exception OG_ERR_OUTOFLIMIT Valor no válido. |
---|
| 1177 | #@exception OG_ERR_PARTITION Error al cambiar el id. de partición. |
---|
[5af5d5f] | 1178 | #@attention Requisitos: fdisk, sgdisk |
---|
| 1179 | #@version 0.1 - Integracion para Opengnsys - SetPartitionType() en ATA.lib |
---|
| 1180 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 1181 | #@date 2008/10/27 |
---|
| 1182 | #@version 1.0.4 - Soporte para discos GPT. |
---|
| 1183 | #@author Universidad de Huelva |
---|
| 1184 | #@date 2012/03/13 |
---|
[ec6de25] | 1185 | #@version 1.0.5 - Utiliza el id. de tipo de partición (no el mnemónico) |
---|
| 1186 | #@author Universidad de Huelva |
---|
[0a693d3] | 1187 | #@date 2012/05/14 |
---|
[5af5d5f] | 1188 | #*/ ## |
---|
[6e390b1] | 1189 | function ogSetPartitionId () |
---|
| 1190 | { |
---|
[5af5d5f] | 1191 | # Variables locales |
---|
| 1192 | local DISK PART PTTYPE ID |
---|
| 1193 | |
---|
| 1194 | # Si se solicita, mostrar ayuda. |
---|
| 1195 | if [ "$*" == "help" ]; then |
---|
[8ca8f5e] | 1196 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition hex_partid" \ |
---|
| 1197 | "$FUNCNAME 1 1 7" |
---|
[5af5d5f] | 1198 | return |
---|
| 1199 | fi |
---|
| 1200 | # Error si no se reciben 3 parámetros. |
---|
| 1201 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 1202 | |
---|
[ec6de25] | 1203 | # Sustituye nº de disco y nº partición por su dispositivo. |
---|
| 1204 | DISK=$(ogDiskToDev $1) || return $? |
---|
| 1205 | PART=$(ogDiskToDev $1 $2) || return $? |
---|
| 1206 | # Error si el id. de partición no es hexadecimal. |
---|
| 1207 | ID="${3^^}" |
---|
| 1208 | [[ "$ID" =~ ^[0-9A-F]+$ ]] || ogRaiseError $OG_ERR_OUTOFLIMIT "$3" || return $? |
---|
[5af5d5f] | 1209 | |
---|
| 1210 | # Elección del tipo de partición. |
---|
| 1211 | PTTYPE=$(ogGetPartitionTableType $1) |
---|
| 1212 | case "$PTTYPE" in |
---|
[0a693d3] | 1213 | GPT) sgdisk -t$2:$ID $DISK 2>/dev/null ;; |
---|
[1f2f1e2] | 1214 | MSDOS) echo -ne "t\n$2\n${ID}\nw\n" | fdisk $DISK | grep Syncing &>/dev/null ;; |
---|
[ec6de25] | 1215 | *) ogRaiseError $OG_ERR_OUTOFLIMIT "$1,$PTTYPE" |
---|
| 1216 | return $? ;; |
---|
[5af5d5f] | 1217 | esac |
---|
[1f2f1e2] | 1218 | |
---|
| 1219 | # MSDOS) Correcto si fdisk sin error o con error pero realiza Syncing |
---|
| 1220 | if [ "${PIPESTATUS[1]}" == "0" -o $? -eq 0 ]; then |
---|
[ec6de25] | 1221 | partprobe $DISK 2>/dev/null |
---|
[1f2f1e2] | 1222 | return 0 |
---|
[ec6de25] | 1223 | else |
---|
| 1224 | ogRaiseError $OG_ERR_PARTITION "$1,$2,$3" |
---|
| 1225 | return $? |
---|
| 1226 | fi |
---|
[5af5d5f] | 1227 | } |
---|
| 1228 | |
---|
| 1229 | |
---|
| 1230 | #/** |
---|
[42669ebf] | 1231 | # ogSetPartitionSize int_ndisk int_npartition int_size |
---|
[2ecd096] | 1232 | #@brief Muestra el tamano en KB de una particion determinada. |
---|
[5af5d5f] | 1233 | #@param int_ndisk nº de orden del disco |
---|
[42669ebf] | 1234 | #@param int_npartition nº de orden de la partición |
---|
| 1235 | #@param int_size tamaño de la partición (en KB) |
---|
[2ecd096] | 1236 | #@return (nada) |
---|
| 1237 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 1238 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
| 1239 | #@note Requisitos: sfdisk, awk |
---|
| 1240 | #@todo Compruebar que el tamaño sea numérico positivo y evitar que pueda solaparse con la siguiente partición. |
---|
[afc1e74] | 1241 | #@version 0.9 - Primera versión para OpenGnSys |
---|
[2ecd096] | 1242 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 1243 | #@date 2009/07/24 |
---|
[1e7eaab] | 1244 | #*/ ## |
---|
[42669ebf] | 1245 | function ogSetPartitionSize () |
---|
| 1246 | { |
---|
[2ecd096] | 1247 | # Variables locales. |
---|
| 1248 | local DISK PART SIZE |
---|
| 1249 | |
---|
[1e7eaab] | 1250 | # Si se solicita, mostrar ayuda. |
---|
[2ecd096] | 1251 | if [ "$*" == "help" ]; then |
---|
[311532f] | 1252 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_size" \ |
---|
[2ecd096] | 1253 | "$FUNCNAME 1 1 10000000" |
---|
| 1254 | return |
---|
| 1255 | fi |
---|
[1e7eaab] | 1256 | # Error si no se reciben 3 parámetros. |
---|
[2ecd096] | 1257 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 1258 | |
---|
[1e7eaab] | 1259 | # Obtener el tamaño de la partición. |
---|
[2ecd096] | 1260 | DISK="$(ogDiskToDev $1)" || return $? |
---|
| 1261 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
| 1262 | # Convertir tamaño en KB a sectores de 512 B. |
---|
| 1263 | SIZE=$[$3*2] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[3915005] | 1264 | # Redefinir el tamaño de la partición. |
---|
[1c04494] | 1265 | sfdisk -f -uS -N$2 $DISK <<< ",$SIZE" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $? |
---|
[942dfd7] | 1266 | partprobe $DISK 2>/dev/null |
---|
[2ecd096] | 1267 | } |
---|
| 1268 | |
---|
[5af5d5f] | 1269 | |
---|
[b09d0fa] | 1270 | #/** |
---|
[ec6de25] | 1271 | # ogSetPartitionType int_ndisk int_npartition str_type |
---|
| 1272 | #@brief Cambia el identificador de la partición. |
---|
| 1273 | #@param int_ndisk nº de orden del disco |
---|
| 1274 | #@param int_npartition nº de orden de la partición |
---|
[8ca8f5e] | 1275 | #@param str_type mnemónico de tipo de partición |
---|
[ec6de25] | 1276 | #@return (nada) |
---|
| 1277 | #@attention Requisitos: fdisk, sgdisk |
---|
| 1278 | #@version 0.1 - Integracion para Opengnsys - SetPartitionType() en ATA.lib |
---|
| 1279 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 1280 | #@date 2008/10/27 |
---|
| 1281 | #@version 1.0.4 - Soporte para discos GPT. |
---|
| 1282 | #@author Universidad de Huelva |
---|
| 1283 | #@date 2012/03/13 |
---|
| 1284 | #@version 1.0.5 - Renombrada de ogSetPartitionId. |
---|
| 1285 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 1286 | #@date 2013/03/07 |
---|
| 1287 | #*/ ## |
---|
| 1288 | function ogSetPartitionType () |
---|
| 1289 | { |
---|
| 1290 | # Variables locales |
---|
| 1291 | local DISK PART PTTYPE ID |
---|
| 1292 | |
---|
| 1293 | # Si se solicita, mostrar ayuda. |
---|
| 1294 | if [ "$*" == "help" ]; then |
---|
| 1295 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_type" \ |
---|
| 1296 | "$FUNCNAME 1 1 NTFS" |
---|
| 1297 | return |
---|
| 1298 | fi |
---|
| 1299 | # Error si no se reciben 3 parámetros. |
---|
| 1300 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 1301 | |
---|
| 1302 | # Sustituye nº de disco por su dispositivo. |
---|
| 1303 | DISK=`ogDiskToDev $1` || return $? |
---|
| 1304 | PART=`ogDiskToDev $1 $2` || return $? |
---|
| 1305 | |
---|
| 1306 | # Elección del tipo de partición. |
---|
| 1307 | PTTYPE=$(ogGetPartitionTableType $1) |
---|
| 1308 | ID=$(ogTypeToId "$3" "$PTTYPE") |
---|
| 1309 | [ -n "$ID" ] || ogRaiseError $OG_ERR_FORMAT "$3,$PTTYPE" || return $? |
---|
| 1310 | ogSetPartitionId $1 $2 $ID |
---|
| 1311 | } |
---|
| 1312 | |
---|
| 1313 | |
---|
| 1314 | #/** |
---|
[afc1e74] | 1315 | # ogTypeToId str_parttype [str_tabletype] |
---|
| 1316 | #@brief Devuelve el identificador correspondiente a un tipo de partición. |
---|
| 1317 | #@param str_parttype mnemónico de tipo de partición. |
---|
| 1318 | #@param str_tabletype mnemónico de tipo de tabla de particiones (MSDOS por defecto). |
---|
| 1319 | #@return int_idpart identificador de tipo de partición. |
---|
| 1320 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 1321 | #@note tabletype = { MSDOS, GPT }, (MSDOS, por defecto) |
---|
| 1322 | #@version 0.1 - Integracion para Opengnsys - EAC: TypeFS () en ATA.lib |
---|
| 1323 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
| 1324 | #@date 2008/10/27 |
---|
| 1325 | #@version 0.9 - Primera version para OpenGnSys |
---|
| 1326 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 1327 | #@date 2009-12-14 |
---|
| 1328 | #@version 1.0.4 - Soportar discos GPT (sustituye a ogFsToId). |
---|
| 1329 | #@author Universidad de Huelva |
---|
| 1330 | #@date 2012/03/30 |
---|
| 1331 | #*/ ## |
---|
| 1332 | function ogTypeToId () |
---|
| 1333 | { |
---|
| 1334 | # Variables locales |
---|
| 1335 | local PTTYPE ID |
---|
| 1336 | |
---|
| 1337 | # Si se solicita, mostrar ayuda. |
---|
| 1338 | if [ "$*" == "help" ]; then |
---|
| 1339 | ogHelp "$FUNCNAME" "$FUNCNAME str_parttype [str_tabletype]" \ |
---|
| 1340 | "$FUNCNAME LINUX => 83" \ |
---|
| 1341 | "$FUNCNAME LINUX MSDOS => 83" |
---|
| 1342 | return |
---|
| 1343 | fi |
---|
| 1344 | # Error si no se reciben 1 o 2 parámetros. |
---|
| 1345 | [ $# -lt 1 -o $# -gt 2 ] && (ogRaiseError $OG_ERR_FORMAT; return $?) |
---|
| 1346 | |
---|
| 1347 | # Asociar id. de partición para su mnemónico. |
---|
| 1348 | PTTYPE=${2:-"MSDOS"} |
---|
| 1349 | case "$PTTYPE" in |
---|
| 1350 | GPT) # Se incluyen mnemónicos compatibles con tablas MSDOS. |
---|
| 1351 | case "$1" in |
---|
| 1352 | EMPTY) ID=0 ;; |
---|
| 1353 | WINDOWS|NTFS|EXFAT|FAT32|FAT16|FAT12|HNTFS|HFAT32|HFAT16|HFAT12) |
---|
| 1354 | ID=0700 ;; |
---|
| 1355 | WIN-RESERV) ID=0C01 ;; |
---|
| 1356 | CHROMEOS-KRN) ID=7F00 ;; |
---|
| 1357 | CHROMEOS) ID=7F01 ;; |
---|
| 1358 | CHROMEOS-RESERV) ID=7F02 ;; |
---|
| 1359 | LINUX-SWAP) ID=8200 ;; |
---|
| 1360 | LINUX|EXT[234]|REISERFS|REISER4|XFS|JFS) |
---|
| 1361 | ID=8300 ;; |
---|
| 1362 | LINUX-RESERV) ID=8301 ;; |
---|
| 1363 | LINUX-LVM) ID=8E00 ;; |
---|
| 1364 | FREEBSD-DISK) ID=A500 ;; |
---|
| 1365 | FREEBSD-BOOT) ID=A501 ;; |
---|
| 1366 | FREEBSD-SWAP) ID=A502 ;; |
---|
| 1367 | FREEBSD) ID=A503 ;; |
---|
[b663655] | 1368 | HFS-BOOT) ID=AB00 ;; |
---|
[afc1e74] | 1369 | HFS|HFS+) ID=AF00 ;; |
---|
[1cbf9e0] | 1370 | HFSPLUS) ID=AF00 ;; |
---|
[afc1e74] | 1371 | HFS-RAID) ID=AF01 ;; |
---|
| 1372 | SOLARIS-BOOT) ID=BE00 ;; |
---|
| 1373 | SOLARIS) ID=BF00 ;; |
---|
| 1374 | SOLARIS-SWAP) ID=BF02 ;; |
---|
| 1375 | SOLARIS-DISK) ID=BF03 ;; |
---|
| 1376 | CACHE) ID=CA00;; |
---|
| 1377 | EFI) ID=EF00 ;; |
---|
| 1378 | LINUX-RAID) ID=FD00 ;; |
---|
| 1379 | *) ID="" ;; |
---|
| 1380 | esac |
---|
| 1381 | ;; |
---|
| 1382 | MSDOS) |
---|
| 1383 | case "$1" in |
---|
| 1384 | EMPTY) ID=0 ;; |
---|
| 1385 | FAT12) ID=1 ;; |
---|
| 1386 | EXTENDED) ID=5 ;; |
---|
| 1387 | FAT16) ID=6 ;; |
---|
| 1388 | WINDOWS|NTFS|EXFAT) |
---|
| 1389 | ID=7 ;; |
---|
| 1390 | FAT32) ID=b ;; |
---|
| 1391 | HFAT12) ID=11 ;; |
---|
| 1392 | HFAT16) ID=16 ;; |
---|
| 1393 | HNTFS) ID=17 ;; |
---|
| 1394 | HFAT32) ID=1b ;; |
---|
| 1395 | LINUX-SWAP) ID=82 ;; |
---|
| 1396 | LINUX|EXT[234]|REISERFS|REISER4|XFS|JFS) |
---|
| 1397 | ID=83 ;; |
---|
| 1398 | LINUX-LVM) ID=8e ;; |
---|
| 1399 | FREEBSD) ID=a5 ;; |
---|
| 1400 | OPENBSD) ID=a6 ;; |
---|
| 1401 | HFS|HFS+) ID=af ;; |
---|
| 1402 | SOLARIS-BOOT) ID=be ;; |
---|
| 1403 | SOLARIS) ID=bf ;; |
---|
| 1404 | CACHE) ID=ca ;; |
---|
| 1405 | DATA) ID=da ;; |
---|
| 1406 | GPT) ID=ee ;; |
---|
| 1407 | EFI) ID=ef ;; |
---|
| 1408 | VMFS) ID=fb ;; |
---|
| 1409 | LINUX-RAID) ID=fd ;; |
---|
| 1410 | *) ID="" ;; |
---|
| 1411 | esac |
---|
| 1412 | ;; |
---|
| 1413 | esac |
---|
| 1414 | echo $ID |
---|
| 1415 | } |
---|
| 1416 | |
---|
| 1417 | |
---|
| 1418 | #/** |
---|
[b09d0fa] | 1419 | # ogUnhidePartition int_ndisk int_npartition |
---|
| 1420 | #@brief Hace visible una partición oculta. |
---|
| 1421 | #@param int_ndisk nº de orden del disco |
---|
| 1422 | #@param int_npartition nº de orden de la partición |
---|
| 1423 | #@return (nada) |
---|
| 1424 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
[053993f] | 1425 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
[b09d0fa] | 1426 | #@exception OG_ERR_PARTITION tipo de partición no reconocido. |
---|
| 1427 | #@version 1.0 - Versión en pruebas. |
---|
| 1428 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 1429 | #@date 2010/01/12 |
---|
| 1430 | #*/ ## |
---|
| 1431 | function ogUnhidePartition () |
---|
| 1432 | { |
---|
| 1433 | # Variables locales. |
---|
| 1434 | local PART TYPE NEWTYPE |
---|
| 1435 | # Si se solicita, mostrar ayuda. |
---|
| 1436 | if [ "$*" == "help" ]; then |
---|
| 1437 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 1438 | "$FUNCNAME 1 1" |
---|
| 1439 | return |
---|
| 1440 | fi |
---|
| 1441 | # Error si no se reciben 2 parámetros. |
---|
| 1442 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 1443 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
| 1444 | |
---|
| 1445 | # Obtener tipo de partición. |
---|
| 1446 | TYPE=$(ogGetPartitionType "$1" "$2") |
---|
| 1447 | case "$TYPE" in |
---|
| 1448 | HNTFS) NEWTYPE="NTFS" ;; |
---|
| 1449 | HFAT32) NEWTYPE="FAT32" ;; |
---|
| 1450 | HFAT16) NEWTYPE="FAT16" ;; |
---|
| 1451 | HFAT12) NEWTYPE="FAT12" ;; |
---|
| 1452 | *) ogRaiseError $OG_ERR_PARTITION "$TYPE" |
---|
| 1453 | return $? ;; |
---|
| 1454 | esac |
---|
| 1455 | # Cambiar tipo de partición. |
---|
[ec6de25] | 1456 | ogSetPartitionType $1 $2 $NEWTYPE |
---|
[b09d0fa] | 1457 | } |
---|
| 1458 | |
---|
[2ecd096] | 1459 | |
---|
| 1460 | #/** |
---|
[6cdca0c] | 1461 | # ogUpdatePartitionTable |
---|
[1553fc7] | 1462 | #@brief Fuerza al kernel releer la tabla de particiones de los discos duros |
---|
[42669ebf] | 1463 | #@param no requiere |
---|
[1553fc7] | 1464 | #@return informacion propia de la herramienta |
---|
| 1465 | #@note Requisitos: \c partprobe |
---|
| 1466 | #@warning pendiente estructurar la funcion a opengnsys |
---|
[985bef0] | 1467 | #@version 0.1 - Integracion para Opengnsys - EAC: UpdatePartitionTable() en ATA.lib |
---|
| 1468 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 1469 | #@date 27/10/2008 |
---|
[3915005] | 1470 | #*/ ## |
---|
[42669ebf] | 1471 | function ogUpdatePartitionTable () |
---|
| 1472 | { |
---|
[3915005] | 1473 | local i |
---|
[c6087b9] | 1474 | for i in `ogDiskToDev` |
---|
| 1475 | do |
---|
| 1476 | partprobe $i |
---|
| 1477 | done |
---|
[1553fc7] | 1478 | } |
---|