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



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

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

Instance Attribute Details

- (Object) model (readonly)

Returns the value of attribute model



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

def model
  @model
end

Instance Method Details

- (Object) add_udev_device(dev)



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

def add_udev_device(dev)
  kernel_dev = Bootloader::UdevMapping.to_kernel_device(dev)
  real_devices = ::Bootloader::Stage1Device.new(kernel_dev).real_devices
  udev_devices = real_devices.map { |d| Bootloader::UdevMapping.to_mountby_device(d) }
  udev_devices.each { |d| @model.add_device(d) }
end

- (Object) available_locations

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



147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'src/lib/bootloader/stage1.rb', line 147

def available_locations
  case Yast::Arch.architecture
  when "i386", "x86_64"
    res = available_partitions
    res[:mbr] = Yast::BootStorage.mbr_disk

    return res
  else
    log.info "no available non-custom location for arch #{Yast::Arch.architecture}"

    return {}
  end
end

- (Boolean) boot_partition?

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
84
# File 'src/lib/bootloader/stage1.rb', line 75

def boot_partition?
  if !@boot_partition_device
    dev = Yast::BootStorage.BootPartitionDevice
    kernel_dev = Bootloader::UdevMapping.to_kernel_device(dev)

    @boot_partition_device = ::Bootloader::Stage1Device.new(kernel_dev)
  end

  include_real_devs?(@boot_partition_device.real_devices)
end

- (Boolean) can_use_boot?

Returns:

  • (Boolean)


161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'src/lib/bootloader/stage1.rb', line 161

def can_use_boot?
  tm = Yast::Storage.GetTargetMap
  partition = Yast::BootStorage.BootPartitionDevice

  part = Yast::Storage.GetPartition(tm, partition)

  if !part
    log.error "cannot find partition #{partition}"
    return false
  end

  log.info "Boot partition info #{part.inspect}"

  # cannot install stage one to xfs as it doesn't have reserved space (bnc#884255)
  return false if part["used_fs"] == :xfs

  true
end

- (Object) clear_devices



69
70
71
72
73
# File 'src/lib/bootloader/stage1.rb', line 69

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

- (Object) custom_devices



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

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)


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

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

  if !@extended_partition_device
    dev = Yast::BootStorage.ExtendedPartitionDevice
    kernel_dev = Bootloader::UdevMapping.to_kernel_device(dev)

    @extended_partition_device = ::Bootloader::Stage1Device.new(kernel_dev)
  end

  include_real_devs?(@extended_partition_device.real_devices)
end

- (Boolean) include?(dev)

Checks if given device is used as stage1 location

Parameters:

  • dev (String)

    device to check, it can be kernel or udev name, it can also be virtual or real device, method convert it as needed

Returns:

  • (Boolean)


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

def include?(dev)
  kernel_dev = Bootloader::UdevMapping.to_kernel_device(dev)
  real_devs = ::Bootloader::Stage1Device.new(kernel_dev).real_devices

  include_real_devs?(real_devs)
end

- (Object) inspect



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

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

- (Boolean) mbr?

Returns:

  • (Boolean)


97
98
99
100
101
102
103
104
105
106
# File 'src/lib/bootloader/stage1.rb', line 97

def mbr?
  if !@mbr_device
    dev = Yast::BootStorage.mbr_disk
    kernel_dev = Bootloader::UdevMapping.to_kernel_device(dev)

    @mbr_device = ::Bootloader::Stage1Device.new(kernel_dev)
  end

  include_real_devs?(@mbr_device.real_devices)
end

- (Object) merge(other)



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'src/lib/bootloader/stage1.rb', line 180

def merge(other)
  # merge here is a bit tricky, as for stage1 does not exist `defined?`
  # because grub_installdevice contain value or not, so it is not
  # possible to recognize if chosen or just not set
  # so logic is following
  # 1) if any flag is set to true, then use it because e.g. autoyast defined flags,
  #    but devices usually not
  # 2) if there is devices specified, then set also flags to value in other
  #    as it mean, that there is enough info to decide
  log.info "stage1 to merge #{other.inspect}"

  if other.devices.empty?
    self.activate    = activate? || other.activate?
    self.generic_mbr = generic_mbr? || other.generic_mbr?
  else
    clear_devices
    other.devices.each { |d| add_udev_device(d) }

    self.activate    = other.activate?
    self.generic_mbr = other.generic_mbr?
  end

  log.info "stage1 after merge #{inspect}"
end

- (Object) propose

Propose and set Stage1 location. It sets properly all devices where bootloader stage1 should be written. It also sets if partition should be activated by setting its boot flag. It proposes if generic_mbr will be written into MBR. The proposal is only based on storage information, disregarding any existing values of the output variables (which are respected at other times, in AutoYaST).



142
143
144
# File 'src/lib/bootloader/stage1.rb', line 142

def propose
  Stage1Proposal.propose(self)
end

- (Object) read



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

def read
  @model.load
end

- (Object) remove_device(dev)



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

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)


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

def root_partition?
  if !@root_partition_device
    dev = Yast::BootStorage.RootPartitionDevice
    kernel_dev = Bootloader::UdevMapping.to_kernel_device(dev)

    @root_partition_device = ::Bootloader::Stage1Device.new(kernel_dev)
  end

  include_real_devs?(@root_partition_device.real_devices)
end

- (Object) write



38
39
40
# File 'src/lib/bootloader/stage1.rb', line 38

def write
  @model.save
end