コード例 #1
0
    def create_initrd(self,
                      mbrid: Optional[SystemIdentifier] = None,
                      basename: Optional[str] = None,
                      install_initrd: bool = False) -> None:
        """
        Create kiwi .profile environment to be included in dracut initrd.
        Call dracut as chroot operation to create the initrd and move
        the result into the image build target directory

        :param SystemIdentifier mbrid: unused
        :param str basename: base initrd file name
        :param bool install_initrd: unused
        """
        if self.is_prepared():
            log.info('Creating generic dracut initrd archive')
            self._create_profile_environment()
            kernel_info = Kernel(self.boot_root_directory)
            kernel_details = kernel_info.get_kernel(raise_on_not_found=True)
            if basename:
                dracut_initrd_basename = basename
            else:
                dracut_initrd_basename = self.initrd_base_name
            included_files = self.included_files
            modules_args = [
                '--modules', ' {0} '.format(' '.join(self.modules))
            ] if self.modules else []
            modules_args += [
                '--add', ' {0} '.format(' '.join(self.add_modules))
            ] if self.add_modules else []
            modules_args += [
                '--omit', ' {0} '.format(' '.join(self.omit_modules))
            ] if self.omit_modules else []
            dracut_initrd_basename += '.xz'
            options = self.dracut_options + modules_args + included_files
            if kernel_details:
                self.device_mount = MountManager(
                    device='/dev',
                    mountpoint=self.boot_root_directory + '/dev')
                self.device_mount.bind_mount()
                self.proc_mount = MountManager(
                    device='/proc',
                    mountpoint=self.boot_root_directory + '/proc')
                self.proc_mount.bind_mount()
                dracut_call = Command.run([
                    'chroot', self.boot_root_directory, 'dracut', '--verbose',
                    '--no-hostonly', '--no-hostonly-cmdline', '--xz'
                ] + options + [dracut_initrd_basename, kernel_details.version],
                                          stderr_to_stdout=True)
                self.device_mount.umount()
                self.proc_mount.umount()
            log.debug(dracut_call.output)
            Command.run([
                'mv',
                os.sep.join([self.boot_root_directory,
                             dracut_initrd_basename]), self.target_dir
            ])
            self.initrd_filename = os.sep.join(
                [self.target_dir, dracut_initrd_basename])
コード例 #2
0
 def _add_to_mount_list(self, volume_name, realpath):
     device_node = self.volume_map[volume_name]
     if volume_name == 'LVRoot':
         # root volume must be first in the list
         self.mount_list.insert(
             0, MountManager(device=device_node,
                             mountpoint=self.mountpoint))
     else:
         self.mount_list.append(
             MountManager(device=device_node,
                          mountpoint=self.mountpoint + '/' + realpath))
コード例 #3
0
    def sync_data(self, exclude=None):
        """
        Copy root data tree into filesystem

        :param list exclude: list of exclude dirs/files
        """
        if not self.root_dir:
            raise KiwiFileSystemSyncError(
                'no root directory specified'
            )
        if not os.path.exists(self.root_dir):
            raise KiwiFileSystemSyncError(
                'given root directory %s does not exist' % self.root_dir
            )
        self.filesystem_mount = MountManager(
            device=self.device_provider.get_device()
        )
        self.filesystem_mount.mount(
            self.custom_args['mount_options']
        )
        data = DataSync(
            self.root_dir, self.filesystem_mount.mountpoint
        )
        data.sync_data(
            options=['-a', '-H', '-X', '-A', '--one-file-system'],
            exclude=exclude
        )
        self.filesystem_mount.umount()
コード例 #4
0
    def setup(self, name=None):
        """
        Setup btrfs volume management

        In case of btrfs a toplevel(@) subvolume is created and marked
        as default volume. If snapshots are activated via the custom_args
        the setup method also created the @/.snapshots/1/snapshot
        subvolumes. There is no concept of a volume manager name, thus
        the name argument is not used for btrfs

        :param string name: unused
        """
        self.setup_mountpoint()

        filesystem = FileSystem(name='btrfs',
                                device_provider=MappedDevice(
                                    device=self.device, device_provider=self),
                                custom_args=self.custom_filesystem_args)
        filesystem.create_on_device(label=self.custom_args['root_label'])
        self.toplevel_mount = MountManager(device=self.device,
                                           mountpoint=self.mountpoint)
        self.toplevel_mount.mount(self.custom_filesystem_args['mount_options'])
        root_volume = self.mountpoint + '/@'
        Command.run(['btrfs', 'subvolume', 'create', root_volume])
        if self.custom_args['root_is_snapshot']:
            snapshot_volume = self.mountpoint + '/@/.snapshots'
            Command.run(['btrfs', 'subvolume', 'create', snapshot_volume])
            Path.create(snapshot_volume + '/1')
            snapshot = self.mountpoint + '/@/.snapshots/1/snapshot'
            Command.run(
                ['btrfs', 'subvolume', 'snapshot', root_volume, snapshot])
            self._set_default_volume('@/.snapshots/1/snapshot')
        else:
            self._set_default_volume('@')
コード例 #5
0
    def sync_data(self, exclude: List[str] = []):
        """
        Copy root data tree into filesystem

        :param list exclude: list of exclude dirs/files
        """
        if not self.root_dir:
            raise KiwiFileSystemSyncError(
                'no root directory specified'
            )
        if not os.path.exists(self.root_dir):
            raise KiwiFileSystemSyncError(
                'given root directory %s does not exist' % self.root_dir
            )
        self.filesystem_mount = MountManager(
            device=self.device_provider.get_device()
        )
        self.filesystem_mount.mount(
            self.custom_args['mount_options']
        )
        self._apply_attributes()
        data = DataSync(
            self.root_dir, self.filesystem_mount.mountpoint
        )
        data.sync_data(
            exclude=exclude, options=Defaults.get_sync_options()
        )
コード例 #6
0
ファイル: root_bind.py プロジェクト: vmoutoussamy/kiwi
    def mount_shared_directory(self, host_dir=None):
        """
        Bind mount shared location

        The shared location is a directory which shares data from
        the image buildsystem host with the image root system. It
        is used for the repository setup and the package manager
        cache to allow chroot operations without being forced to
        duplicate this data

        :param str host_dir: directory to share between image root and build
            system root

        :raises KiwiMountSharedDirectoryError: if mount fails
        """
        if not host_dir:
            host_dir = self.shared_location
        try:
            Path.create(self.root_dir + host_dir)
            Path.create('/' + host_dir)
            shared_mount = MountManager(
                device=host_dir, mountpoint=self.root_dir + host_dir
            )
            shared_mount.bind_mount()
            self.mount_stack.append(shared_mount)
            self.dir_stack.append(host_dir)
        except Exception as e:
            self.cleanup()
            raise KiwiMountSharedDirectoryError(
                '%s: %s' % (type(e).__name__, format(e))
            )
コード例 #7
0
ファイル: root_bind.py プロジェクト: vmoutoussamy/kiwi
    def mount_kernel_file_systems(self):
        """
        Bind mount kernel filesystems

        :raises KiwiMountKernelFileSystemsError: if some kernel filesystem
            fails to mount
        """
        try:
            for location in self.bind_locations:
                location_mount_target = os.path.normpath(os.sep.join([
                    self.root_dir, location
                ]))
                if os.path.exists(location) and os.path.exists(
                    location_mount_target
                ):
                    shared_mount = MountManager(
                        device=location, mountpoint=location_mount_target
                    )
                    shared_mount.bind_mount()
                    self.mount_stack.append(shared_mount)
        except Exception as e:
            self.cleanup()
            raise KiwiMountKernelFileSystemsError(
                '%s: %s' % (type(e).__name__, format(e))
            )
コード例 #8
0
ファイル: zipl.py プロジェクト: pombredanne/kiwi-1
    def post_init(self, custom_args):
        self.custom_args = custom_args
        if not custom_args or 'boot_device' not in custom_args:
            raise KiwiBootLoaderZiplInstallError(
                'boot device node name required for zipl installation')

        self.boot_mount = MountManager(custom_args['boot_device'])
コード例 #9
0
ファイル: mount.py プロジェクト: rjschwei/kiwi8
 def _mount_volumes(self, mountpoint) -> None:
     for volume_path in Path.sort_by_hierarchy(sorted(self.volumes.keys())):
         volume_mount = MountManager(
             device=self.volumes[volume_path]['volume_device'],
             mountpoint=os.path.join(mountpoint, volume_path))
         self.mount_list.append(volume_mount)
         volume_mount.mount(
             options=[self.volumes[volume_path]['volume_options']])
コード例 #10
0
    def process_install_requests_bootstrap(self):
        """
        Process package install requests for bootstrap phase (no chroot)
        The debootstrap program is used to bootstrap a new system with
        a collection of predefined packages. The kiwi bootstrap section
        information is not used in this case

        :raises KiwiDebootstrapError: if no main distribution repository
            is configured, if the debootstrap script is not found or if the
            debootstrap script execution fails
        :return: process results in command type
        :rtype: namedtuple
        """
        if not self.distribution:
            raise KiwiDebootstrapError(
                'No main distribution repository is configured')
        bootstrap_script = '/usr/share/debootstrap/scripts/' + \
            self.distribution
        if not os.path.exists(bootstrap_script):
            raise KiwiDebootstrapError(
                'debootstrap script for %s distribution not found' %
                self.distribution)
        bootstrap_dir = self.root_dir + '.debootstrap'
        if 'apt-get' in self.package_requests:
            # debootstrap takes care to install apt-get
            self.package_requests.remove('apt-get')
        try:
            dev_mount = MountManager(device='/dev',
                                     mountpoint=self.root_dir + '/dev')
            dev_mount.umount()
            if self.repository.unauthenticated == 'false':
                log.warning(
                    'KIWI does not support signature checks for apt-get '
                    'package manager during the bootstrap procedure, any '
                    'provided key will only be used inside the chroot '
                    'environment')
            cmd = ['debootstrap', '--no-check-gpg']
            if self.deboostrap_minbase:
                cmd.append('--variant=minbase')
            if self.repository.components:
                cmd.append('--components={0}'.format(','.join(
                    self.repository.components)))
            cmd.extend(
                [self.distribution, bootstrap_dir, self.distribution_path])
            Command.run(cmd, self.command_env)
            data = DataSync(bootstrap_dir + '/', self.root_dir)
            data.sync_data(options=['-a', '-H', '-X', '-A'])
            for key in self.repository.signing_keys:
                Command.run(['chroot', self.root_dir, 'apt-key', 'add', key],
                            self.command_env)
        except Exception as e:
            raise KiwiDebootstrapError('%s: %s' %
                                       (type(e).__name__, format(e)))
        finally:
            Path.wipe(bootstrap_dir)

        return self.process_install_requests()
コード例 #11
0
 def _iso_mount_path(self, path):
     # The prefix name 'kiwi_iso_mount' has a meaning here because the
     # zypper repository manager looks up iso mount paths by its repo
     # source name
     iso_mount_path = mkdtemp(prefix='kiwi_iso_mount.')
     iso_mount = MountManager(device=path, mountpoint=iso_mount_path)
     self.mount_stack.append(iso_mount)
     iso_mount.mount()
     return iso_mount.mountpoint
コード例 #12
0
ファイル: base.py プロジェクト: jitendraky/kiwi
    def _mount_system(
        self, root_device, boot_device, efi_device=None, volumes=None
    ):
        self.root_mount = MountManager(
            device=root_device
        )
        self.boot_mount = MountManager(
            device=boot_device,
            mountpoint=self.root_mount.mountpoint + '/boot'
        )
        if efi_device:
            self.efi_mount = MountManager(
                device=efi_device,
                mountpoint=self.root_mount.mountpoint + '/boot/efi'
            )

        self.root_mount.mount()

        if not self.root_mount.device == self.boot_mount.device:
            self.boot_mount.mount()

        if efi_device:
            self.efi_mount.mount()

        if volumes:
            for volume_path in Path.sort_by_hierarchy(
                sorted(volumes.keys())
            ):
                volume_mount = MountManager(
                    device=volumes[volume_path]['volume_device'],
                    mountpoint=self.root_mount.mountpoint + '/' + volume_path
                )
                self.volumes_mount.append(volume_mount)
                volume_mount.mount(
                    options=[volumes[volume_path]['volume_options']]
                )

        if self.root_filesystem_is_overlay:
            # In case of an overlay root system all parts of the rootfs
            # are read-only by squashfs except for the extra boot partition.
            # However tools like grub's mkconfig creates temporary files
            # at call time and therefore /tmp needs to be writable during
            # the call time of the tools
            self.tmp_mount = MountManager(
                device='/tmp',
                mountpoint=self.root_mount.mountpoint + '/tmp'
            )
            self.tmp_mount.bind_mount()

        self.device_mount = MountManager(
            device='/dev',
            mountpoint=self.root_mount.mountpoint + '/dev'
        )
        self.proc_mount = MountManager(
            device='/proc',
            mountpoint=self.root_mount.mountpoint + '/proc'
        )
        self.device_mount.bind_mount()
        self.proc_mount.bind_mount()
コード例 #13
0
ファイル: btrfs.py プロジェクト: eduardoj/kiwi
    def create_volumes(self, filesystem_name):
        """
        Create configured btrfs subvolumes

        Any btrfs subvolume is of the same btrfs filesystem. There is no
        way to have different filesystems per btrfs subvolume. Thus
        the filesystem_name has no effect for btrfs

        :param string filesystem_name: unused
        """
        log.info(
            'Creating %s sub volumes', filesystem_name
        )
        self.create_volume_paths_in_root_dir()

        canonical_volume_list = self.get_canonical_volume_list()
        if canonical_volume_list.full_size_volume:
            # put an eventual fullsize volume to the volume list
            # because there is no extra handling required for it on btrfs
            canonical_volume_list.volumes.append(
                canonical_volume_list.full_size_volume
            )

        for volume in canonical_volume_list.volumes:
            if volume.name == 'LVRoot':
                # the btrfs root volume named '@' has been created as
                # part of the setup procedure
                pass
            else:
                log.info('--> sub volume %s', volume.realpath)
                toplevel = self.mountpoint + '/@/'
                volume_parent_path = os.path.normpath(
                    toplevel + os.path.dirname(volume.realpath)
                )
                if not os.path.exists(volume_parent_path):
                    Path.create(volume_parent_path)
                Command.run(
                    [
                        'btrfs', 'subvolume', 'create',
                        os.path.normpath(toplevel + volume.realpath)
                    ]
                )
                self.apply_attributes_on_volume(
                    toplevel, volume
                )
                if self.custom_args['root_is_snapshot']:
                    snapshot = self.mountpoint + '/@/.snapshots/1/snapshot/'
                    volume_mount = MountManager(
                        device=self.device,
                        mountpoint=os.path.normpath(snapshot + volume.realpath)
                    )
                    self.subvol_mount_list.append(
                        volume_mount
                    )
コード例 #14
0
 def _get_rpm_database_location(self):
     shared_mount = MountManager(device='/dev',
                                 mountpoint=self.root_dir + '/dev')
     if not shared_mount.is_mounted():
         shared_mount.bind_mount()
     rpmdb = RpmDataBase(self.root_dir)
     if rpmdb.has_rpm():
         dbpath = rpmdb.rpmdb_image.expand_query('%_dbpath')
     else:
         dbpath = rpmdb.rpmdb_host.expand_query('%_dbpath')
     if shared_mount.is_mounted():
         shared_mount.umount_lazy()
     return dbpath
コード例 #15
0
ファイル: base.py プロジェクト: vmoutoussamy/kiwi
    def sync_data(self, exclude=None):
        """
        Implements sync of root directory to mounted volumes

        :param list exclude: file patterns to exclude
        """
        if self.mountpoint:
            root_mount = MountManager(device=None, mountpoint=self.mountpoint)
            if not root_mount.is_mounted():
                self.mount_volumes()
            data = DataSync(self.root_dir, self.mountpoint)
            data.sync_data(options=Defaults.get_sync_options(),
                           exclude=exclude)
コード例 #16
0
ファイル: base.py プロジェクト: isbm/kiwi
    def sync_data(self, exclude=None):
        """
        Implements sync of root directory to mounted volumes

        :param list exclude: file patterns to exclude
        """
        if self.mountpoint:
            root_mount = MountManager(device=None, mountpoint=self.mountpoint)
            if not root_mount.is_mounted():
                self.mount_volumes()
            data = DataSync(self.root_dir, self.mountpoint)
            data.sync_data(
                options=['-a', '-H', '-X', '-A', '--one-file-system'],
                exclude=exclude)
コード例 #17
0
	def finalize(self, image):
		# mount fs
		mount = MountManager(device=self._device)
		mount.mount(options=None)

		# run post-image script
		setup = SystemSetup(xml_state=self._state, root_dir=mount.mountpoint)
		setup.import_description()
		setup.call_disk_script()

		# clean-up
		mount.umount()
		del setup
		return True
コード例 #18
0
ファイル: grub2.py プロジェクト: rabueker/kiwi
    def _mount_device_and_volumes(self):
        if self.root_mount is None:
            self.root_mount = MountManager(
                device=self.custom_args['root_device'])
            self.root_mount.mount()

        if self.boot_mount is None:
            if 's390' in self.arch:
                self.boot_mount = MountManager(
                    device=self.custom_args['boot_device'],
                    mountpoint=self.root_mount.mountpoint + '/boot/zipl')
            else:
                self.boot_mount = MountManager(
                    device=self.custom_args['boot_device'],
                    mountpoint=self.root_mount.mountpoint + '/boot')
            if not self.root_mount.device == self.boot_mount.device:
                self.boot_mount.mount()

        if self.efi_mount is None and self.custom_args.get('efi_device'):
            self.efi_mount = MountManager(
                device=self.custom_args['efi_device'],
                mountpoint=self.root_mount.mountpoint + '/boot/efi')
            self.efi_mount.mount()

        if self.volumes and not self.volumes_mount:
            for volume_path in Path.sort_by_hierarchy(
                    sorted(self.volumes.keys())):
                volume_mount = MountManager(
                    device=self.volumes[volume_path]['volume_device'],
                    mountpoint=self.root_mount.mountpoint + '/' + volume_path)
                self.volumes_mount.append(volume_mount)
                volume_mount.mount(
                    options=[self.volumes[volume_path]['volume_options']])
        if self.device_mount is None:
            self.device_mount = MountManager(
                device='/dev', mountpoint=self.root_mount.mountpoint + '/dev')
            self.device_mount.bind_mount()
        if self.proc_mount is None:
            self.proc_mount = MountManager(
                device='/proc',
                mountpoint=self.root_mount.mountpoint + '/proc')
            self.proc_mount.bind_mount()
        if self.sysfs_mount is None:
            self.sysfs_mount = MountManager(
                device='/sys', mountpoint=self.root_mount.mountpoint + '/sys')
            self.sysfs_mount.bind_mount()
コード例 #19
0
    def post_init(self, custom_args):
        """
        zipl post initialization method

        :param dict custom_args:
            Contains custom zipl bootloader arguments

            .. code:: python

                {'boot_device': string}

        """
        self.custom_args = custom_args
        if not custom_args or 'boot_device' not in custom_args:
            raise KiwiBootLoaderZiplInstallError(
                'boot device node name required for zipl installation')

        self.boot_mount = MountManager(custom_args['boot_device'])
コード例 #20
0
 def setup(self, mock_path_create):
     self.mount_manager = MountManager('/dev/some-device',
                                       '/some/mountpoint')
     mock_path_create.assert_called_once_with('/some/mountpoint')
コード例 #21
0
ファイル: grub2.py プロジェクト: michal42/kiwi-1
    def install(self):
        """
        Install bootloader on disk device
        """
        log.info('Installing grub2 on disk %s', self.device)

        if self.target_removable:
            self.install_arguments.append('--removable')

        if self.arch == 'x86_64' or self.arch == 'i686' or self.arch == 'i586':
            self.target = 'i386-pc'
            self.install_device = self.device
            self.modules = ' '.join(
                Defaults.get_grub_bios_modules(multiboot=True))
            self.install_arguments.append('--skip-fs-probe')
        elif self.arch.startswith('ppc64'):
            if not self.custom_args or 'prep_device' not in self.custom_args:
                raise KiwiBootLoaderGrubInstallError(
                    'prep device name required for grub2 installation on ppc')
            self.target = 'powerpc-ieee1275'
            self.install_device = self.custom_args['prep_device']
            self.modules = ' '.join(Defaults.get_grub_ofw_modules())
            self.install_arguments.append('--skip-fs-probe')
            self.install_arguments.append('--no-nvram')
        else:
            raise KiwiBootLoaderGrubPlatformError(
                'host architecture %s not supported for grub2 installation' %
                self.arch)

        self.root_mount = MountManager(device=self.custom_args['root_device'])
        self.boot_mount = MountManager(device=self.custom_args['boot_device'],
                                       mountpoint=self.root_mount.mountpoint +
                                       '/boot')

        self.root_mount.mount()

        if not self.root_mount.device == self.boot_mount.device:
            self.boot_mount.mount()

        if self.volumes:
            for volume_path in Path.sort_by_hierarchy(
                    sorted(self.volumes.keys())):
                volume_mount = MountManager(
                    device=self.volumes[volume_path]['volume_device'],
                    mountpoint=self.root_mount.mountpoint + '/' + volume_path)
                self.volumes_mount.append(volume_mount)
                volume_mount.mount(
                    options=[self.volumes[volume_path]['volume_options']])

        self.device_mount = MountManager(
            device='/dev', mountpoint=self.root_mount.mountpoint + '/dev')
        self.proc_mount = MountManager(device='/proc',
                                       mountpoint=self.root_mount.mountpoint +
                                       '/proc')
        self.sysfs_mount = MountManager(device='/sys',
                                        mountpoint=self.root_mount.mountpoint +
                                        '/sys')
        self.device_mount.bind_mount()
        self.proc_mount.bind_mount()
        self.sysfs_mount.bind_mount()

        # check if a grub installation could be found in the image system
        grub_directory = Defaults.get_grub_path(self.root_mount.mountpoint +
                                                '/usr/lib')
        if not grub_directory:
            raise KiwiBootLoaderGrubDataError(
                'No grub2 installation found in %s' %
                self.root_mount.mountpoint)
        grub_directory = grub_directory.replace(self.root_mount.mountpoint, '')
        module_directory = grub_directory + '/' + self.target
        boot_directory = '/boot'

        # wipe existing grubenv to allow the grub installer to create a new one
        grubenv_glob = os.sep.join(
            [self.root_mount.mountpoint, 'boot', '*', 'grubenv'])
        for grubenv in glob.glob(grubenv_glob):
            Path.wipe(grubenv)

        # install grub2 boot code
        Command.run([
            'chroot', self.root_mount.mountpoint,
            self._get_grub2_install_tool_name(self.root_mount.mountpoint)
        ] + self.install_arguments + [
            '--directory', module_directory, '--boot-directory',
            boot_directory, '--target', self.target, '--modules', self.modules,
            self.install_device
        ])

        if self.firmware and self.firmware.efi_mode() == 'uefi':
            shim_install = self._get_shim_install_tool_name(
                self.root_mount.mountpoint)
            # if shim-install does _not_ exist the fallback mechanism
            # has applied at the bootloader/config level and we expect
            # no further tool calls to be required
            if shim_install:
                self.efi_mount = MountManager(
                    device=self.custom_args['efi_device'],
                    mountpoint=self.root_mount.mountpoint + '/boot/efi')
                self.efi_mount.mount()

                # Before we call shim-install, the grub installer binary is
                # replaced by a noop. Actually there is no reason for
                # shim-install to call the grub installer because it should
                # only setup the system for EFI secure boot which does not
                # require any bootloader code in the master boot record.
                # In addition kiwi has called the grub installer right
                # before
                self._disable_grub2_install(self.root_mount.mountpoint)
                Command.run([
                    'chroot', self.root_mount.mountpoint, 'shim-install',
                    '--removable', self.install_device
                ])
                # restore the grub installer noop
                self._enable_grub2_install(self.root_mount.mountpoint)
コード例 #22
0
    def install(self):  # noqa: C901
        """
        Install bootloader on disk device
        """
        log.info('Installing grub2 on disk %s', self.device)

        if self.target_removable:
            self.install_arguments.append('--removable')

        if Defaults.is_x86_arch(self.arch):
            self.target = 'i386-pc'
            self.install_device = self.device
            self.modules = ' '.join(
                Defaults.get_grub_bios_modules(multiboot=True)
            )
            self.install_arguments.append('--skip-fs-probe')
        elif self.arch.startswith('ppc64'):
            if not self.custom_args or 'prep_device' not in self.custom_args:
                raise KiwiBootLoaderGrubInstallError(
                    'prep device name required for grub2 installation on ppc'
                )
            self.target = 'powerpc-ieee1275'
            self.install_device = self.custom_args['prep_device']
            self.modules = ' '.join(Defaults.get_grub_ofw_modules())
            self.install_arguments.append('--skip-fs-probe')
            self.install_arguments.append('--no-nvram')
        elif self.arch.startswith('s390'):
            self.target = 's390x-emu'
            self.install_device = self.device
            self.modules = ' '.join(Defaults.get_grub_s390_modules())
            self.install_arguments.append('--skip-fs-probe')
            self.install_arguments.append('--no-nvram')
        else:
            raise KiwiBootLoaderGrubPlatformError(
                'host architecture %s not supported for grub2 installation' %
                self.arch
            )

        self.root_mount = MountManager(
            device=self.custom_args['root_device']
        )
        if 's390' in self.arch:
            self.boot_mount = MountManager(
                device=self.custom_args['boot_device'],
                mountpoint=self.root_mount.mountpoint + '/boot/zipl'
            )
        else:
            self.boot_mount = MountManager(
                device=self.custom_args['boot_device'],
                mountpoint=self.root_mount.mountpoint + '/boot'
            )
        if self.custom_args.get('efi_device'):
            self.efi_mount = MountManager(
                device=self.custom_args['efi_device'],
                mountpoint=self.root_mount.mountpoint + '/boot/efi'
            )

        self.root_mount.mount()

        if not self.root_mount.device == self.boot_mount.device:
            self.boot_mount.mount()

        if self.efi_mount:
            self.efi_mount.mount()

        if self.volumes:
            for volume_path in Path.sort_by_hierarchy(
                sorted(self.volumes.keys())
            ):
                volume_mount = MountManager(
                    device=self.volumes[volume_path]['volume_device'],
                    mountpoint=self.root_mount.mountpoint + '/' + volume_path
                )
                self.volumes_mount.append(volume_mount)
                volume_mount.mount(
                    options=[self.volumes[volume_path]['volume_options']]
                )

        self.device_mount = MountManager(
            device='/dev',
            mountpoint=self.root_mount.mountpoint + '/dev'
        )
        self.proc_mount = MountManager(
            device='/proc',
            mountpoint=self.root_mount.mountpoint + '/proc'
        )
        self.sysfs_mount = MountManager(
            device='/sys',
            mountpoint=self.root_mount.mountpoint + '/sys'
        )
        self.device_mount.bind_mount()
        self.proc_mount.bind_mount()
        self.sysfs_mount.bind_mount()

        # check if a grub installation could be found in the image system
        module_directory = Defaults.get_grub_path(
            self.root_mount.mountpoint, self.target, raise_on_error=False
        )
        if not module_directory:
            raise KiwiBootLoaderGrubDataError(
                'No grub2 installation found in {0} for target {1}'.format(
                    self.root_mount.mountpoint, self.target
                )
            )
        module_directory = module_directory.replace(
            self.root_mount.mountpoint, ''
        )
        boot_directory = '/boot'

        # wipe existing grubenv to allow the grub installer to create a new one
        grubenv_glob = os.sep.join(
            [self.root_mount.mountpoint, 'boot', '*', 'grubenv']
        )
        for grubenv in glob.glob(grubenv_glob):
            Path.wipe(grubenv)

        # install grub2 boot code
        if self.firmware.get_partition_table_type() == 'dasd':
            # On s390 and in CDL mode (4k DASD) the call of grub2-install
            # does not work because grub2-install is not able to identify
            # a 4k fdasd partitioned device as a grub supported device
            # and fails. As grub2-install is only used to invoke
            # grub2-zipl-setup and has no other job to do we can
            # circumvent this problem by directly calling grub2-zipl-setup
            # instead.
            Command.run(
                [
                    'chroot', self.root_mount.mountpoint,
                    'grub2-zipl-setup', '--keep'
                ]
            )
            zipl_config_file = ''.join(
                [
                    self.root_mount.mountpoint, '/boot/zipl/config'
                ]
            )
            zipl2grub_config_file_orig = ''.join(
                [
                    self.root_mount.mountpoint,
                    '/etc/default/zipl2grub.conf.in.orig'
                ]
            )
            if os.path.exists(zipl2grub_config_file_orig):
                Command.run(
                    [
                        'mv', zipl2grub_config_file_orig,
                        zipl2grub_config_file_orig.replace('.orig', '')
                    ]
                )
            if os.path.exists(zipl_config_file):
                Command.run(
                    ['mv', zipl_config_file, zipl_config_file + '.kiwi']
                )
        else:
            Command.run(
                [
                    'chroot', self.root_mount.mountpoint,
                    self._get_grub2_install_tool_name(
                        self.root_mount.mountpoint
                    )
                ] + self.install_arguments + [
                    '--directory', module_directory,
                    '--boot-directory', boot_directory,
                    '--target', self.target,
                    '--modules', self.modules,
                    self.install_device
                ]
            )

        if self.firmware and self.firmware.efi_mode() == 'uefi':
            shim_install = self._get_shim_install_tool_name(
                self.root_mount.mountpoint
            )
            # if shim-install does _not_ exist the fallback mechanism
            # has applied at the bootloader/config level and we expect
            # no further tool calls to be required
            if shim_install:
                # Before we call shim-install, the grub installer binary is
                # replaced by a noop. Actually there is no reason for
                # shim-install to call the grub installer because it should
                # only setup the system for EFI secure boot which does not
                # require any bootloader code in the master boot record.
                # In addition kiwi has called the grub installer right
                # before
                self._disable_grub2_install(self.root_mount.mountpoint)
                Command.run(
                    [
                        'chroot', self.root_mount.mountpoint,
                        'shim-install', '--removable',
                        self.install_device
                    ]
                )
                # restore the grub installer noop
                self._enable_grub2_install(self.root_mount.mountpoint)
コード例 #23
0
 def setup(self):
     self.mount_manager = MountManager(
         '/dev/some-device', '/some/mountpoint'
     )
コード例 #24
0
 def test_setup_empty_mountpoint(self, mock_mkdtemp):
     mock_mkdtemp.return_value = 'tmpdir'
     mount_manager = MountManager('/dev/some-device')
     assert mount_manager.mountpoint == 'tmpdir'
コード例 #25
0
ファイル: mount.py プロジェクト: rjschwei/kiwi8
    def mount(self) -> None:
        """
        Mount image system from current block layers
        """
        # mount root boot and efi devices as they are present
        (root_device, boot_device, efi_device) = self._setup_device_names()
        root_mount = MountManager(device=root_device)
        if 's390' in self.arch:
            boot_mount = MountManager(device=boot_device,
                                      mountpoint=os.path.join(
                                          root_mount.mountpoint, 'boot',
                                          'zipl'))
        else:
            boot_mount = MountManager(device=boot_device,
                                      mountpoint=os.path.join(
                                          root_mount.mountpoint, 'boot'))
        if efi_device:
            efi_mount = MountManager(device=efi_device,
                                     mountpoint=os.path.join(
                                         root_mount.mountpoint, 'boot', 'efi'))

        self.mount_list.append(root_mount)
        root_mount.mount()

        if not root_mount.device == boot_mount.device:
            self.mount_list.append(boot_mount)
            boot_mount.mount()

        if efi_device:
            self.mount_list.append(efi_mount)
            efi_mount.mount()

        if self.volumes:
            self._mount_volumes(root_mount.mountpoint)

        # bind mount /image from unpacked root to get access to e.g scripts
        image_mount = MountManager(device=os.path.join(self.root_dir, 'image'),
                                   mountpoint=os.path.join(
                                       root_mount.mountpoint, 'image'))
        self.mount_list.append(image_mount)
        image_mount.bind_mount()

        # mount tmp as tmpfs
        tmp_mount = MountManager(device='tmpfs',
                                 mountpoint=os.path.join(
                                     root_mount.mountpoint, 'tmp'))
        self.mount_list.append(tmp_mount)
        tmp_mount.tmpfs_mount()

        # mount var/tmp as tmpfs
        var_tmp_mount = MountManager(device='tmpfs',
                                     mountpoint=os.path.join(
                                         root_mount.mountpoint, 'var', 'tmp'))
        self.mount_list.append(var_tmp_mount)
        var_tmp_mount.tmpfs_mount()

        # mount dev as bind
        device_mount = MountManager(device='/dev',
                                    mountpoint=os.path.join(
                                        root_mount.mountpoint, 'dev'))
        self.mount_list.append(device_mount)
        device_mount.bind_mount()

        # mount proc as bind
        proc_mount = MountManager(device='/proc',
                                  mountpoint=os.path.join(
                                      root_mount.mountpoint, 'proc'))
        self.mount_list.append(proc_mount)
        proc_mount.bind_mount()
コード例 #26
0
ファイル: mount_manager_test.py プロジェクト: mottsen/kiwi
 def test_setup_empty_mountpoint(self, mock_Temporary):
     mock_Temporary.return_value.new_dir.return_value.name = 'tmpdir'
     mount_manager = MountManager('/dev/some-device')
     assert mount_manager.mountpoint == 'tmpdir'