Wednesday, July 26, 2023

Install Windows 11 KVM Guest on Manjaro Linux 22.1 (Gnome)

Update as of 08/11/2023  

Deploying virtio-win-0.1.229-1.noarch.rpm on Arch Linux Distributions (Manjaro, ArcoLinux, EndeavourOS)

*******************************************************

On Manjaro Linux we intend to convert virtio-win-0_1_229-1_noarch.rpm to Arch format and install corresponding Arch package as pre-installation step on KVM Hypervisor's Manajaro Linux Host.

1. Configure the RPM for Arch

Start with install Ruby and rpm-tools .

$ sudo pacman -S ruby rpm-tools

$ chmod +x rpmtoarch

$ sudo ./rpmtoarch  virtio-win-0_1_229-1_noarch.rpm

Install the New Package

$ sudo chown -R boris virtio-win-0_1_229-1_noarch

$ cd virtio-win-0_1_229-1_noarch

$ makepkg -s

$ sudo pacman -U virtio-win-0_1_229-1_noarch-unknown-1-x86_64.pkg.tar.zst

loading packages...

resolving dependencies...

looking for conflicting packages...

Packages (1) virtio-win-0_1_229-1_noarch-unknown-1

Total Installed Size:  1018,37 MiB

:: Proceed with installation? [Y/n] Y

(1/1) checking keys in keyring                         [############################] 100%

(1/1) checking package integrity                       [############################] 100%

(1/1) loading package files                            [############################] 100%

(1/1) checking for file conflicts                      [############################] 100%

(1/1) checking available disk space                    [############################] 100%

:: Processing package changes...

(1/1) installing virtio-win-0_1_229-1_noarch           [############################] 100%

:: Running post-transaction hooks...

(1/1) Arming ConditionNeedsUpdate...

2. When done, proceed with standard Win11 installation as KVM Guest on Manjaro Linux 22.1. For details of KVM Host setup see https://computingforgeeks.com/install-kvm-qemu-virt-manager-arch-manjar/




























References

Zinovyev's rpmtoarch uploaded (just in case)
==================================

#!/usr/bin/env ruby

require "fileutils"

class Package
  FILTERED_PARTS = %w[rpm x86_64]

  INSTALL_SECTIONS = %w[pre_install post_install pre_upgrade
                        post_upgrade pre_remove post_remove].freeze

  RPM_INSTALL_SECTIONS = %w[preinstall postinstall preupgrade
                            postupgrade preuninstall postuninstall].freeze

  attr_accessor :path_to_rpm, :pwd

  def initialize(path_to_rpm)
    @path_to_rpm = path_to_rpm
    @pwd = Dir.pwd
  end

  def run
    create_dir
    copy_rpm_file
    create_pkgbuild
    scripts = extract_scripts
    create_install_script(scripts)
    # Extract install scripts from rpm
    # Create install script
  end

  def pkgbuild
    <<-PKGBUILD.gsub(/\ {6}/, "")
      pkgname=#{package_name}
      pkgver=unknown
      pkgrel=1
      epoch=
      pkgdesc=""
      arch=("x86_64")
      url=""
      license=('Unknown')
      groups=()
      depends=()
      makedepends=()
      checkdepends=()
      optdepends=()
      provides=()
      conflicts=()
      replaces=()
      backup=()
      options=()
      install="#{package_name}.install"
      changelog=
      source=()
      noextract=()
      md5sums=()
      validpgpkeys=()
      prepare() {
        cp ../#{rpm_basename} $srcdir/
      }
      package() {
        rpm2cpio #{rpm_basename} | cpio -idmv -D $pkgdir/
      }
    PKGBUILD
  end

  def extract_scripts
    Dir.chdir(package_name)
    rpm_scripts = %x(rpm -qp --scripts #{rpm_basename})
    rpm_scripts = rpm_scripts.encode!("UTF-8", "UTF-8", invalid: :replace)
    Dir.chdir(pwd)
    parse_blocks(rpm_scripts)
  end

  def parse_blocks(rpm_scripts)
    current_block = nil
    rpm_scripts.split("\n").each_with_object({}) do |line, blocks|
      if section = find_section_in_line(line)
        blocks[section] = []
        current_block = blocks[section]
      elsif current_block
        current_block << line
      end
    end
  end

  def find_section_in_line(line)
    RPM_INSTALL_SECTIONS.each_with_index do |section, idx|
      return INSTALL_SECTIONS[idx] if line =~ /#{section}/
    end && nil
  end

  def create_install_script(scripts)
    File.open(install_script_path, "w") do |f|
      install_script = scripts.map do |function_name, code|
        <<-CODE.gsub(/\ {8}/, "")
        #{function_name}() {
        #{code.join("\n")}
        }
        CODE
      end.join("\n")
      f.write(install_script)
    end
  end

  def create_pkgbuild
    File.open(pkgbuild_path, "w") do |f|
      f.write(pkgbuild)
    end
  end

  def copy_rpm_file
    FileUtils.cp(rpm_basename, "#{package_name}/")
  end

  def create_dir
    Dir.mkdir(package_name) unless Dir.exists?(package_name)
  end

  def rpm_basename
    @_rpm_basename ||= File.basename(@path_to_rpm)
  end

  def install_script_path
    "#{package_name}/#{package_name}.install"
  end

  def pkgbuild_path
    "#{package_name}/PKGBUILD"
  end

  def package_name
    @_package_name ||= begin
      rpm_basename.split(".").reject do |p|
        FILTERED_PARTS.include?(p.to_s)
      end.join("_")
    end
  end
end

package = Package.new(ARGV[0])

puts "Basename: #{package.rpm_basename}"
puts "Package_name: #{package.package_name}"
puts "RUN: #{package.run}"



No comments:

Post a Comment