diff --git a/Dockerfile b/Dockerfile index ccab095..7e0169a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ RUN git clone -c http.sslVerify=false --branch ${OPENGNSYS_BRANCH} https://ognpr git --git-dir /tmp/ogrepo/.git log --date format:r%Y%m%d --format=%ad -1 >/tmp/opengnsys/oglive_builder/gitrelease && \ rm -rf /tmp/ogrepo/ -RUN echo foo2 ## development: invalidate docker cache at this point, so that the 'COPY' below actually copies files +#RUN echo 0 ## development: invalidate docker cache at this point, so that the 'COPY' below actually copies files COPY . /tmp/opengnsys/oglive_builder/ RUN cp /tmp/opengnsys/oglive_builder/schroot.conf /tmp/opengnsys/oglive_builder/mount-defaults /etc/schroot/ && echo '' >/etc/schroot/default/nssdatabases && rm -f /etc/schroot/setup.d/*chrootname diff --git a/INSTALL.es.txt b/INSTALL.es.txt index 6645796..86e7396 100644 --- a/INSTALL.es.txt +++ b/INSTALL.es.txt @@ -4,43 +4,37 @@ OpenGnsys Client boot-tools INSTALL.es.txt Advertencia previa: ----------------------------- -- No usar este instalador en un sistema OpenGnsys en producción. - Se puede ejecutar este script desde un sistema Ubuntu 10.04 o superior. - Mas información https://opengnsys.es/trac/wiki/ClienteInitrdDSGenerarloV1.0.2 Requisitos iniciales -------------------- -- Utilizar el usuario "root" para ejecutar el proceso de generación del cliente. - Comprobar la conexión a Internet, sobre todo si usas proxy (el hecho de que funcione apt-get no significa que tengas el proxy configurado). -Proceso de instalación ----------------------- +Proceso de creación de imagen docker +------------------------------------ -#0. Si ya tenemos configurado TFTP, renombrar el directorio /var/lib/tftpboot/ogclient. -mv /opt/opengnsys/tftpboot/ogclient /opt/opengnsys/tftpboot/ogclient-old; +Simplemente llamar a docker build sin sorpresas: -#1. Descargar del Subversion las herramientas del cliente -apt-get install subversion wget -svn checkout https://opengnsys.es/svn/branches/version1.1/client /tmp/opengnsys_installer/opengnsys/client/; -find /tmp/opengnsys_installer/ -name .svn -type d -exec rm -fr {} \; 2>/dev/null; + docker build -t mkoglive . -#2. Ejecutar el instalador: -/tmp/opengnsys_installer/opengnsys/client/boot-tools/boottoolsgenerator.sh; +Si queremos usar una rama diferente del repo de opengnsys: -Notas para ejecución del instalador en Ubuntu 12.10: -- Configuración openssh-client: - - *** ssh_config (Y/I/N/O/D/Z) [default=N] ? [intro] -- Mapa de caracteres: - - Pantalla "Configuring console-data": elegir "Select keymap from full list" - - Keymap: pc / qwerty / Spanish / Standard / Standard -- Clave publica del servidor - - verwrite (y/n)? [intro] -- Mapa de caracteres (repetición): - - Pantalla "Configuring console-data": - - Select keymap from full list - - pc / qwerty / Spanish / Standard / Standard, UTF-8, Combined - Latin; Slavic Cyrillic; Greek, Fixed, 16 + docker build --build-arg OPENGNSYS_BRANCH=mybranch -t mkoglive . + + +Proceso de creación de imagen oglive +------------------------------------ + + docker run --rm --name mkoglive --privileged=true --volume $PWD/ogclient:/var/lib/tftpboot/ogclient mkoglive --codename noble + +Hace falta --privileged=true para que mkoglive.py pueda ejecutar, entre otras cosas, losetup. + +El parámetro --codename permite especificar la versión de ubuntu. + +Las imágenes se crean en ./ogclient. @@ -48,14 +42,15 @@ Descripción de la estrucutra de boot-tools ------------------------------------------ - INSTALL.es.txt este mismo archivo. -- boottollsgenerator.sh proceso de generación del sistema operativo opengnsys. -- boottoolsfunctions.lib libreria complementaria del boottolsgenerator.sh -- includes/ directorio con ficheros específicos para incluir en la distribución. - - - -NOTA: - boottollsfuncions.lib -> btogSetfsBase - bootsoftwareinstall -> - packages ->sw.testing - +- mkoglive: + - mkoglive.py script principal para crear la imagen oglive + - mkoglive.cfg configuración de mkoglive.py + - boottools/ libreria complementaria del mkoglive.py + - includes/ directorio con ficheros específicos para incluir en la distribución +- schroot: + - schroot.conf configuración de schroot + - mount-defaults configuración de puntos de montaje para schroot + - chroot-tasks.py helper para configurar el oglive estando en schroot +- docker: + - Dockerfile para crear una imagen docker + - .dockerignore para limitar el contexto de docker-build diff --git a/boottools/btog.py b/boottools/btog.py index 3b85b76..e1e7bf9 100644 --- a/boottools/btog.py +++ b/boottools/btog.py @@ -193,8 +193,7 @@ def mkrootfs (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, btt logger.info (f'"{btrootfsimg}" "{btvirtualdisksize}" MB : OK') -# debootstrap: Genera el sistema root base con debootstrap -# trabaja sobre un rootfs ya montado +# works on an already mounted rootfs def debootstrap (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp): logger.info ('Iniciando la generación del sistema de archivos') @@ -245,23 +244,22 @@ def copy_og_files (builder, og_shared, og_engine, ogclientmount, osdistrib, osco if os.path.exists (f'{og_shared}/bin/ogAdmClient'): shutil.copy (f'{og_shared}/bin/ogAdmClient', f'{ogclientmount}/bin/') def ssh_server (btrootfsmnt): - if not os.path.exists ('/root/.ssh/id_rsa'): ## crea un par de claves en la VM, no en el chroot + if not os.path.exists ('/root/.ssh/id_rsa'): ## creates a key pair in the VM (or docker container), not in the chroot utils.run (['ssh-keygen', '-q', '-f', '/root/.ssh/id_rsa', '-N', '']) logger.debug ('comprobando directorio .ssh del root') - if not os.path.exists (f'{btrootfsmnt}/root/.ssh'): ## crea directorio dentro del chroot + if not os.path.exists (f'{btrootfsmnt}/root/.ssh'): ## creates directory within the chroot logger.debug ('creando directorio .ssh 600') os.mkdir (f'{btrootfsmnt}/root/.ssh') os.chmod (f'{btrootfsmnt}/root/.ssh', 0o700) - logger.debug ('creando el fichero authorized_keys') ## crea archivo en el chroot + logger.debug ('creando el fichero authorized_keys') ## creates file within the chroot if not os.path.exists (f'{btrootfsmnt}/root/.ssh/authorized_keys'): open (f'{btrootfsmnt}/root/.ssh/authorized_keys', 'w').close() os.chmod (f'{btrootfsmnt}/root/.ssh/authorized_keys', 0o600) logger.debug ('importando la clave publica del servidor OG') - #cat /tmp/id_rsa.pub - if os.path.exists ('/root/.ssh/id_rsa.pub'): ## coge la publica de la VM y la pone en el authorized_keys del chroot + if os.path.exists ('/root/.ssh/id_rsa.pub'): ## takes the pubkey from the VM (or docker container) and puts it in the authorized_keys within the chroot fdin = open ('/root/.ssh/id_rsa.pub', 'r') fdout = open (f'{btrootfsmnt}/root/.ssh/authorized_keys', 'a') while True: @@ -276,9 +274,9 @@ def ssh_server (btrootfsmnt): def ssh_client (btrootfsmnt): if not os.path.exists (f'{btrootfsmnt}/root/.ssh/id_rsa'): - utils.run (['ssh-keygen', '-q', '-f', f'{btrootfsmnt}/root/.ssh/id_rsa', '-N', '']) ## crea un par de claves en el chroot + utils.run (['ssh-keygen', '-q', '-f', f'{btrootfsmnt}/root/.ssh/id_rsa', '-N', '']) ## creates a key pair in the chroot - #cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys ## coge la publica y se la autoriza a sí mismo + #cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys ## takes the pubkey and authorises it to itself fdin = open (f'{btrootfsmnt}//root/.ssh/id_rsa.pub', 'r') fdout = open (f'{btrootfsmnt}/root/.ssh/authorized_keys', 'a') while True: @@ -291,11 +289,7 @@ def ssh_client (btrootfsmnt): ## TODO: exportamos la publica a los repos #cp /root/.ssh/id_rsa.pub /tmp/rsa.ogclient.pub -#move_initrd genera un initrd. def move_initrd (bttargetdir, osrelease): - #echo "cp /tmp/*-${OSRELEASE} ${BTTARGETDIR}" - #cp /tmp/*-${OSRELEASE} ${BTTARGETDIR} ## esto copia algo?? - ## backup de oginitrd.img, oginitrd.img.sum, ogvmlinuz y ogvmlinuz.sum now = datetime.datetime.now(datetime.timezone.utc).strftime ('%Y%m%d-%H%M%S%z') if os.path.exists (f'{bttargetdir}/oginitrd.img'): @@ -315,11 +309,9 @@ def move_initrd (bttargetdir, osrelease): for f in glob.glob (f'{bttargetdir}/oginitrd*') + glob.glob (f'{bttargetdir}/vmlinuz*'): os.chmod (f, 0o755) -#mksquashfs convierte el sistema root en sqfs def mksquashfs (bttargetdir, btrootfsmnt): logger.info ('Iniciando la creación del sistema de archivos en sqfs') - # si ya existe un sqfs lo renombramos if os.path.exists (f'{bttargetdir}/ogclient.sqfs'): now = datetime.datetime.now(datetime.timezone.utc).strftime ('%Y%m%d-%H%M%S%z') os.rename (f'{bttargetdir}/ogclient.sqfs', f'{bttargetdir}/ogclient.sqfs.{now}') @@ -330,7 +322,6 @@ def mksquashfs (bttargetdir, btrootfsmnt): utils.write_md5 (f'{bttargetdir}/ogclient.sqfs') -# mkisofs genera la iso del cliente def mkisofs (pxepkg, isolinux_tpl, bttargetdir, nameisoclient): #Preparamos los gestores de arranque try: os.makedirs ('/tmp/iso/isolinux', exist_ok=True) diff --git a/boottools/utils.py b/boottools/utils.py index 5e0a7fc..37dc0ce 100644 --- a/boottools/utils.py +++ b/boottools/utils.py @@ -16,27 +16,20 @@ def run (args): sel.register (p.stderr.fileno(), selectors.EVENT_READ) while True: events = sel.select() - #logger.debug (f'got {len(events)} events') for key, _ in events: if key.fileobj == p.stdout.fileno(): - #logger.debug (f'reading from stdout') line = p.stdout.readline() if not line: break stdout += line logger.debug (line.rstrip()) elif key.fileobj == p.stderr.fileno(): - #logger.debug (f'reading from stderr') line = p.stderr.readline() if not line: break stderr += line logger.warn (line.rstrip()) if p.poll() != None: - #logger.debug ('process exited, breaking loop') break sel.close() - #p.stdout.close() - #p.stderr.close() - #p.wait() stdout = stdout.strip() stderr = stderr.strip() diff --git a/chroot-tasks.py b/chroot-tasks.py index bcdd9d9..e2ce26a 100755 --- a/chroot-tasks.py +++ b/chroot-tasks.py @@ -32,13 +32,13 @@ def boottoolsSoftwareInstall (osarch, osrelease): pkgs32 = [] if 'i386' != osarch: utils.run (['dpkg', '--add-architecture', 'i386']) - pkgs32 = 'lib32gcc-s1 lib32stdc++6 lib32z1 libc6-i386'.split (' ') ## he cambiado lib32gcc1 por lib32gcc-s1 pero como queramos crear un oglive viejo, esto va a petar + pkgs32 = 'lib32gcc-s1 lib32stdc++6 lib32z1 libc6-i386'.split (' ') ## nserrano: he cambiado lib32gcc1 por lib32gcc-s1 pero como queramos crear un oglive viejo, esto va a petar _oghook_deactivate() print ('boottoolsSoftwareInstall: debconf-set-selections', file=sys.stderr) subprocess.run (['debconf-set-selections'], input=debconf_settings, text=True) - utils.run (['dpkg-reconfigure', '--frontend', 'noninteractive', 'console-setup', 'locales']) ## despues de esto, debconf-get-selections devuelve los valores antiguos, no se por que... + utils.run (['dpkg-reconfigure', '--frontend', 'noninteractive', 'console-setup', 'locales']) ## XXX: despues de esto, debconf-get-selections devuelve los valores antiguos, no se por que... pkgs = [] for section in config.options('Packages'): @@ -46,7 +46,7 @@ def boottoolsSoftwareInstall (osarch, osrelease): pkgs = [f'linux-image-{osrelease}', f'linux-headers-{osrelease}', f'linux-modules-{osrelease}', f'linux-modules-extra-{osrelease}', 'dkms', 'shim-signed', 'openssl', 'sshfs', 'kexec-tools'] + pkgs32 + pkgs print (f'boottoolsSoftwareInstall: installing packages: {str(pkgs)}', file=sys.stderr) - apt.install (pkgs, opts={'DPkg::Options::': '--force-confdef'}) ## hace falta --force-confdef para evitar un tema interactivo del /etc/ssh/ssh_config + apt.install (pkgs, opts={'DPkg::Options::': '--force-confdef'}) ## --force-confdef is required to avoid an interactive question regarding /etc/ssh/ssh_config # Instalar módulos que algunos paquetes puedan tener pendientes de compilar. print ('boottoolsSoftwareInstall: dkms', file=sys.stderr) diff --git a/mkoglive.py b/mkoglive.py index 0151645..095e435 100755 --- a/mkoglive.py +++ b/mkoglive.py @@ -37,7 +37,6 @@ def _mount_rootfs (btrootfsimg, btrootfsmnt): sys.exit (1) def _get_pxepkg(): - #grep "http://free.nchc.org.tw/drbl-core" /etc/apt/sources.list || echo "deb http://free.nchc.org.tw/drbl-core drbl stable" >> /etc/apt/sources.list pxepkg = None cache = apt.cache_search (['gpxe', 'ipxe']) if cache['gpxe']: pxepkg = 'gpxe' @@ -57,9 +56,6 @@ def _mkrootfs (btrootfsimg, btrootfsmnt, btrootfsimglabel, btvirtualdisksize, bt logger.error (str (e)) sys.exit (1) -## para hacer schroot --cosas, el mntpt tiene que estar desmontado -## si está montado da un pete tal que 'E: 10mount: mount: /run/schroot/mount/IMGogclient-7fbf51a2-e37e-48e5-8e5d-83f8901fc7ed: wrong fs type, bad option, bad superblock on /dev/loop1, missing codepage or helper program, or other error.' - def _debootstrap (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp): logger.info ('Stage 1.2 - debootstrap system') logger.debug ('Try creation of a file within chroot (this operation may fail with "... etc/resolv.conf: No such file or directory"--that is ok)') @@ -73,10 +69,7 @@ def _debootstrap (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp): logger.error (str (e)) sys.exit (1) -# Incluir revisión. def _initramfs_version (gitrelease, osrelease, curdir): - ## FIXME esto la incluye incondicionalmente, y luego terminamos con "OpenGnsys Client 1.2.0-rc1 gitrelease (osrelease) gitrelease (osrelease) gitrelease (osrelease) gitrelease (osrelease) gitrelease (osrelease) gitrelease (osrelease) ..." - #sed -i "1 s/$/ $GITRELEASE ($OSRELEASE)/" ${BTDIR}/includes/etc/initramfs-tools/scripts/VERSION.txt utils.run (['sed', '-i', f'1 s/$/ {gitrelease} ({osrelease})/', f'{curdir}/includes/etc/initramfs-tools/scripts/VERSION.txt']) def _copy_og_files (btrootfsimg, btrootfsmnt, osdistrib, oscodename): @@ -90,17 +83,17 @@ def _copy_og_files (btrootfsimg, btrootfsmnt, osdistrib, oscodename): def _chroot_tasks (cfgfile, curdir, osrelease, osarch): logger.debug (f'running \'schroot --chroot IMGogclient -- {curdir}/chroot-tasks.py --osrelease "{osrelease}" --osarch "{osarch}"\'') stdout, _ = utils.run (['schroot', '--chroot', 'IMGogclient', '--', f'{curdir}/chroot-tasks.py', '--osrelease', osrelease, '--osarch', osarch, '--config', cfgfile]) - ## esto deja initrd.img-6.8.0-31-generic y vmlinuz-6.8.0-31-generic en /tmp + ## this leaves initrd.img-6.8.0-31-generic and vmlinuz-6.8.0-31-generic in /tmp def _ssh_stuff (btrootfsimg, btrootfsmnt): _mount_rootfs (btrootfsimg, btrootfsmnt) btog.ssh_server (btrootfsmnt) btog.ssh_client (btrootfsmnt) utils.umount (btrootfsmnt) - ## el resultado es: - ## - hay un nuevo par de claves en la VM /root/.ssh - ## - hay otro nuevo par de claves en el rootfs /var/lib/tftpboot/ogclient/ogclientmount/root/.ssh - ## - las dos claves públicas (una de cada par) están autorizadan en el rootfs /var/lib/tftpboot/ogclient/ogclientmount/root/.ssh/authorized_keys + ## the end result is: + ## - there's a new key pair in the VM (or docker container), in /root/.ssh + ## - there's another new key pair in the rootfs, in /var/lib/tftpboot/ogclient/ogclientmount/root/.ssh + ## - the two pubkeys (one of each pair) end up being authorised in the rootfs, in /var/lib/tftpboot/ogclient/ogclientmount/root/.ssh/authorized_keys def _mkinitrd_squashfs_isofs (bttargetdir, osrelease, btrootfsimg, btrootfsmnt, pxepkg, isolinux_tpl, nameisoclient): logger.info ('Stage 4.1 - Put initrd in place')