blkid
Get attirbutes of block devices on a system in ruby.
linux manual
Basic Usage
require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: '127.0.1.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
host.su('root')
result = host.blkid(device: '/dev/vda1')
result.success?
true
result.name
"/dev/vda1"
result.type
"ext4"
This command needs escalated privlidges to access certain attributes of a device.
Parameters
| Field | Type | Description | 
|---|---|---|
| label | 
              
                string | Search a device drive by label | 
| uuid | 
              
                string | Search a device drive by uuid | 
| device | 
              
                string | Search a device drive by name | 
Result
Returns an array of BlkidDevice structs if parameters are blank, or device field is present. If label or uuid is presented as a search parameter, the name of the device will be the only item returned.
BlkidDevice Fields
| Field | Type | Description | 
|---|---|---|
| name | 
              
                string
              
             | The name of the block device | 
| label | 
              
                string
              
             | A descriptive identifier used for easy querying of the device block. | 
| uuid | 
              
                string
              
             | Unique identifier assigned to the filesystem | 
| type | 
              
                string
              
             | Filesystem formatted partition type (ext4, xfs, fat, etc) | 
| uuid_sub | 
              
                string
              
             | Unique identifier assigned to a brfts volume | 
| label_fatboot | 
              
                string
              
             | A label given to a fat formatted partiton device. | 
| version | 
              
                double
              
             | The filesystem version | 
| usage | 
              
                string
              
             | How is the device block being used, eg "filesystem", "raid", etc. | 
| part_uuid | 
              
                string
              
             | Unique identifier for GPT partitioned disks | 
| part_entry_scheme | 
              
                string
              
             | Partition table type | 
| part_entry_uuid | 
              
                string
              
             | Unique identifier for the partition entry | 
| part_entry_type | 
              
                string
              
             | Partition type, 0xNN (e.g 0x82) or type UUID (gpt only) or type string (mac) | 
| part_entry_number | 
              
                string
              
             | Partition number | 
| part_entry_offset | 
              
                string
              
             | The beginning of the offset | 
| part_entry_size | 
              
                string
              
             | The size of the partition | 
| part_entry_disk | 
              
                string
              
             | The whole disk, maj:min | 
| minimum_io_size | 
              
                string
              
             | Minimum size which is the device's preferred unit of I/O. For RAID arrays it is often the stripe chunk size. | 
| physical_sector_size | 
              
                string
              
             | The smallest unit a physical storage device can write atomically. It is usually the same as the logical sector size but may be bigger. | 
| logical_sector_size | 
              
                string
              
             | The smallest unit the storage device can address. It is typically 512 bytes | 
Return Example
host.blkid(device: '/dev/vda1')[0]
#<Struct:Kanrisuru::Core::Disk::BlkidDevice:0x000005a0
  label = "cloudimg-rootfs",
  label_fatboot = nil,
  logical_sector_size = 512,
  minimum_io_size = 512,
  name = "/dev/vda1",
  part_entry_disk = "252:0",
  part_entry_number = 1,
  part_entry_offset = 227328,
  part_entry_scheme = "gpt",
  part_entry_size = 16549855,
  part_entry_type = "0fc63daf-8483-4772-8e79-3d69d8477de4",
  part_entry_uuid = "6cbfe876-34eb-487b-8389-7d7cb327ddd9",
  part_uuid = nil,
  physical_sector_size = 512,
  type = "ext4",
  usage = "filesystem",
  uuid = "b8976b0d-6f88-49b9-8e4a-787323d98d2c",
  uuid_sub = nil,
  version = 1.0
>
Exit Status
| Code | Description | 
|---|---|
| 0 | Success | 
| 2 | If the specified token was not found, or no (specified) devices could be identified | 
| 4 | Usage or other errors | 
Additional Examples
host.blkid(uuid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx').to_s
"/dev/vda1"
host.blkid(label: 'cloudimg-rootfs').to_s
"/dev/vda1"
Tested On
- Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES