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