Class: Bootloader::DevicePath

Inherits:
Object
  • Object
show all
Defined in:
src/lib/bootloader/device_path.rb

Overview

Class for device path

Examples:

device path can be defined explicitly

DevicePath.new("/devs/sda")

definition by UUID is translated to device path

dev = DevicePath.new("UUID=\"0000-00-00\"")
dev.path -> "/dev/disk/by-uuid/0000-00-00"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dev) ⇒ DevicePath

Performs initialization

Parameters:

  • dev (<String>)

    either a path like /dev/sda or special string for uuid or label



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'src/lib/bootloader/device_path.rb', line 20

def initialize(dev)
  dev = dev.strip

  @path = if dev_by_uuid?(dev)
    # if defined by uuid, convert it
    dev.sub(/UUID="([-a-zA-Z0-9]*)"/, '/dev/disk/by-uuid/\1')
  elsif dev_by_label?(dev)
    # as well for label
    dev.sub(/LABEL="(.*)"/, '/dev/disk/by-label/\1')
  else
    # add it exactly (but whitespaces) as specified by the user
    dev
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'src/lib/bootloader/device_path.rb', line 15

def path
  @path
end

Instance Method Details

#exists?Boolean Also known as: valid?

Returns true if the @path exists in the system.

Returns:

  • (Boolean)

    true if the @path exists in the system



36
37
38
# File 'src/lib/bootloader/device_path.rb', line 36

def exists?
  !devicegraph.find_by_any_name(path).nil?
end

#label?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'src/lib/bootloader/device_path.rb', line 46

def label?
  !!(path =~ /by-label/)
end

#uuid?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'src/lib/bootloader/device_path.rb', line 42

def uuid?
  !!(path =~ /by-uuid/)
end