Class: Bootloader::Stage1

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Yast::Logger
Defined in:
src/lib/bootloader/stage1.rb

Overview

Represents where is bootloader stage1 installed. Allows also proposing its location.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Stage1) initialize

Returns a new instance of Stage1



22
23
24
# File 'src/lib/bootloader/stage1.rb', line 22

def initialize
  @model = CFA::Grub2::InstallDevice.new
end

Instance Attribute Details

- (Object) model (readonly)

Returns the value of attribute model



19
20
21
# File 'src/lib/bootloader/stage1.rb', line 19

def model
  @model
end

Instance Method Details

- (Object) add_udev_device(dev)



47
48
49
50
# File 'src/lib/bootloader/stage1.rb', line 47

def add_udev_device(dev)
  udev_device = Bootloader::UdevMapping.to_mountby_device(dev)
  @model.add_device(udev_device)
end

- (Object) available_locations

returns hash, where key is symbol for location and value is device name



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'src/lib/bootloader/stage1.rb', line 123

def available_locations
  res = {}

  case Yast::Arch.architecture
  when "i386", "x86_64"
    available_partitions(res)
    res[:mbr] = Yast::BootStorage.mbr_disk
  else
    log.info "no available non-custom location for arch #{Yast::Arch.architecture}"
  end

  res
end

- (Boolean) boot_partition?

Returns:

  • (Boolean)


68
69
70
# File 'src/lib/bootloader/stage1.rb', line 68

def boot_partition?
  include?(Yast::BootStorage.BootPartitionDevice)
end

- (Object) clear_devices



62
63
64
65
66
# File 'src/lib/bootloader/stage1.rb', line 62

def clear_devices
  devices.each do |dev|
    @model.remove_device(dev)
  end
end

- (Object) custom_devices



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'src/lib/bootloader/stage1.rb', line 86

def custom_devices
  known_devices = [
    Yast::BootStorage.BootPartitionDevice,
    Yast::BootStorage.RootPartitionDevice,
    Yast::BootStorage.mbr_disk,
    Yast::BootStorage.ExtendedPartitionDevice
  ]
  known_devices.compact!
  known_devices.map! { |d| Bootloader::UdevMapping.to_kernel_device(d) }

  devices.select do |dev|
    !known_devices.include?(Bootloader::UdevMapping.to_kernel_device(dev))
  end
end

- (Boolean) extended_partition?

Returns:

  • (Boolean)


80
81
82
83
84
# File 'src/lib/bootloader/stage1.rb', line 80

def extended_partition?
  return false unless Yast::BootStorage.ExtendedPartitionDevice

  include?(Yast::BootStorage.ExtendedPartitionDevice)
end

- (Boolean) include?(dev)

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'src/lib/bootloader/stage1.rb', line 39

def include?(dev)
  kernel_dev = Bootloader::UdevMapping.to_kernel_device(dev)

  devices.any? do |map_dev|
    kernel_dev == Bootloader::UdevMapping.to_kernel_device(map_dev)
  end
end

- (Object) inspect



26
27
28
29
# File 'src/lib/bootloader/stage1.rb', line 26

def inspect
  "<Bootloader::Stage1 #{object_id} activate: #{activate?} " \
    "generic_mbr: #{generic_mbr?} devices: #{devices.inspect}>"
end

- (Boolean) mbr?

Returns:

  • (Boolean)


76
77
78
# File 'src/lib/bootloader/stage1.rb', line 76

def mbr?
  include?(Yast::BootStorage.mbr_disk)
end

- (Object) propose

Propose and set Stage1 location. It sets properly all “boot_*” entries in globals. It also sets if partition should be activated by setting its boot flag (in globals key “activate”). It proposes if generic_mbr will be written into MBR (globals key “generic_mbr”). And last but not least it propose if protective MBR flag need to be removed The proposal is only based on storage information, disregarding any existing values of the output variables (which are respected at other times, in AutoYaST).

See Also:

  • keys in globals to https://old-en.opensuse.org/YaST/Bootloader_API#global_options_in_map


109
110
111
112
113
114
115
116
117
118
119
120
# File 'src/lib/bootloader/stage1.rb', line 109

def propose
  case Yast::Arch.architecture
  when "i386", "x86_64"
    propose_x86
  when /ppc/
    propose_ppc
  when /s390/
    propose_s390
  else
    raise "unsuported architecture #{Yast::Arch.architecture}"
  end
end

- (Object) read



31
32
33
# File 'src/lib/bootloader/stage1.rb', line 31

def read
  @model.load
end

- (Object) remove_device(dev)



52
53
54
55
56
57
58
59
60
# File 'src/lib/bootloader/stage1.rb', line 52

def remove_device(dev)
  kernel_dev = Bootloader::UdevMapping.to_kernel_device(dev)

  dev = devices.find do |map_dev|
    kernel_dev == Bootloader::UdevMapping.to_kernel_device(map_dev)
  end

  @model.remove_device(dev)
end

- (Boolean) root_partition?

Returns:

  • (Boolean)


72
73
74
# File 'src/lib/bootloader/stage1.rb', line 72

def root_partition?
  include?(Yast::BootStorage.RootPartitionDevice)
end

- (Object) write



35
36
37
# File 'src/lib/bootloader/stage1.rb', line 35

def write
  @model.save
end