Example #1
0
 def import_overlay_files(
     self, follow_links=False, preserve_owner_group=False
 ):
     """
         copy overlay files from the image description to
         the image root tree. Supported are a root/ directory
         or a root.tar.gz tarball. The root/ directory takes
         precedence over the tarball
     """
     overlay_directory = self.description_dir + '/root/'
     overlay_archive = self.description_dir + '/root.tar.gz'
     if os.path.exists(overlay_directory):
         log.info('Copying user defined files to image tree')
         rsync_options = [
             '-r', '-p', '-t', '-D', '-H', '-X', '-A', '--one-file-system'
         ]
         if follow_links:
             rsync_options.append('--copy-links')
         else:
             rsync_options.append('--links')
         if preserve_owner_group:
             rsync_options.append('-o')
             rsync_options.append('-g')
         Command.run(
             ['rsync'] + rsync_options + [
                 overlay_directory, self.root_dir
             ]
         )
     elif os.path.exists(overlay_archive):
         log.info('Extracting user defined files from archive to image tree')
         archive = ArchiveTar(overlay_archive)
         archive.extract(self.root_dir)
Example #2
0
    def create_image_format(self):
        self.temp_image_dir = mkdtemp(
            dir=self.target_dir
        )
        diskname = ''.join(
            [
                self.target_dir, '/',
                self.xml_state.xml_data.get_name(), '.raw'
            ]
        )
        Command.run(
            ['cp', diskname, self.temp_image_dir + '/disk.raw']
        )
        if self.tag:
            with open(self.temp_image_dir + '/manifest.json', 'w') as manifest:
                manifest.write('{"licenses":["%s"]}' % self.tag)

        archive_name = self.get_target_name_for_format('gce')

        # delete the '.gz' suffix from the name. The suffix is appended by
        # the archive creation method depending on the creation type.
        archive_name = archive_name.replace('.gz', '')

        archive = ArchiveTar(
            self.target_dir + '/' + archive_name
        )
        archive.create_gnu_gzip_compressed(
            self.temp_image_dir
        )
Example #3
0
 def __install_archives(self, archive_list):
     log.info("Installing archives")
     for archive in archive_list:
         log.info("--> archive: %s", archive)
         tar = ArchiveTar(self.xml_state.xml_data.description_dir + '/' +
                          archive)
         tar.extract(self.root_bind.root_dir)
Example #4
0
 def __install_archives(self, archive_list):
     log.info("Installing archives")
     for archive in archive_list:
         log.info("--> archive: %s", archive)
         tar = ArchiveTar(
             self.xml_state.xml_data.description_dir + '/' + archive
         )
         tar.extract(self.root_bind.root_dir)
Example #5
0
 def create(self, filename):
     exclude_list = [
         'image', '.profile', '.kconfig', 'var/cache/kiwi', 'boot'
     ]
     # replace potential suffix from filename because
     # it is added by the archive creation call
     archive = ArchiveTar(filename.replace('.xz', ''))
     archive.create_xz_compressed(source_dir=self.root_dir,
                                  exclude=exclude_list)
Example #6
0
 def create(self, filename):
     exclude_list = [
         'image', '.profile', '.kconfig', 'var/cache/kiwi', 'boot'
     ]
     # replace potential suffix from filename because
     # it is added by the archive creation call
     archive = ArchiveTar(
         filename.replace('.xz', '')
     )
     archive.create_xz_compressed(
         source_dir=self.root_dir, exclude=exclude_list
     )
Example #7
0
    def create(self):
        supported_archives = Defaults.get_archive_image_types()
        if self.requested_archive_type not in supported_archives:
            raise KiwiArchiveSetupError('Unknown archive type: %s' %
                                        self.requested_archive_type)

        if self.requested_archive_type == 'tbz':
            log.info('Creating XZ compressed tar archive')
            archive = ArchiveTar(self.__target_file_for('tar'))
            archive.create_xz_compressed(self.root_dir)
            checksum = Checksum(self.filename)
            log.info('--> Creating archive checksum')
            checksum.md5(self.checksum)
            self.result.add('root_archive', self.filename)
            self.result.add('root_archive_checksum', self.checksum)
        return self.result
Example #8
0
    def create_image_format(self):
        self.temp_image_dir = mkdtemp(dir=self.target_dir)
        diskname = ''.join(
            [self.target_dir, '/',
             self.xml_state.xml_data.get_name(), '.raw'])
        Command.run(['cp', diskname, self.temp_image_dir + '/disk.raw'])
        if self.tag:
            with open(self.temp_image_dir + '/manifest.json', 'w') as manifest:
                manifest.write('{"licenses":["%s"]}' % self.tag)

        archive_name = self.get_target_name_for_format('gce')

        # delete the '.gz' suffix from the name. The suffix is appended by
        # the archive creation method depending on the creation type.
        archive_name = archive_name.replace('.gz', '')

        archive = ArchiveTar(self.target_dir + '/' + archive_name)
        archive.create_gnu_gzip_compressed(self.temp_image_dir)
Example #9
0
    def create_install_pxe_archive(self):
        """
            Create an oem install tar archive suitable for installing a
            disk image via the network using the PXE boot protocol.
            The archive contains the raw disk image and its checksum
            as well as an install initrd and kernel plus the required
            kernel commandline information which needs to be added
            as append line in the pxelinux config file on the boot
            server
        """
        self.pxe_dir = mkdtemp(prefix="pxe-install-media.", dir=self.target_dir)
        # the system image is transfered as xz compressed variant
        log.info("xz compressing disk image")
        pxe_image_filename = "".join([self.pxe_dir, "/", self.xml_state.xml_data.get_name(), ".xz"])
        compress = Compress(source_filename=self.diskname, keep_source_on_compress=True)
        compress.xz()
        Command.run(["mv", compress.compressed_filename, pxe_image_filename])

        # the system image transfer is checked against a checksum
        log.info("Creating disk image checksum")
        pxe_md5_filename = "".join([self.pxe_dir, "/", self.xml_state.xml_data.get_name(), ".md5"])
        checksum = Checksum(pxe_image_filename)
        checksum.md5(pxe_md5_filename)

        # create pxe config append information
        # this information helps to configure the boot server correctly
        append_filename = "".join([self.pxe_dir, "/", self.xml_state.xml_data.get_name(), ".append"])
        cmdline = "pxe=1"
        custom_cmdline = self.xml_state.build_type.get_kernelcmdline()
        if custom_cmdline:
            cmdline += " " + custom_cmdline
        with open(append_filename, "w") as append:
            append.write("%s\n" % cmdline)

        # create initrd for pxe install
        log.info("Creating pxe install boot image")
        self.__create_pxe_install_kernel_and_initrd()

        # create pxe install tarball
        log.info("Creating pxe install archive")
        archive = ArchiveTar(self.pxename.replace(".xz", ""))
        archive.create_xz_compressed(self.pxe_dir)
Example #10
0
    def create(self):
        supported_archives = Defaults.get_archive_image_types()
        if self.requested_archive_type not in supported_archives:
            raise KiwiArchiveSetupError(
                'Unknown archive type: %s' % self.requested_archive_type
            )

        if self.requested_archive_type == 'tbz':
            log.info('Creating XZ compressed tar archive')
            archive = ArchiveTar(
                self.__target_file_for('tar')
            )
            archive.create_xz_compressed(self.root_dir)
            checksum = Checksum(self.filename)
            log.info('--> Creating archive checksum')
            checksum.md5(self.checksum)
            self.result.add(
                'root_archive', self.filename
            )
            self.result.add(
                'root_archive_checksum', self.checksum
            )
        return self.result
Example #11
0
    def create_install_pxe_archive(self):
        """
            Create an oem install tar archive suitable for installing a
            disk image via the network using the PXE boot protocol.
            The archive contains the raw disk image and its checksum
            as well as an install initrd and kernel plus the required
            kernel commandline information which needs to be added
            as append line in the pxelinux config file on the boot
            server
        """
        self.pxe_dir = mkdtemp(
            prefix='pxe-install-media.', dir=self.target_dir
        )
        # the system image is transfered as xz compressed variant
        log.info('xz compressing disk image')
        pxe_image_filename = ''.join(
            [
                self.pxe_dir, '/',
                self.xml_state.xml_data.get_name(), '.xz'
            ]
        )
        compress = Compress(
            source_filename=self.diskname,
            keep_source_on_compress=True
        )
        compress.xz()
        Command.run(
            ['mv', compress.compressed_filename, pxe_image_filename]
        )

        # the system image transfer is checked against a checksum
        log.info('Creating disk image checksum')
        pxe_md5_filename = ''.join(
            [
                self.pxe_dir, '/',
                self.xml_state.xml_data.get_name(), '.md5'
            ]
        )
        checksum = Checksum(pxe_image_filename)
        checksum.md5(pxe_md5_filename)

        # create pxe config append information
        # this information helps to configure the boot server correctly
        append_filename = ''.join(
            [
                self.pxe_dir, '/',
                self.xml_state.xml_data.get_name(), '.append'
            ]
        )
        cmdline = 'pxe=1'
        custom_cmdline = self.xml_state.build_type.get_kernelcmdline()
        if custom_cmdline:
            cmdline += ' ' + custom_cmdline
        with open(append_filename, 'w') as append:
            append.write('%s\n' % cmdline)

        # create initrd for pxe install
        log.info('Creating pxe install boot image')
        self.__create_pxe_install_kernel_and_initrd()

        # create pxe install tarball
        log.info('Creating pxe install archive')
        archive = ArchiveTar(
            self.pxename.replace('.xz', '')
        )
        archive.create_xz_compressed(
            self.pxe_dir
        )
Example #12
0
 def create_recovery_archive(self):
     """
         create a compressed recovery archive from the root tree
         for use with kiwi's recvoery system. The method creates
         additional data into the image root filesystem which is
         deleted prior to the creation of a new recovery data set
     """
     # cleanup
     bash_comand = [
         'rm', '-f', self.root_dir + '/recovery.*'
     ]
     Command.run(['bash', '-c', ' '.join(bash_comand)])
     if not self.oemconfig['recovery']:
         return
     # recovery.tar
     log.info('Creating recovery tar archive')
     metadata = {
         'archive_name':
             self.root_dir + '/recovery.tar',
         'archive_filecount':
             self.root_dir + '/recovery.tar.files',
         'archive_size':
             self.root_dir + '/recovery.tar.size',
         'partition_size':
             self.root_dir + '/recovery.partition.size',
         'partition_filesystem':
             self.root_dir + '/recovery.tar.filesystem'
     }
     recovery_archive = NamedTemporaryFile(
         delete=False
     )
     archive = ArchiveTar(
         filename=recovery_archive.name,
         create_from_file_list=False
     )
     archive.create(
         source_dir=self.root_dir,
         exclude=['dev', 'proc', 'sys'],
         options=[
             '--numeric-owner',
             '--hard-dereference',
             '--preserve-permissions'
         ]
     )
     Command.run(
         ['mv', recovery_archive.name, metadata['archive_name']]
     )
     # recovery.tar.filesystem
     recovery_filesystem = self.xml_state.build_type.get_filesystem()
     with open(metadata['partition_filesystem'], 'w') as partfs:
         partfs.write('%s' % recovery_filesystem)
     log.info(
         '--> Recovery partition filesystem: %s', recovery_filesystem
     )
     # recovery.tar.files
     bash_comand = [
         'tar', '-tf', metadata['archive_name'], '|', 'wc', '-l'
     ]
     tar_files_call = Command.run(
         ['bash', '-c', ' '.join(bash_comand)]
     )
     tar_files_count = int(tar_files_call.output.rstrip('\n'))
     with open(metadata['archive_filecount'], 'w') as files:
         files.write('%d\n' % tar_files_count)
     log.info(
         '--> Recovery file count: %d files', tar_files_count
     )
     # recovery.tar.size
     recovery_archive_size_bytes = os.path.getsize(metadata['archive_name'])
     with open(metadata['archive_size'], 'w') as size:
         size.write('%d' % recovery_archive_size_bytes)
     log.info(
         '--> Recovery uncompressed size: %d mbytes',
         int(recovery_archive_size_bytes / 1048576)
     )
     # recovery.tar.gz
     log.info('--> Compressing recovery archive')
     compress = Compress(self.root_dir + '/recovery.tar')
     compress.gzip()
     # recovery.partition.size
     recovery_archive_gz_size_mbytes = int(
         os.path.getsize(metadata['archive_name'] + '.gz') / 1048576
     )
     recovery_partition_mbytes = recovery_archive_gz_size_mbytes \
         + Defaults.get_recovery_spare_mbytes()
     with open(metadata['partition_size'], 'w') as gzsize:
         gzsize.write('%d' % recovery_partition_mbytes)
     log.info(
         '--> Recovery partition size: %d mbytes',
         recovery_partition_mbytes
     )
     # delete recovery archive if inplace recovery is requested
     # In this mode the recovery archive is created at install time
     # and not at image creation time. However the recovery metadata
     # is preserved in order to be able to check if enough space
     # is available on the disk to create the recovery archive.
     if self.oemconfig['recovery_inplace']:
         log.info(
             '--> Inplace recovery requested, deleting archive'
         )
         Path.wipe(metadata['archive_name'] + '.gz')