source: client/shared/scripts/createBaseImage @ fc57da8

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since fc57da8 was 0d4cef22, checked in by irina <irinagomez@…>, 7 years ago

#770 Al crear imagen: Se aumenta el tamaño estimado de las sincronizadas. Se espera antes de chequear si ha ido bien.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@5512 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 6.2 KB
Line 
1#!/bin/bash
2
3#/**
4#         createBaseImage
5#@brief   Script de ejemplo para crear una imagen de un sistema de archivos.
6#@brief   Se usa como base para el programa de creación de imágenes de OpenGnsys Admin).
7#@param 1 disco
8#@param 2 particion
9#@param 3 REPO|CACHE
10#@param 4 imagen
11#@return 
12#@exception OG_ERR_FORMAT     # 1 formato incorrecto.
13#@exception OG_ERR_PARTITION  # 3 Error en partición de disco o en su sistema de archivos
14#@exception OG_ERR_LOCKED     # 4 Imagen o particion bloqueada
15#@exception OG_ERR_IMAGE      # 5 Error en funcion ogCreateImage o ogRestoreImage.
16#@exception OG_ERR_NOTWRITE   # 14 error de escritura
17#@exception OG_ERR_NOTCACHE   # 15 si cache no existe 15
18#@exception OG_ERR_CACHESIZE  # 16 si espacio de la cache local o remota no tiene espacio 16
19#@exception OG_ERR_DONTMOUNT_IMAGE # 70 Error al montar una imagen sincronizada
20#@note  No necesario permiso se escritura por samba en repo.
21#@todo: que hacer, si el tamaño de la cache es sufciente, pero no tiene espacio libre
22#@version 1.0 - creación imagen con btrfs
23#@author 
24#@date   2012-12-04
25#@version 1.1.0 - Se muestra el espacio necesario para alojar la imagen y el disponible (ticket #771)
26#@author  Irina Gomez - ETSII Universidad de Sevilla
27#@date    2017-03-28
28#*/ ##
29
30trap "onexit $1 $2 $3 \"$4\"" 1 2 3 6 9 14 15 EXIT
31
32# Si salimos con error demontamos la imagen y desbloqueamos la imagen y la particion
33function onexit() {
34    local exit_status=$?
35    if [ $exit_status -ne 4 ]; then
36        ogUnlockImage "$3" "/$4.$IMGEXT"
37        ogUnlock $1 $2
38    fi
39    exit $exit_status
40}
41
42TIME1=$SECONDS
43#Carga el configurador del engine desde el fichero engine.cfg
44[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
45
46PROG="$(basename $0)"
47# Si se solicita, mostrar ayuda.
48if [ "$*" == "help" ]; then
49    ogHelp  "$PROG: $MSG_HELP_createBaseImage" \
50            "$PROG ndisco nparticion REPO|CACHE base_image" \
51            "$PROG 1 1 REPO Windows7"
52    exit 0
53fi
54
55[ $# -ne 4 ] && exit $(ogRaiseError session $OG_ERR_FORMAT "$MSG_FORMAT: $PROG ndisco nparticion REPO|CACHE imagen" ; echo $?)
56
57# Limpiamos fichero de log
58echo  " " > $OGLOGCOMMAND
59[ "$(ogGetCaller)" == "CrearImagenBasica" ] || echo  -n ""> $OGLOGSESSION
60
61ogEcho log session "[1] $MSG_SCRIPTS_START $0 $*"
62
63# Valores por defecto en etc/engine.cfg
64IMGEXT=${IMGEXT:-"img"}
65REPOIP=$(ogGetRepoIp)
66
67
68# Comprobamos si la imagen o la particion estan bloqueada:
69ogIsImageLocked "$3" "$4.$IMGEXT" && exit $(ogRaiseError session $OG_ERR_LOCKED "$3 $4.$IMGEXT"; echo $?)
70ogIsLocked "$1" "$2" && exit $(ogRaiseError session $OG_ERR_LOCKED  "$1 $2"; echo $?)
71
72# Si el repositorio es CACHE comprobamos que exista
73if [ "$3" == "CACHE" -o "$3" == "cache" ]; then
74        ! ogFindCache >/dev/null && exit $(ogRaiseError session $OG_ERR_NOTCACHE "CACHE "; echo $?)
75fi
76
77# Obtener información de los parámetros de entrada.
78PART=$(ogDiskToDev "$1" "$2" 2>/dev/null) || exit $(ogRaiseError session $OG_ERR_PARTITION "$1 $2" ; echo $?)
79# Comprobar consistencia del sistema de archivos.
80echo " " > $OGLOGCOMMAND
81SIZEFS=$(ogGetFsSize  $1 $2)
82ogEcho log session "[20] $MSG_HELP_ogCheckFs  $PART $SIZEFS (KB) "
83ogUnmount $1 $2
84ogCheckFs $1 $2 &> $OGLOGCOMMAND || exit $(ogRaiseError session $OG_ERR_PARTITION "ogCheckFs $1 $2"; echo $?)
85
86# Comprobamos que la particion se puede montar
87ORIG=$(ogMount $1 $2) || exit $(ogRaiseError session $OG_ERR_PARTITION "$1 $2" ; echo $?)
88
89# Borramos ficheros de paginacion y configuracion
90ogCleanOs $1 $2
91
92#Comprobar espacio que requerira la imagen para ser almacenada
93read SIZEDATA SIZEREQUIRED SIZEFREE ISENOUGHSPACE <<< $(ogGetSizeParameters $1 $2 "$3" "$4" SYNC)
94
95ogEcho log session "[16] $PROG: $MSG_SCRIPTS_CREATE_SIZE $SIZEREQUIRED $SIZEFREE"
96[ "$ISENOUGHSPACE" ==  "TRUE" ] || exit $(ogRaiseError session $OG_ERR_CACHESIZE "$3"; echo $?)
97
98IMGDIR="$(ogGetParentPath "$3" "/$4")"
99IMGFILE=${IMGDIR[$3]}/$(basename "/$4").$IMGEXT
100
101# Crear la imagen.
102echo " " > $OGLOGCOMMAND
103TIME2=$SECONDS
104
105ogEcho log session "[40] $MSG_HELP_ogCreateImage $1 $2 $3 $4 "
106
107# Si existe el fichero de la imagen se hace copia de seguridad y se redimensiona, si  no existe se crea.
108# Bloqueo la imagen. Si esta en modo lectura dara error y nos salimos
109ogEcho log session "[50] $MSG_HELP_ogCreateFileImage."
110ogLockImage "$3"  "/$4.$IMGEXT" || exit $?
111ogCreateFileImage $3 "$4" $IMGEXT $SIZEREQUIRED
112
113# Creamos la lista del contenido y lo situamos en la particion a copiar.
114ogEcho log session "[60] $MSG_HELP_ogCreateInfoImage"
115ogCreateInfoImage $1 $2 $IMGEXT
116
117TIMEAUX3=$[SECONDS-TIME2]
118ogEcho log session "      $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL : $[TIMEAUX3/60]m $[TIMEAUX3%60]s"
119
120# Esperamos que el servidor termine de crear y montar la imagen
121ogWaitSyncImage "$3" "$4" $IMGEXT "mounted" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?)
122
123# Sincronizamos los datos de la particion con la imagen.
124ogEcho log session "[70] $MSG_HELP_ogSyncCreate."
125ogSyncCreate $1 $2 $3 "$4"  $IMGEXT
126RETVAL=$?
127[ $RETVAL == 0 ] || ogEcho session warning "$MSG_ERR_SYNCHRONIZING"
128
129TIMEAUX5=$[SECONDS-TIMEAUX3]
130ogEcho log session "      $MSG_SCRIPTS_TASK_END, $MSG_SCRIPTS_TIME_PARTIAL: $[TIMEAUX5/60]m $[TIMEAUX5%60]s"
131
132# Reducimos la imagen: solo para kernel <= 3.7, imagenes con FS ext4. (Desmonta y desbloquea la imagen)
133ogEcho log session "[80] $MSG_HELP_ogReduceImage: $3 /$4.$IMGEXT"
134ogReduceImage $3 "$4" $IMGEXT
135# Esperamos que el servidor termine de reducir la imagen
136ogWaitSyncImage "$3" "$4" $IMGEXT "reduced" $SIZEREQUIRED || exit $(ogRaiseError session $OG_ERR_DONTMOUNT_IMAGE "$3 $4 $IMGEXT: time_out."; echo $?)
137
138echo  " " > $OGLOGCOMMAND
139sleep 2
140# Comprobamos que la imagen esta bien detectacdo que es un sistema de ficheros.
141ogEcho log session "[95] $MSG_HELP_ogCheckSyncImage"
142ogCheckSyncImage $3 "$4" "img" || exit $(ogRaiseError session $OG_ERR_IMAGE "$3 $4 img" ; echo $?)
143
144#resumen de la operacion
145IMGSIZE=$(ls -l --block-size=1024 "$IMGFILE" | cut -f5 -d" ")
146
147TIME=$[SECONDS-TIME1]
148ogEcho log session "[100] $MSG_SCRIPTS_TIME_TOTAL $[TIME/60]m $[TIME%60]s"
149ogEcho log session "      FileSystem $PART with $SIZEDATA KB data created onto file-image as $4 and used $IMGSIZE KB acros DFS rsync "
150
151# Si ha habido problema al sincronizar nos salimos con error
152[ $RETVAL == 0 ] || exit $OG_ERR_SYNCHRONIZING
Note: See TracBrowser for help on using the repository browser.