[00a2c2c] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | #@file boottoolsfunctions.lib |
---|
| 4 | #@brief Librería o clase Boot-Tools |
---|
| 5 | #@class Boot-Tools |
---|
| 6 | #@brief Funciones para generar un sistema operativo cliente para opengnsys |
---|
[83d87a3] | 7 | #@version 1.1.1 |
---|
[00a2c2c] | 8 | #@warning License: GNU GPLv3+ |
---|
| 9 | #*/ |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | # btGetVariables: define las constantes a utilizar |
---|
| 13 | # Autor: Antonio J. Doblas Viso. Universidad de Málaga. |
---|
[27ee376] | 14 | function btogGetVar() |
---|
[00a2c2c] | 15 | { |
---|
[83d87a3] | 16 | export BTDIR=/tmp/opengnsys_installer/opengnsys/client/boot-tools |
---|
[00a2c2c] | 17 | export BTTARGETDIR=/var/lib/tftpboot/ogclient/ |
---|
| 18 | export BTROOTFSIMG=${BTTARGETDIR}ogclient.img |
---|
| 19 | export BTROOTFSMNT=${BTTARGETDIR}ogclientmount |
---|
[abfdc97] | 20 | if [ "$OSARCH" = "i386" ]; then |
---|
| 21 | # tamaño maximo limitado por schroot 2GB para 32 bits |
---|
| 22 | export BTVIRTUALDISKSIZE=2000 |
---|
| 23 | else |
---|
| 24 | export BTVIRTUALDISKSIZE="3G" |
---|
| 25 | fi |
---|
[00a2c2c] | 26 | export BTROOTFSIMGLABEL=ogClient |
---|
| 27 | |
---|
| 28 | export LOG_FILE=/tmp/boot-tools_installation.log |
---|
[841ce50] | 29 | |
---|
[0d178ab] | 30 | export VERSIONBOOTTOOLS="ogLive" |
---|
[00a2c2c] | 31 | } |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | # btGetOsInfo: detecta la version del host, para tenerla de referencia en el boot-tools a generar. |
---|
| 35 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
| 36 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 37 | #@date 2010/05/24 |
---|
| 38 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
| 39 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 40 | #@date 2011/08/03 |
---|
[9de55e2] | 41 | #@version 1.0.5 - Fichero general de configuración, Kernel 3.7 para Ubuntu 12.10. |
---|
| 42 | #@author Ramón Gómez, ETSII Univ. Sevilla |
---|
| 43 | #@date 2013/02/06 |
---|
[00a2c2c] | 44 | function btogGetOsInfo () |
---|
| 45 | { |
---|
[5bcd021] | 46 | OGCLIENTCFG=/tmp/ogclient.cfg |
---|
| 47 | case "${1,,}" in |
---|
[385e255] | 48 | precise) # ogLive 1.0.4-rc2 basado en Ubuntu 12.04 LTS. |
---|
| 49 | OSDISTRIB="ubuntu" |
---|
| 50 | OSCODENAME="precise" |
---|
| 51 | OSRELEASE="3.2.0-23-generic" |
---|
[11694ea] | 52 | #OSRELEASE="3.11.0-26-generic" |
---|
[5bcd021] | 53 | OSARCH="i386" |
---|
| 54 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
[00a2c2c] | 55 | ;; |
---|
[5c09bc5] | 56 | wheezy) # ogLive basado en Debian 7.3. |
---|
| 57 | OSDISTRIB="debian" |
---|
| 58 | OSCODENAME="wheezy" |
---|
| 59 | OSRELEASE="3.2.0-4-i386" |
---|
| 60 | OSARCH="i386" |
---|
| 61 | OSHTTP="http://ftp.es.debian.org/debian/" |
---|
| 62 | ;; |
---|
[385e255] | 63 | quantal) # ogLive 1.0.5-rc2 basado en Ubuntu 12.10 con Kernel descargado. |
---|
[5bcd021] | 64 | OSDISTRIB="ubuntu" |
---|
[385e255] | 65 | OSCODENAME="quantal" |
---|
| 66 | OSRELEASE="3.7.6-030706-generic" |
---|
[5bcd021] | 67 | OSARCH="i386" |
---|
| 68 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
[00a2c2c] | 69 | ;; |
---|
[385e255] | 70 | raring) # ogLive 1.0.5-rc3 basado en Ubuntu 13.04. |
---|
[9de55e2] | 71 | OSDISTRIB="ubuntu" |
---|
[385e255] | 72 | OSCODENAME="raring" |
---|
| 73 | OSRELEASE="3.8.0-22-generic" |
---|
| 74 | OSARCH="i386" |
---|
| 75 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
| 76 | ;; |
---|
[5c09bc5] | 77 | trusty) # ogLive 1.0.5-rc4 basado en Ubuntu 14.04. |
---|
[9e0ee12] | 78 | OSDISTRIB="ubuntu" |
---|
[5c09bc5] | 79 | OSCODENAME="trusty" |
---|
| 80 | OSRELEASE="3.13.0-24-generic" |
---|
[9e0ee12] | 81 | OSARCH="i386" |
---|
| 82 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
| 83 | ;; |
---|
[8176c4f] | 84 | vivid) # ogLive 1.1.0-rc2 basado en Ubuntu 15.04. |
---|
[5c09bc5] | 85 | OSDISTRIB="ubuntu" |
---|
| 86 | OSCODENAME="vivid" |
---|
[8176c4f] | 87 | OSRELEASE="3.19.0-49-generic" |
---|
[385e255] | 88 | OSARCH="i386" |
---|
[5c09bc5] | 89 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
[385e255] | 90 | ;; |
---|
[5c09bc5] | 91 | wily) # ogLive 1.1.0-rc1 basado en Ubuntu 15.10. |
---|
[385e255] | 92 | OSDISTRIB="ubuntu" |
---|
[5c09bc5] | 93 | OSCODENAME="wily" |
---|
[16fc7ab] | 94 | OSRELEASE="4.2.0-35-generic" |
---|
[9de55e2] | 95 | OSARCH="i386" |
---|
| 96 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
| 97 | ;; |
---|
[6acd145] | 98 | xenial|xenial-4.4) # ogLive 1.1.0-rc4 basado en Ubuntu 16.04 y Kernel 4.4. |
---|
[11364a6] | 99 | OSDISTRIB="ubuntu" |
---|
| 100 | OSCODENAME="xenial" |
---|
| 101 | OSRELEASE="4.4.0-34-generic" |
---|
| 102 | OSARCH="i386" |
---|
| 103 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
| 104 | ;; |
---|
[6acd145] | 105 | xenial-4.8) # ogLive 1.1.0-rc5 basado en Ubuntu 16.04 y Kernel 4.8. |
---|
| 106 | OSDISTRIB="ubuntu" |
---|
| 107 | OSCODENAME="xenial" |
---|
[73d2b755] | 108 | OSRELEASE="4.8.0-39-generic" |
---|
| 109 | OSARCH="amd64" |
---|
[6acd145] | 110 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
| 111 | ;; |
---|
[5d62f74] | 112 | xenial-4.13) # ogLive 1.1.0-rc6 basado en Ubuntu 16.04 y Kernel 4.13. |
---|
| 113 | OSDISTRIB="ubuntu" |
---|
| 114 | OSCODENAME="xenial" |
---|
| 115 | OSRELEASE="4.13.0-17-generic" |
---|
| 116 | OSARCH="amd64" |
---|
| 117 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
| 118 | ;; |
---|
[58a6159] | 119 | bionic|bionic-4.15) # ogLive 1.1.1-rc1 basado en Ubuntu 18.04 y Kernel 4.15. |
---|
[5d62f74] | 120 | OSDISTRIB="ubuntu" |
---|
[e9edb52] | 121 | OSCODENAME="bionic" |
---|
[83d87a3] | 122 | OSRELEASE="4.15.0-32-generic" |
---|
[5d62f74] | 123 | OSARCH="amd64" |
---|
| 124 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
| 125 | ;; |
---|
[58a6159] | 126 | bionic-4.18) # ogLive 1.1.1-rc3 basado en Ubuntu 18.04 y Kernel 4.18. |
---|
| 127 | OSDISTRIB="ubuntu" |
---|
| 128 | OSCODENAME="bionic" |
---|
| 129 | OSRELEASE="4.18.0-17-generic" |
---|
| 130 | OSARCH="amd64" |
---|
| 131 | OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
| 132 | ;; |
---|
[e4060f1] | 133 | host) # ogLive basado en la distribución del servidor. |
---|
[5bcd021] | 134 | OSDISTRIB=$(lsb_release -is) |
---|
| 135 | OSCODENAME=$(lsb_release -cs) |
---|
[73d2b755] | 136 | OSRELEASE=$(uname -r) |
---|
| 137 | OSARCH=$(dpkg --print-architecture) |
---|
[5bcd021] | 138 | export OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
[00a2c2c] | 139 | ;; |
---|
[e4060f1] | 140 | *) # Parámetro desconocido |
---|
| 141 | echo "Parámetro no válido." |
---|
| 142 | exit 1 |
---|
| 143 | ;; |
---|
[5bcd021] | 144 | esac |
---|
[83d87a3] | 145 | BRANCH="devel" |
---|
| 146 | GITURL="https://api.github.com/repos/opengnsys/OpenGnsys/commits?sha=$BRANCH&path=/client" |
---|
[2dd6a85] | 147 | GITRELEASE=$(curl -s "$GITURL" | jq -r '"r" + (.[0].commit.committer.date | split("-") | join("")[:8]) + "." + (.[0].sha[:7])') |
---|
[83d87a3] | 148 | NAMEISOCLIENT="$VERSIONBOOTTOOLS-$OSCODENAME-$OSRELEASE-$OSARCH-$GITRELEASE" |
---|
| 149 | NAMEHOSTCLIENT="$VERSIONBOOTTOOLS-$OSCODENAME-$GITRELEASE" |
---|
[5bcd021] | 150 | export OSDISTRIB OSCODENAME OSRELEASE OSARCH OSHTTP |
---|
[83d87a3] | 151 | export TYPECLIENT GITRELEASE NAMEISOCLIENT NAMEHOSTCLIENT |
---|
[5bcd021] | 152 | ### El fichero de configuración debe sustituir a estos 3 ficheros (borrar las 3 líneas siguientes). |
---|
[0d178ab] | 153 | echo "$NAMEISOCLIENT" > /tmp/opengnsys_info_rootfs |
---|
| 154 | echo "$NAMEHOSTCLIENT" > /tmp/opengnsys_chroot |
---|
[5bcd021] | 155 | # Generar fichero de configuración. |
---|
| 156 | cat << EOT > $OGCLIENTCFG |
---|
| 157 | TYPECLIENT="$1" |
---|
| 158 | OSDISTRIB="$OSDISTRIB" |
---|
| 159 | OSCODENAME="$OSCODENAME" |
---|
| 160 | OSRELEASE="$OSRELEASE" |
---|
| 161 | OSARCH="$OSARCH" |
---|
| 162 | OSHTTP="$OSHTTP" |
---|
[83d87a3] | 163 | GITRELEASE="$GITRELEASE" |
---|
[5bcd021] | 164 | NAMEISOCLIENT="$NAMEISOCLIENT" |
---|
| 165 | NAMEHOSTCLIENT="$NAMEHOSTCLIENT" |
---|
| 166 | EOT |
---|
[00a2c2c] | 167 | } |
---|
| 168 | |
---|
| 169 | # btogSetFsVirtual: Crea y formatea el fichero - disco duro virtual |
---|
| 170 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
| 171 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 172 | #@date 2010/05/24 |
---|
| 173 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
| 174 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 175 | #@date 2011/08/03 |
---|
| 176 | # error code return 2 |
---|
[27ee376] | 177 | function btogSetFsVirtual () |
---|
[00a2c2c] | 178 | { |
---|
| 179 | |
---|
| 180 | local RERROR DISKLOOP PARTLOOP #return code error |
---|
| 181 | |
---|
| 182 | #Dependencias. |
---|
| 183 | [ -z "$BTROOTFSIMG" ] && btogGetVar |
---|
| 184 | |
---|
| 185 | echoAndLog "$FUNCNAME(): Creación y formateo del disco virtual $BTVIRTUALDISKSIZE MB " |
---|
| 186 | |
---|
| 187 | #Desmontamos el dispositivo virtual |
---|
| 188 | mount | grep $BTROOTFSMNT && umount $BTROOTFSMNT |
---|
[0d178ab] | 189 | mount | grep $BTROOTFSMNT && umount $BTROOTFSMNT |
---|
[00a2c2c] | 190 | |
---|
| 191 | #echo "$FUNCNAME(): Creando el directorio donde se montará el disco virtual $BTROOTFSMNT" |
---|
| 192 | mkdir -p $BTROOTFSMNT |
---|
| 193 | |
---|
| 194 | if [ $? -ne 0 ] |
---|
| 195 | then |
---|
| 196 | errorAndLog "$FUNCNAME(): Creando directorio $BTROOTFSMNT : ERROR" |
---|
| 197 | return 1 |
---|
| 198 | fi |
---|
| 199 | |
---|
| 200 | # Permisos para el usuario opengnsys. |
---|
| 201 | chown -R root:opengnsys $BTTARGETDIR |
---|
| 202 | |
---|
| 203 | #echo "$FUNCNAME(): Creando el disco virtual con tamaño máximo de $BTVIRTUALDISKSIZE MB" |
---|
[abfdc97] | 204 | if [ "$OSARCH" = "i386" ]; then |
---|
| 205 | dd if=/dev/zero of=$BTROOTFSIMG bs=1048576 count=$BTVIRTUALDISKSIZE |
---|
[00a2c2c] | 206 | #dd if=/dev/zero of=$BTROOTFSIMG bs=1k count=$OGCLIENTSIZEKB # necesita 500MB |
---|
[abfdc97] | 207 | else |
---|
| 208 | qemu-img create $BTROOTFSIMG $BTVIRTUALDISKSIZE |
---|
| 209 | fi |
---|
[00a2c2c] | 210 | if [ $? -ne 0 ] |
---|
| 211 | then |
---|
| 212 | errorAndLog "$FUNCNAME(): Creando el disco virtual con tamaño maxima $BTVIRTUALDISKSIZE MB : ERROR" |
---|
| 213 | return 2 |
---|
| 214 | fi |
---|
| 215 | |
---|
| 216 | # Particionamos el disco virtual con una sola particion primaria. |
---|
| 217 | DISKLOOP=$(losetup -f) |
---|
| 218 | #TODO: si no DISKLOOP error |
---|
| 219 | losetup $DISKLOOP $BTROOTFSIMG |
---|
| 220 | #echo "$FUNCNAME(): particiondo el disco virtual - $DISKLOOP - con una particion primaria" |
---|
| 221 | echo -e "n\np\n1\n\n\nt\n83\nw" | fdisk $DISKLOOP |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | #echoAndLog "$FUNCNAME(): Liberamos Desmontando $DISKLOOP despues del particionado " |
---|
[ed7e34d] | 225 | sleep 10 |
---|
[00a2c2c] | 226 | losetup -d $DISKLOOP |
---|
| 227 | if [ $? -ne 0 ] |
---|
| 228 | then |
---|
| 229 | errorAndLog "$FUNCNAME(): Liberando disco virtual despues del particionado: ERROR" |
---|
| 230 | return 2 |
---|
| 231 | fi |
---|
| 232 | |
---|
| 233 | |
---|
| 234 | PARTLOOP=$(losetup -f) |
---|
| 235 | #echo "$FUNCNAME(): Formateando la particion principal $PARTLOOP" |
---|
[69fe46e] | 236 | losetup -o 32256 $PARTLOOP $BTROOTFSIMG && mkfs.ext4 -b 4096 -L $BTROOTFSIMGLABEL $PARTLOOP |
---|
[00a2c2c] | 237 | if [ $? -ne 0 ] |
---|
| 238 | then |
---|
| 239 | errorAndLog "$FUNCNAME(): Formateando la particion principal del disco virtual: ERROR" |
---|
| 240 | return 2 |
---|
| 241 | fi |
---|
| 242 | #echoAndLog "$FUNCNAME(): Desmontando $PARTLOOP despues del formateo " |
---|
[ed7e34d] | 243 | sleep 10 |
---|
[00a2c2c] | 244 | losetup -d $PARTLOOP |
---|
| 245 | if [ $? -ne 0 ] |
---|
| 246 | then |
---|
| 247 | errorAndLog "$FUNCNAME(): Liberando la particion virtual despues del formateo: ERROR" |
---|
| 248 | return 2 |
---|
| 249 | else |
---|
| 250 | echoAndLog "$FUNCNAME(): $BTROOTFSIMG $BTVIRTUALDISKSIZE MB : OK" |
---|
| 251 | fi |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | |
---|
| 255 | # btogSetfsBase: Genera el sistema root base con debootstrap |
---|
| 256 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
| 257 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 258 | #@date 2010/05/24 |
---|
| 259 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
| 260 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 261 | #@date 2011/08/03 |
---|
| 262 | # error code return 3 |
---|
[27ee376] | 263 | function btogSetFsBase () |
---|
[00a2c2c] | 264 | { |
---|
| 265 | |
---|
| 266 | # Dependencias |
---|
[5bcd021] | 267 | [ -z "$OSCODENAME" ] && btogGetOsInfo $TYPECLIENT |
---|
[00a2c2c] | 268 | |
---|
| 269 | echoAndLog "$FUNCNAME: Iniciando la generación del sistema de archivos " |
---|
| 270 | |
---|
| 271 | #Montamos el dispositivo virtual en su punto de montaje. |
---|
| 272 | mount | grep $BTROOTFSMNT || mount $BTROOTFSIMG $BTROOTFSMNT -o loop,offset=32256 |
---|
| 273 | mount | grep $BTROOTFSMNT && echoAndLog "$FUNCNAME: mount $BTROOTFSIMG $BTROOTFSMNT -o loop,offset=32256 OK " || errorAndLog "$FUNCNAME: mount $BTROOTFSIMG $BTROOTFSMNT -o loop,offset=32256 : FAILURE " |
---|
| 274 | |
---|
[5bcd021] | 275 | debootstrap --arch=$OSARCH --components=main,universe ${OSCODENAME} ${BTROOTFSMNT} ${OSHTTP} |
---|
[ed7e34d] | 276 | #debootstrap --arch=$OSARCH ${OSCODENAME} ${BTROOTFSMNT} http://archive.ubuntu.com/ubuntu/ |
---|
[00a2c2c] | 277 | |
---|
| 278 | |
---|
| 279 | if [ $? -ne 0 ]; then |
---|
[5bcd021] | 280 | errorAndLog "$FUNCNAME: debootstrap --arch=$OSARCH --components=main,universe $OSCODENAME $BTROOTFSMNT $OSHTTP : ha fallado!" |
---|
[00a2c2c] | 281 | mount | grep $BTROOTFSMNT && umount $BTROOTFSMNT |
---|
| 282 | return 3 |
---|
| 283 | else |
---|
| 284 | echoAndLog "$FUNCNAME: debootstrap --include=linux-image-${OSRELEASE},linux-headers-${OSRELEASE} --arch=$OSARCH --components=main,universe $OSCODENAME $BTROOTFSMNT $OSHTTP : ok" |
---|
| 285 | mount | grep $BTROOTFSMNT && umount $BTROOTFSMNT |
---|
| 286 | return 0 |
---|
| 287 | fi |
---|
| 288 | sleep 5 |
---|
| 289 | |
---|
| 290 | ##preubas revisar OSRELEASE |
---|
| 291 | #debootstrap --include=linux-image-${OSRELEASE},linux-headers-${OSRELEASE} --arch=$OSARCH --components=main,universe ${OSCODENAME} ${OGCLIENTMOUNT} ${OSHTTP} |
---|
| 292 | #debootstrap --include=linux-image-${OSRELEASE} --arch=i386 --variant=minbase $OSVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/ |
---|
| 293 | #debootstrap --variant=minbase --include=linux-image-${OGRELEASE} --arch=i386 $OGVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/ |
---|
| 294 | #echo debootstrap --include=linux-image-${OGRELEASE},dbus --arch=i386 --components=main,universe $OGVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/ |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | #btogSetFsAcces: habilita el acceso al sistema root del cliente con schroot |
---|
| 298 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
| 299 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 300 | #@date 2010/05/24 |
---|
| 301 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
| 302 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 303 | #@date 2011/08/03 |
---|
[27ee376] | 304 | function btogSetFsAccess() |
---|
[00a2c2c] | 305 | { |
---|
| 306 | echoAndLog "$FUNCNAME: Iniciando la configuración del schroot " |
---|
| 307 | cp /etc/schroot/schroot.conf /etc/schroot/schroot.conf.`getDateTime` |
---|
| 308 | cat << EOF > /etc/schroot/schroot.conf |
---|
| 309 | [IMGogclient] |
---|
| 310 | type=loopback |
---|
| 311 | file=/var/lib/tftpboot/ogclient/ogclient.img |
---|
[69fe46e] | 312 | description=ogclient Ubuntu image |
---|
[00a2c2c] | 313 | #priority=1 |
---|
| 314 | users=root |
---|
| 315 | groups=root |
---|
| 316 | root-groups=root |
---|
| 317 | mount-options=-o offset=32256 |
---|
| 318 | root-users=root |
---|
| 319 | EOF |
---|
| 320 | |
---|
| 321 | cp /etc/schroot/mount-defaults /etc/schroot/mount-defaults.`getDateTime` |
---|
| 322 | cat << EOF > /etc/schroot/mount-defaults |
---|
| 323 | # mount.defaults: static file system information for chroots. |
---|
| 324 | # Note that the mount point will be prefixed by the chroot path |
---|
| 325 | # (CHROOT_PATH) |
---|
| 326 | # |
---|
| 327 | # <file system> <mount point> <type> <options> <dump> <pass> |
---|
| 328 | proc /proc proc defaults 0 0 |
---|
| 329 | #procbususb /proc/bus/usb usbfs defaults 0 0 |
---|
| 330 | #/dev /dev none rw,bind 0 0 |
---|
| 331 | /dev/pts /dev/pts none rw,bind 0 0 |
---|
| 332 | /dev/shm /dev/shm none rw,bind 0 0 |
---|
| 333 | #/home /home none rw,bind 0 0 |
---|
| 334 | /tmp /tmp none rw,bind 0 0 |
---|
| 335 | EOF |
---|
| 336 | |
---|
[841ce50] | 337 | rm /etc/schroot/setup.d/*chrootname |
---|
| 338 | |
---|
[00a2c2c] | 339 | echoAndLog "$FUNCNAME: Finalizado: OK " |
---|
| 340 | return 0 |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | |
---|
| 344 | |
---|
| 345 | #btogFsInitr genera un initrd. |
---|
| 346 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
| 347 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 348 | #@date 2010/05/24 |
---|
| 349 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
| 350 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 351 | #@date 2011/08/03 |
---|
[27ee376] | 352 | function btogFsInitrd () |
---|
[00a2c2c] | 353 | { |
---|
| 354 | #DEPENDENCIAS |
---|
[27ee376] | 355 | [ -z "$BTROOTFSIMG" ] && btogGetVar |
---|
[5bcd021] | 356 | [ -z "$OSCODENAME" ] && btogGetOsInfo $TYPECLIENT |
---|
[27ee376] | 357 | |
---|
[00a2c2c] | 358 | cd / |
---|
[27ee376] | 359 | schroot -c IMGogclient -- /usr/bin/boot-tools/boottoolsInitrdGenerate.sh |
---|
| 360 | echo "cp /tmp/*-${OSRELEASE} ${BTTARGETDIR}" |
---|
| 361 | cp /tmp/*-${OSRELEASE} ${BTTARGETDIR} |
---|
[841ce50] | 362 | #Creando copias de las version oginitr y ogvmlinux previas |
---|
| 363 | TIMEMOD=`date +%Y%m%d-%H%M%S` |
---|
| 364 | [ -f $BTTARGETDIR/oginitrd.img ] && mv $BTTARGETDIR/oginitrd.img $BTTARGETDIR/oginitrd.img.$TIMEMOD; mv $BTTARGETDIR/oginitrd.img.sum $BTTARGETDIR/oginitrd.img.sum.$TIMEMOD |
---|
| 365 | [ -f $BTTARGETDIR/ogvmlinuz ] && mv $BTTARGETDIR/ogvmlinuz $BTTARGETDIR/ogvmlinuz.$TIMEMOD; mv $BTTARGETDIR/ogvmlinuz.sum $BTTARGETDIR/ogvmlinuz.sum.$TIMEMOD |
---|
| 366 | |
---|
| 367 | #copiando |
---|
[27ee376] | 368 | cp /tmp/initrd.img-${OSRELEASE} ${BTTARGETDIR}/oginitrd.img |
---|
[83d87a3] | 369 | cp /tmp/vmlinuz-${OSRELEASE} ${BTTARGETDIR}/ogvmlinuz |
---|
[841ce50] | 370 | #generamos md5 del kernel y del initrd. |
---|
| 371 | DATASUM=`md5sum "${BTTARGETDIR}/oginitrd.img" | cut -f1 -d" "` |
---|
| 372 | echo $DATASUM > ${BTTARGETDIR}/oginitrd.img.sum |
---|
| 373 | DATASUM=`md5sum "${BTTARGETDIR}/ogvmlinuz" | cut -f1 -d" "` |
---|
| 374 | echo $DATASUM > ${BTTARGETDIR}/ogvmlinuz.sum |
---|
| 375 | #Damos permisos |
---|
[00a2c2c] | 376 | cd - |
---|
[841ce50] | 377 | chmod -R 755 $BTTARGETDIR |
---|
[00a2c2c] | 378 | } |
---|
| 379 | |
---|
[27ee376] | 380 | #btogFsSqfs convierte el sistema root en sqfs |
---|
[00a2c2c] | 381 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
| 382 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 383 | #@date 2010/05/24 |
---|
| 384 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
| 385 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 386 | #@date 2011/08/03 |
---|
[27ee376] | 387 | function btogFsSqfs () |
---|
[00a2c2c] | 388 | { |
---|
| 389 | #Dependencias. |
---|
[841ce50] | 390 | [ -z "$BTROOTFSIMG" ] && btogGetVar |
---|
[5bcd021] | 391 | [ -z "$OSCODENAME" ] && btogGetOsInfo $TYPECLIENT |
---|
[00a2c2c] | 392 | |
---|
| 393 | echoAndLog "$FUNCNAME: Iniciando la creación del sistema de archivos en sqfs " |
---|
| 394 | # si ya existe un sqfs lo renombramos |
---|
[27ee376] | 395 | [ -f $BTTARGETDIR/ogclient.sqfs ] && mv $BTTARGETDIR/ogclient.sqfs $BTTARGETDIR/ogclient.sqfs.`date +%Y%m%d-%H%M%S` |
---|
| 396 | mount | grep $BTROOTFSMNT || mount $BTROOTFSIMG $BTROOTFSMNT -o loop,offset=32256 |
---|
| 397 | mksquashfs $BTROOTFSMNT $BTTARGETDIR/ogclient.sqfs |
---|
| 398 | mount | grep $BTROOTFSMNT && umount $BTROOTFSMNT |
---|
[841ce50] | 399 | chmod 744 $BTTARGETDIR/ogclient.sqfs |
---|
| 400 | DATASUM=`md5sum "${BTTARGETDIR}/ogclient.sqfs" | cut -f1 -d" "` |
---|
| 401 | echo $DATASUM > ${BTTARGETDIR}/ogclient.sqfs.sum |
---|
[00a2c2c] | 402 | } |
---|
| 403 | |
---|
| 404 | |
---|
| 405 | |
---|
| 406 | |
---|
| 407 | |
---|
| 408 | # btogIsoGenerator genera la iso del cliente |
---|
| 409 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
| 410 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 411 | #@date 2010/05/24 |
---|
| 412 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
| 413 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 414 | #@date 2011/08/03 |
---|
| 415 | function btogIsoGenerator { |
---|
[841ce50] | 416 | #Dependencias. |
---|
| 417 | #[ -z "$BTROOTFSIMG" ] && btogGetVar |
---|
| 418 | btogGetVar |
---|
| 419 | #Preparamos los gestores de arranque |
---|
[00a2c2c] | 420 | mkdir -p /tmp/iso/isolinux |
---|
[98cd714c] | 421 | cp -av /usr/lib/syslinux/* /tmp/iso/isolinux/ |
---|
[11364a6] | 422 | if [ -d /usr/share/gpxe ]; then |
---|
| 423 | cp -av /usr/share/gpxe/* /tmp/iso/isolinux |
---|
| 424 | PXE=gpxe |
---|
| 425 | elif [ -d /usr/lib/ipxe ]; then |
---|
| 426 | cp -av /usr/lib/ipxe/* /tmp/iso/isolinux |
---|
| 427 | PXE=ipxe |
---|
| 428 | fi |
---|
[98cd714c] | 429 | |
---|
[11364a6] | 430 | # Si existe el fichero ISO, montarlo para extraer isolinux.bin. |
---|
| 431 | if [ -f /tmp/iso/isolinux/$PXE.iso ]; then |
---|
[98cd714c] | 432 | mkdir -p /tmp/iso/isolinux/mount |
---|
[11364a6] | 433 | mount -o loop /tmp/iso/isolinux/$PXE.iso /tmp/iso/isolinux/mount |
---|
[98cd714c] | 434 | cp -va /tmp/iso/isolinux/mount/* /tmp/iso/isolinux |
---|
| 435 | umount /tmp/iso/isolinux/mount |
---|
| 436 | rmdir /tmp/iso/isolinux/mount |
---|
[11364a6] | 437 | rm -f /tmp/iso/isolinux/$PXE.iso |
---|
[98cd714c] | 438 | fi |
---|
[00a2c2c] | 439 | |
---|
| 440 | cat << FIN > /tmp/iso/isolinux/isolinux.cfg |
---|
| 441 | DEFAULT menu.c32 |
---|
| 442 | PROMPT 0 |
---|
| 443 | ALLOWOPTIONS 1 |
---|
| 444 | |
---|
[841ce50] | 445 | MENU TITLE OpenGnsys ${NAMEISOCLIENT} |
---|
[00a2c2c] | 446 | |
---|
| 447 | |
---|
| 448 | LABEL 0 |
---|
[308f61c] | 449 | MENU LABEL ogLive vga irqpool acpi ogdebug ip:none |
---|
[00a2c2c] | 450 | KERNEL /ogclient/linuxISO |
---|
| 451 | APPEND initrd=/ogclient/oginitrd.img ro vga=788 irqpoll acpi=on boot=oginit og2nd=sqfs ogprotocol=local ogactiveadmin=true ogdebug=true ip=none |
---|
| 452 | |
---|
| 453 | LABEL 1 |
---|
[308f61c] | 454 | MENU LABEL ogLive irqpoll acpi ip:none |
---|
[00a2c2c] | 455 | KERNEL /ogclient/linuxISO |
---|
| 456 | APPEND initrd=/ogclient/oginitrd.img ro irqpoll acpi=on boot=oginit og2nd=sqfs ogprotocol=local ogactiveadmin=true ogdebug=false ip=none |
---|
| 457 | |
---|
| 458 | LABEL 2 |
---|
[308f61c] | 459 | MENU LABEL ogLive acpi debug ip=dhcp |
---|
[00a2c2c] | 460 | KERNEL /ogclient/linuxISO |
---|
| 461 | APPEND initrd=/ogclient/oginitrd.img ro acpi=on boot=oginit og2nd=sqfs ogprotocol=local ogactiveadmin=true ogdebug=true ip=dhcp |
---|
| 462 | |
---|
| 463 | LABEL 3 |
---|
[308f61c] | 464 | MENU LABEL ogLive ip=dhcp |
---|
[00a2c2c] | 465 | KERNEL /ogclient/linuxISO |
---|
| 466 | APPEND initrd=/ogclient/oginitrd.img ro acpi=off boot=oginit og2nd=sqfs ogprotocol=local ogactiveadmin=true ogdebug=false ip=dhcp |
---|
| 467 | |
---|
| 468 | LABEL 4 |
---|
| 469 | MENU LABEL local |
---|
| 470 | localboot 0x80 |
---|
| 471 | append - |
---|
| 472 | |
---|
| 473 | label 5 |
---|
| 474 | MENU LABEL Network boot via gPXE lkrn |
---|
[11364a6] | 475 | KERNEL $PXE.lkrn |
---|
[00a2c2c] | 476 | |
---|
[27ee376] | 477 | label 6 |
---|
[00a2c2c] | 478 | MENU LABEL Network boot via gPXE usb |
---|
[11364a6] | 479 | KERNEL $PXE.usb |
---|
[00a2c2c] | 480 | |
---|
[27ee376] | 481 | label 7 |
---|
[00a2c2c] | 482 | MENU LABEL Network boot via gPXE pxe |
---|
[11364a6] | 483 | KERNEL $PXE.pxe |
---|
[00a2c2c] | 484 | |
---|
[27ee376] | 485 | label 8 |
---|
[00a2c2c] | 486 | MENU LABEL Network boot via gPXE iso |
---|
[11364a6] | 487 | KERNEL $PXE.iso |
---|
[308f61c] | 488 | |
---|
| 489 | label 9 |
---|
[11364a6] | 490 | MENU LABEL pxe |
---|
[308f61c] | 491 | KERNEL /clonezilla/live/vmlinuz1 |
---|
| 492 | APPEND initrd=/clonezilla/live/initrd1.img boot=live union=aufs noswap vga=788 ip=frommedia |
---|
[00a2c2c] | 493 | FIN |
---|
[841ce50] | 494 | |
---|
| 495 | |
---|
| 496 | |
---|
| 497 | |
---|
| 498 | # preparamos el directorio boot-tools. |
---|
| 499 | mkdir -p /tmp/iso/ogclient |
---|
| 500 | cp ${BTTARGETDIR}/ogclient.sqfs /tmp/iso/ogclient/ |
---|
| 501 | cp ${BTTARGETDIR}/ogclient.sqfs.sum /tmp/iso/ogclient/ |
---|
| 502 | cp ${BTTARGETDIR}/ogvmlinuz /tmp/iso/ogclient/ |
---|
| 503 | cp ${BTTARGETDIR}/ogvmlinuz.sum /tmp/iso/ogclient/ |
---|
| 504 | cp ${BTTARGETDIR}/ogvmlinuz /tmp/iso/ogclient/linuxISO |
---|
| 505 | cp ${BTTARGETDIR}/ogvmlinuz.sum /tmp/iso/ogclient/linuxISO.sum |
---|
| 506 | cp ${BTTARGETDIR}/oginitrd.img /tmp/iso/ogclient/ |
---|
| 507 | cp ${BTTARGETDIR}/oginitrd.img.sum /tmp/iso/ogclient/ |
---|
| 508 | #el ogclienteToISO debe tener una copia del ogvmlinuz como linuxISO |
---|
| 509 | #cp -prv /var/lib/tftpboot/ogclientToIso/* /tmp/iso/ogclient |
---|
| 510 | |
---|
| 511 | cd /tmp |
---|
| 512 | #TIMEMOD=`date +%Y%m%d-%H%M%S` |
---|
| 513 | ####Generamos la iso |
---|
| 514 | echo "mkisofs -V ogClient -o ${NAMEISOCLIENT}.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -J -no-emul-boot -boot-load-size 4 -boot-info-table /tmp/iso" |
---|
| 515 | mkisofs -V ogClient -o ${NAMEISOCLIENT}.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -J -no-emul-boot -boot-load-size 4 -boot-info-table /tmp/iso |
---|
| 516 | ##Generamos el md5 |
---|
| 517 | DATASUM=`md5sum ${NAMEISOCLIENT}.iso | cut -f1 -d" "` |
---|
| 518 | echo $DATASUM > ${NAMEISOCLIENT}.iso.sum |
---|
| 519 | |
---|
[82ae131] | 520 | mv /tmp/${NAMEISOCLIENT}.iso /var/lib/tftpboot/ogclient/ |
---|
| 521 | mv /tmp/${NAMEISOCLIENT}.iso.sum /var/lib/tftpboot/ogclient/ |
---|
| 522 | |
---|
[00a2c2c] | 523 | |
---|
| 524 | ### vi /etc/grub.d/40_custom |
---|
| 525 | ## |
---|
| 526 | #menuentry "og cache " { |
---|
| 527 | #set root=(hd0,4) |
---|
| 528 | #linux /ogvmlinuz ro vga=788 irqpoll acpi=on boot=oginit og2nd=sqfs ogprotocol=local ogactiveadmin=true ogdebug=true ip=none |
---|
| 529 | #initrd /oginitrd.img |
---|
| 530 | #} |
---|
| 531 | |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | |
---|
| 535 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
| 536 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 537 | #@date 2010/05/24 |
---|
| 538 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
| 539 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
| 540 | #@date 2011/08/03 |
---|
| 541 | function btogIsoTest { |
---|
| 542 | #/tmp/iso |
---|
| 543 | qemu -m 256 -boot d -cdrom ogClient.iso |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | |
---|
| 547 | |
---|
| 548 | |
---|
| 549 | function getDateTime() |
---|
| 550 | { |
---|
| 551 | echo `date +%Y%m%d-%H%M%S` |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | # Escribe a fichero y muestra por pantalla |
---|
| 555 | function echoAndLog() |
---|
| 556 | { |
---|
| 557 | echo $1 |
---|
| 558 | FECHAHORA=`getDateTime` |
---|
| 559 | echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | function errorAndLog() |
---|
| 563 | { |
---|
| 564 | echo "ERROR: $1" |
---|
| 565 | FECHAHORA=`getDateTime` |
---|
| 566 | echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | |
---|
| 570 | |
---|
| 571 | |
---|
| 572 | |
---|
| 573 | |
---|
| 574 | |
---|
| 575 | |
---|
| 576 | |
---|
| 577 | |
---|
| 578 | ############### No usados en el instalador, solo en actualizaciones. |
---|
| 579 | #/** |
---|
| 580 | # ogClientMount [str_program] |
---|
| 581 | #@brief Acceso al 2nd FS del cliente desde el Servidor Opengnsys |
---|
| 582 | #@param 1 Opciona: scripts o programa a ejecutar para automatizaciones |
---|
| 583 | #@return Si no hay parametros: login de acceso. |
---|
| 584 | #@return con un parametro: La salida del programa ejecutado |
---|
| 585 | #@exception |
---|
| 586 | #@note |
---|
| 587 | #@todo |
---|
| 588 | #@version 0.9 - Primera versión para OpenGnSys |
---|
| 589 | #@author Antonio J. Doblas Viso, Universidad de Málaga |
---|
| 590 | #@date 2010/02/15 |
---|
| 591 | #*/ ## |
---|
| 592 | function ogClientMount () |
---|
| 593 | { |
---|
| 594 | #TODO comprobar que OGFILE y OGFILEMOUNT existe. |
---|
| 595 | mount | grep $OGCLIENTFILE > /dev/null || mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256 |
---|
| 596 | mount | grep $OGCLIENTMOUNT/proc > /dev/null || mount --bind /proc $OGCLIENTMOUNT/proc |
---|
| 597 | mount | grep $OGCLIENTMOUNT/sys > /dev/null || mount --bind /sys $OGCLIENTMOUNT/sys |
---|
| 598 | mount | grep $OGCLIENTMOUNT/tmp > /dev/null || mount --bind /tmp $OGCLIENTMOUNT/tmp |
---|
| 599 | mount | grep $OGCLIENTMOUNT/dev > /dev/null || mount --bind /dev $OGCLIENTMOUNT/dev |
---|
| 600 | mount | grep $OGCLIENTMOUNT/dev/pts > /dev/null || mount --bind /dev/pts $OGCLIENTMOUNT/dev/pts |
---|
| 601 | |
---|
| 602 | |
---|
| 603 | [ $# = 0 ] && $(chroot $OGCLIENTMOUNT /sbin/getty 38400 `tty`) |
---|
| 604 | [ $# = 1 ] && chroot $OGCLIENTMOUNT $1 |
---|
| 605 | |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | #/** |
---|
| 609 | # ogClientUnmount |
---|
| 610 | #@brief Desmonta el 2nd FS del cliente desde el Servidor Opengnsys |
---|
| 611 | #@param |
---|
| 612 | #@return |
---|
| 613 | #@exception |
---|
| 614 | #@note |
---|
| 615 | #@todo |
---|
| 616 | #@version 0.9 - Primera versión para OpenGnSys |
---|
| 617 | #@author Antonio J. Doblas Viso, Universidad de Málaga |
---|
| 618 | #@date 2010/02/15 |
---|
| 619 | #*/ ## |
---|
| 620 | |
---|
| 621 | function ogClientUnmount () |
---|
| 622 | { |
---|
| 623 | cd /tmp |
---|
| 624 | echo "desmontando cliente espere" |
---|
| 625 | sleep 5 |
---|
| 626 | mount | grep $OGCLIENTMOUNT/dev > /dev/null && umount $OGCLIENTMOUNT/dev || ogClientUnmount |
---|
| 627 | mount | grep $OGCLIENTMOUNT/dev/pts > /dev/null && umount $OGCLIENTMOUNT/dev/pts || ogClientUnmount |
---|
| 628 | mount | grep $OGCLIENTMOUNT/proc > /dev/null && umount $OGCLIENTMOUNT/proc || ogClientUnmount |
---|
| 629 | mount | grep $OGCLIENTMOUNT/sys > /dev/null && umount $OGCLIENTMOUNT/sys || ogClientUnmount |
---|
| 630 | mount | grep $OGCLIENTMOUNT/tmp > /dev/null && umount $OGCLIENTMOUNT/tmp || ogClientUnmount |
---|
| 631 | mount | grep $OGCLIENTMOUNT > /dev/null && umount $OGCLIENTMOUNT || ogClientUnmount |
---|
| 632 | #-d -f -l |
---|
| 633 | |
---|
| 634 | } |
---|