This is the development version of Kanrisuru. Since this is still a pre-1.0 release, we don't recommend using this in system-critical production environments.

Kanrisuru

lsblk

List block devices in ruby
linux manual

Basic Usage

require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: '127.0.1.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])

result = host.lsblk
result.success?
true

result[0].name
"vda"

result[0].children[0].name
"vda1"

result[0].children[0].mount_point
"/"

result[0].fsize
'8G'

result[0].children[0].fsize
"7.9G"

result[0].type
"disk"

result[0].children[0].type
"part"

Parameters

Field Type Description
all boolean
Toggle restriction of listing all devices on a system
paths boolean
Show absolute file path for device location
nodeps boolean
Don't print device holders or slaves.

Result

Returns an array of LsblkDevice structs. If there are child devices of the block device, each device has a children array of LsblkDevice structs.

Lsblk starting on version 2.27 supports a JSON output. We currently don't have a parser supporting previous versions of lsblk with a nested output of the block devices. For versions 2.26 and earlier, the block devices will be structured as a flat array.

LsblkDevice Fields

Field Type Description
name string The name of the block device
maj_dev integer The major device number assigned to the block device
min_dev integer The minor device number assigned to the block device
removable_device boolean This field indicates if the device can be removed or not
readonly_device boolean If the device can only read from, or write/read
owner string The owner of the block device
group string The group the block device belongs to
mode string The permission fields for the owner, group, and other
fsize string The total size of the block device
type string Which disk type the block device is
mount_point string Where the block device mount point is mounted at
fs_type string If the block device is partitioned, what type of file system type is
uuid string The unique UUID field given to the device
children array An array of nested block devices, in the form of `LsblkDevice` structs

Return Example

host.lsblk.data[0]
#<Struct:Kanrisuru::Core::Disk::LsblkDevice:0x00005af0
  fsize = "8G",
  children = [
    #<Struct:Kanrisuru::Core::Disk::LsblkDevice:0x00005b68
      fsize = "7.9G",
      children = nil,
      fs_type = "ext4",
      group = "disk",
      maj_dev = 252,
      min_dev = 1,
      mode = "brw-rw----",
      mount_point = "/",
      name = "vda1",
      owner = "root",
      readonly_device = false,
      removable_device = false,
      type = "part",
      uuid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    >,
    #<Struct:Kanrisuru::Core::Disk::LsblkDevice:0x00005d48
      fsize = "4M",
      children = nil,
      fs_type = nil,
      group = "disk",
      maj_dev = 252,
      min_dev = 14,
      mode = "brw-rw----",
      mount_point = nil,
      name = "vda14",
      owner = "root",
      readonly_device = false,
      removable_device = false,
      type = "part",
      uuid = nil
    >,
    #<Struct:Kanrisuru::Core::Disk::LsblkDevice:0x00005eb0
      fsize = "106M",
      children = nil,
      fs_type = "vfat",
      group = "disk",
      maj_dev = 252,
      min_dev = 15,
      mode = "brw-rw----",
      mount_point = "/boot/efi",
      name = "vda15",
      owner = "root",
      readonly_device = false,
      removable_device = false,
      type = "part",
      uuid = "xxxx-xxxx"
    >
  ],
  fs_type = nil,
  group = "disk",
  maj_dev = 252,
  min_dev = 0,
  mode = "brw-rw----",
  mount_point = nil,
  name = "vda",
  owner = "root",
  readonly_device = false,
  removable_device = false,
  type = "disk",
  uuid = nil
>

Exit Status

Code Description
0 Success
1 Failure
32 None of specified devices found
64 Some specified devices found, some not found

Tested On

  • Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES