Example #1
0
    def __call__(self, location: Location, system_context: SystemContext,
                 *args: typing.Any, **kwargs: typing.Any) -> None:
        """Execute command."""

        # Set some kernel parameters for:
        system_context.set_or_append_substitution(
            "KERNEL_CMDLINE", "nvidia-drm.modeset=1 nouveau.blacklist=1")

        self._execute(
            location,
            system_context,
            "pacman",
            "nvidia",
            "nvidia-settings",
            "nvidia-utils",
            "opencl-nvidia",
            "libvdpau",
            "lib32-libvdpau",
            "lib32-nvidia-utils",
            "lib32-opencl-nvidia",
            "vdpauinfo",
            "mesa",
            "mesa-demos",
        )

        self._execute(
            location.next_line(),
            system_context,
            "create",
            "/etc/modprobe.d/nouveau-blacklist.conf",
            "blacklist nouveau",
        )
Example #2
0
    def __call__(self, location: Location, system_context: SystemContext,
                 *args: typing.Any, **kwargs: typing.Any) -> None:
        """Execute command."""

        # enable kms:
        system_context.set_or_append_substitution("INITRD_EXTRA_MODULES",
                                                  "intel_agp i915")
    def __call__(
        self,
        location: Location,
        system_context: SystemContext,
        *args: typing.Any,
        **kwargs: typing.Any,
    ) -> None:
        """Execute command."""
        if not os.path.exists(
                os.path.join(system_context.boot_directory, "vmlinuz")):
            info("Skipping initrd generation: No vmlinuz in boot directory.")
            return

        root_hash = kwargs.get("root_hash", "")
        vg = system_context.substitution_expanded("DEFAULT_VG", None)
        image_fs = system_context.substitution_expanded("IMAGE_FS", None)
        image_device = _device_ify(
            system_context.substitution_expanded("IMAGE_DEVICE", None))
        image_options = system_context.substitution_expanded(
            "IMAGE_OPTIONS", "")
        image_name = system_context.substitution_expanded(
            "CLRM_IMAGE_FILENAME", "")

        initrd = args[0]

        staging_area = os.path.join(system_context.cache_directory,
                                    "clrm_extra")
        os.makedirs(staging_area)

        modules = [
            *system_context.substitution_expanded("INITRD_EXTRA_MODULES",
                                                  "").split(","),
            "squashfs",
            *_install_image_file_support(staging_area, image_fs, image_device,
                                         image_options, image_name),
            *_install_lvm_support(staging_area, vg, image_name),
            *_install_sysroot_setup_support(staging_area),
            *_install_verity_support(staging_area, system_context, root_hash),
            *_install_volatile_support(staging_area, system_context),
            *_install_var_mount_support(staging_area, system_context),
            *_install_etc_shadow(staging_area, system_context),
        ]
        modules = [m for m in modules
                   if m]  # Trim empty modules (e.g. added by the substitution)
        system_context.set_or_append_substitution("INITRD_EXTRA_MODULES",
                                                  ",".join(modules))
        debug(
            f'INITRD_EXTRA_MODULES is now {system_context.substitution("INITRD_EXTRA_MODULES", "")}.'
        )

        # Create Initrd:
        run(
            "/bin/sh",
            "-c",
            f'cd "{staging_area}" ; "{self._binary(Binaries.FIND)}" . | "{self._binary(Binaries.CPIO)}" -o -H newc > "{initrd}"',
        )

        assert os.path.exists(initrd)
Example #4
0
    def __call__(
        self,
        location: Location,
        system_context: SystemContext,
        *args: typing.Any,
        **kwargs: typing.Any
    ) -> None:
        """Execute command."""

        # Enable KMS:
        self._execute(location, system_context, "pkg_intel_kms")

        self._execute(location, system_context, "pkg_xorg")

        # Set some kernel parameters:
        system_context.set_or_append_substitution(
            "KERNEL_CMDLINE", "intel_iommu=igfx_off i915.fastboot=1"
        )

        self._execute(
            location,
            system_context,
            "pacman",
            "libva-intel-driver",
            "mesa",
            "vulkan-intel",
            "xf86-video-intel",
            "intel-media-driver",
        )

        self._execute(
            location.next_line(),
            system_context,
            "create",
            "/etc/modprobe.d/i915-guc.conf",
            "options i915 enable_guc=3",
        )

        self._execute(
            location.next_line(),
            system_context,
            "remove",
            "/usr/lib/firmware/amdgpu/*",
            "/usr/lib/firmware/nvidia/*",
            "/usr/lib/firmware/radeon/*",
            force=True,
            recursive=True,
        )
Example #5
0
    def __call__(
        self,
        location: Location,
        system_context: SystemContext,
        *args: typing.Any,
        **kwargs: typing.Any,
    ) -> None:
        """Execute command."""

        # Nested virtualization:
        self._execute(
            location,
            system_context,
            "create",
            "/etc/modprobe.d/kvm_intel.conf",
            "options kvm_intel nested=1",
        )

        # Intel ucode:
        location.set_description("Install intel-ucode")
        self._execute(location, system_context, "pacman", "intel-ucode")

        initrd_parts = os.path.join(system_context.boot_directory,
                                    "initrd-parts")
        os.makedirs(initrd_parts, exist_ok=True)
        self._execute(
            location,
            system_context,
            "move",
            "/boot/intel-ucode.img",
            os.path.join(initrd_parts, "00-intel-ucode"),
            to_outside=True,
        )

        system_context.set_or_append_substitution("INITRD_EXTRA_MODULES",
                                                  "crc32c-intel")

        # Clean out firmware:
        self._execute(
            location.next_line(),
            system_context,
            "remove",
            "/usr/lib/firmware/amd-ucode/*",
            force=True,
        )
Example #6
0
    def __call__(
        self,
        location: Location,
        system_context: SystemContext,
        *args: typing.Any,
        **kwargs: typing.Any,
    ) -> None:
        """Execute command."""
        uuid = args[0]
        name = args[1]

        cmdline = system_context.substitution("KERNEL_CMDLINE", "")
        if "rd.luks.name=" in cmdline:
            raise GenerateError("rd.luks.name already set.", location=location)

        system_context.set_or_append_substitution(
            "KERNEL_CMDLINE",
            f"rd.luks.name={uuid}={name} rd.luks.options=discard",
        )
Example #7
0
    def __call__(
        self,
        location: Location,
        system_context: SystemContext,
        *args: typing.Any,
        **kwargs: typing.Any,
    ) -> None:
        """Execute command."""
        cert = kwargs.get("efi_cert", "")
        efi_emulator = kwargs.get("efi_emulator", "")
        key = kwargs.get("efi_key", "")
        skip_validation = kwargs.get("skip_validation", False)
        repository = args[0]
        repository_compression = kwargs.get("repository_compression", "zstd")
        repository_compression_level = kwargs.get(
            "repository_compression_level", 5)
        usr_only = kwargs.get("usr_only", True)

        debug_initrd = kwargs.get("debug_initrd", False)

        h2(f'Exporting system "{system_context.system_name}".')
        debug("Running Hooks.")
        self._run_all_exportcommand_hooks(system_context)

        verbose("Preparing system for export.")
        self._execute(location.next_line(), system_context,
                      "_write_deploy_info")

        # Create some extra data:
        self._create_root_tarball(location, system_context)

        root_partition = self._create_root_fsimage(location,
                                                   system_context,
                                                   usr_only=usr_only)
        assert root_partition
        (verity_partition, root_hash) = self._create_rootverity_fsimage(
            location,
            system_context,
            rootfs=root_partition,
        )
        assert root_hash

        has_kernel = os.path.exists(
            os.path.join(system_context.boot_directory, "vmlinuz"))
        if has_kernel:
            self._create_initrd(location, system_context)
            self._create_clrm_config_initrd(location,
                                            system_context,
                                            root_hash,
                                            debug=debug_initrd)

        cmdline = system_context.set_or_append_substitution(
            "KERNEL_CMDLINE", "systemd.volatile=true rootfstype=squashfs")
        cmdline = _setup_kernel_commandline(cmdline, root_hash)

        kernel_file = ""
        if has_kernel:
            trace(
                f'KERNEL_FILENAME: {system_context.substitution("KERNEL_FILENAME", "")}'
            )
            kernel_file = os.path.join(
                system_context.boot_directory,
                system_context.substitution_expanded("KERNEL_FILENAME", ""),
            )

            assert kernel_file
            self._create_complete_kernel(
                location,
                system_context,
                cmdline,
                kernel_file=kernel_file,
                efi_key=key,
                efi_cert=cert,
            )

        efi_partition = os.path.join(system_context.cache_directory,
                                     "efi_partition.img")

        self._create_efi_partition(
            location,
            system_context,
            efi_partition=efi_partition,
            kernel_file=kernel_file,
            efi_emulator=efi_emulator,
            root_hash=root_hash,
        )

        info("Validating installation for export.")
        if not skip_validation:
            _validate_installation(location.next_line(), system_context)

        export_directory = self.create_export_directory(system_context)
        assert export_directory
        self.create_image(
            location,
            system_context,
            export_directory,
            efi_partition=efi_partition,
            root_partition=root_partition,
            verity_partition=verity_partition,
            root_hash=root_hash,
        )

        system_context.set_substitution("EXPORT_DIRECTORY", export_directory)

        verbose(f"Exporting all data in {export_directory}.")
        self._execute(
            location.next_line(),
            system_context,
            "_export_directory",
            export_directory,
            compression=repository_compression,
            compression_level=repository_compression_level,
            repository=repository,
        )

        info("Cleaning up export location.")
        self.delete_export_directory(export_directory)
        system_context.set_substitution("EXPORT_DIRECTORY", "")