Sha256: 7fb0ed0d62cec7122a65f7f0e372d70c2f281cdc317c21670fc9a1709a36ced2

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require 'nito'

module Getch
  module Config
    # install grub
    class Grub
      include NiTo

      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

      protected

      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
        mount '-t efivarfs', 'efivarfs', '/sys/firmware/efi/efivars'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
getch-0.11.0 lib/getch/config/grub.rb
getch-0.7.3 lib/getch/config/grub.rb
getch-0.7.0 lib/getch/config/grub.rb