Class: CFA::Grub2::DeviceMap
- Inherits:
-
BaseModel
- Object
- BaseModel
- CFA::Grub2::DeviceMap
- Defined in:
- lib/cfa/grub2/device_map.rb
Overview
Represents grub device map in /boot/grub2/device_map for details see www.gnu.org/software/grub/manual/html_node/Device-map.html Main features:
-
Do not overwrite files
-
When setting value first try to just change value if key already exists
-
When grub key is not there, then add to file
-
checks and raise exception if number of mappings exceed limit 8. Limitation is caused by BIOS Int 13 used by grub2 for selecting boot device.
Constant Summary collapse
- PARSER =
AugeasParser.new("device_map.lns")
- PATH =
"/boot/grub2/device.map".freeze
Instance Method Summary collapse
-
#add_mapping(grub_device, system_device) ⇒ Object
Appends to configuration mapping between grub_device and system_device.
-
#grub_device_for(system_dev) ⇒ String
Grub device name for given system device.
-
#grub_devices ⇒ Array<String>
List of all grub devices which have mapping.
-
#initialize(file_handler: nil) ⇒ DeviceMap
constructor
A new instance of DeviceMap.
-
#remove_mapping(grub_device) ⇒ Object
Removes mapping for given grub device.
- #save(changes_only: false) ⇒ Object
-
#system_device_for(grub_device) ⇒ String
System device name for given grub device.
Constructor Details
Instance Method Details
#add_mapping(grub_device, system_device) ⇒ Object
if mapping for given grub device is already defined, it will be overwritten
Appends to configuration mapping between grub_device and system_device
48 49 50 |
# File 'lib/cfa/grub2/device_map.rb', line 48 def add_mapping(grub_device, system_device) generic_set(grub_device, system_device) end |
#grub_device_for(system_dev) ⇒ String
Returns grub device name for given system device.
33 34 35 36 37 38 |
# File 'lib/cfa/grub2/device_map.rb', line 33 def grub_device_for(system_dev) matcher = Matcher.new(value_matcher: system_dev) entry = data.select(matcher) entry.empty? ? nil : entry.first[:key] end |
#grub_devices ⇒ Array<String>
Returns list of all grub devices which have mapping. If there is no mapping, then it return empty list.
59 60 61 62 63 64 |
# File 'lib/cfa/grub2/device_map.rb', line 59 def grub_devices matcher = Matcher.new { |k, _v| k !~ /comment/ } entries = data.select(matcher) entries.map { |e| e[:key] } end |
#remove_mapping(grub_device) ⇒ Object
Removes mapping for given grub device
53 54 55 |
# File 'lib/cfa/grub2/device_map.rb', line 53 def remove_mapping(grub_device) data.delete(grub_device) end |
#save(changes_only: false) ⇒ Object
26 27 28 29 30 |
# File 'lib/cfa/grub2/device_map.rb', line 26 def save(changes_only: false) raise "Too many grub devices. Limit is 8." if grub_devices.size > 8 super end |
#system_device_for(grub_device) ⇒ String
Returns system device name for given grub device.
41 42 43 |
# File 'lib/cfa/grub2/device_map.rb', line 41 def system_device_for(grub_device) data[grub_device] end |