Fstab
The Kanrisuru::Remote::Fstab
class helps manage the fstab file on a remote host. This includes looking up existing entries, validating mounted block devices, and adding new entries to the file.
Namespace
Fstab::Entry
Fstab::Options
Public Class Methods
new
Instantiates a new instance of fstab. Takes a host instance and an optional path to the fstab file on the remote host.
fstab = Kanrisuru::Remote::Fstab.new(host)
fstab.to_s
"UUID=6cd50e51-cfc6-40b9-9ec5-f32fa2e4ff03 / xfs defaults 0 0"
Public Instance Methods
[]
Fetches an entry in the fstab by device name, uuid, or label.
fstab['/dev/vda1']
#<Kanrisuru::Remote::Fstab::Entry:0x920 @line=LABEL=cloudimg-rootfs / ext4 defaults 0 0 @device=/dev/vda1 @label=cloudimg-rootfs@uuid= @freq=0 @pasno=0@opts=<Kanrisuru::Remote::Fstab::Options:0x940 @opts={"defaults"=>true} @type=ext4>}>
get_entry
Fetches an entry in the fstab by device name, uuid, or label.
fstab.get_entry('/dev/vda1')
#<Kanrisuru::Remote::Fstab::Entry:0x920 @line=LABEL=cloudimg-rootfs / ext4 defaults 0 0 @device=/dev/vda1 @label=cloudimg-rootfs@uuid= @freq=0 @pasno=0@opts=<Kanrisuru::Remote::Fstab::Options:0x940 @opts={"defaults"=>true} @type=ext4>}>
«
Add a new fstab entry into the fstab. Can take the form of a Kanrisuru::Remote::Fstab::Entry
instance or a line formatted as normally in the fstab file.
fstab << Kanrisuru::Remote::Fstab::Entry.new(
device: '/dev/vda14',
mount_point: '/mnt/test',
type: 'ext4',
opts: { defaults: true },
freq: '0',
passno: '0'
)
fstab.to_s
"LABEL=cloudimg-rootfs / ext4 defaults 0 0"
"LABEL=UEFI /boot/efi vfat defaults 0 0"
"/dev/vda14 /mnt/test ext4 defaults 0 0"
append
Add a new fstab entry into the fstab. Can take the form of a Kanrisuru::Remote::Fstab::Entry
instance or a line formatted as normally in the fstab file.
fstab.append("/dev/vda14 /mnt/test ext4 defaults 0 0")
fstab['/dev/vda14']
#<Kanrisuru::Remote::Fstab::Entry:0x1040 @line=/dev/vda14 /mnt/test ext4 defaults 0 0 @device=/dev/vda14 @label='' @uuid='' @freq=0 @pasno=0 @opts=<Kanrisuru::Remote::Fstab::Options:0x1060 @opts={"defaults"=>true} @type=ext4>}>
delete
Remove a fstab entry.
fstab.delete('/dev/vda14')
each
Iterate through each fstab entry device.
fstab.each do |entry|
case entry.type
when 'ext4'
## do something for ext4 device types
when 'xfs'
## do something for xfs device types
else
## do something for other device types
end
end
append_file!
Append new entries to fstab. Existing ones in the fstab file won’t be updated.
fstab << '/dev/vda14 /mnt/test ext4 defaults 0 0'
fstab.append_file!
write_file!
Overwrite the entire fstab. This will update any existing lines in the fstab file with the present state of the entries.
to_s
Output the fstab entries as a string
reload!
Fetches all the entries from the fstab file on the remote host.