Sha256: 1e93fa34ee0e05ba4e1869e7449b7c6127645bec5c8d5e0ca1381ec517c24905

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'nito'

module Getch
  module Config
    class Grub
      def initialize
        @log = Log.new
        @disk = OPTIONS[:boot_disk] ||= OPTIONS[:disk]
        # https://wiki.archlinux.org/title/Install_Arch_Linux_on_ZFS
        @prefix = OPTIONS[:fs] == 'zfs' ? 'ZPOOL_VDEV_NAME_PATH=1' : ''
        @os_name = OPTIONS[:os].capitalize
        x
      end

      def x
        @log.info "Installing Grub on #{@disk}...\n"
        Helpers.efi? ? grub_efi : grub_bios
      end 

      private

      def grub_efi
        mount_efivars
        cmd = "#{@prefix} grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=\"#{@os_name}\""
        ChrootOutput.new(cmd)
      end

      def grub_bios
        cmd = "#{@prefix} grub-install /dev/#{@disk}"
        ChrootOutput.new(cmd)
      end

      # In case where efivars is not mounted
      # avoid error with grub
      def mount_efivars
        NiTo.mount '-t efivarfs', 'efivarfs', '/sys/firmware/efi/efivars'
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
getch-0.5.0 lib/getch/config/grub.rb
getch-0.3.6 lib/getch/config/grub.rb
getch-0.3.5 lib/getch/config/grub.rb
getch-0.3.4 lib/getch/config/grub.rb
getch-0.3.3 lib/getch/config/grub.rb
getch-0.3.0 lib/getch/config/grub.rb