Skip to content

LogicalVolume.create should allow for %FREE option #47

@jrafanie

Description

@jrafanie

For example, we should use this to avoid specifying specific sizes:
lvcreate -l 100%FREE -n lv vg

irb(main):002:0> disk = LinuxAdmin::Disk.local.select {|d| d.path == "/dev/sdb"}.first
=> #<LinuxAdmin::Disk:0x000000046a2508 @path="/dev/sdb">

irb(main):003:0> partition = disk.partitions.first
=> #<LinuxAdmin::Partition:0x0000000471eb58 @id=1, @size=1125122048.0, @disk=#<LinuxAdmin::Disk:0x000000046a2508 @path="/dev/sdb", @parted_default_options=["--script", "/dev/sdb"], @partitions=[#<LinuxAdmin::Partition:0x0000000471eb58 ...>]>, @fs_type=nil, @start_sector="1049kB", @end_sector=1126170624.0, @partition_type="primary">

irb(main):004:0> pv = LinuxAdmin::PhysicalVolume.create(partition)
=> #<LinuxAdmin::PhysicalVolume:0x00000004f9fae8 @device_name="/dev/sdb1", @volume_group=nil, @size=1125122048.0>

irb(main):005:0> vg = LinuxAdmin::VolumeGroup.create("vg", pv)
=> #<LinuxAdmin::VolumeGroup:0x00000004471e28 @name="vg_data">

It should be easier to determine the size of the logical volume:

irb(main):015:0> begin; lv = LinuxAdmin::LogicalVolume.create("lv", vg, ((disk.size/1.megabyte) - 1.bytes)); rescue => err; puts err.result.inspect; end
#<CommandResult:0x000000051de688 @output="", @error="  Volume group \"vg\" has insufficient free space (255 extents): 268 required.\n", @exit_status=5>
=> nil

irb(main):016:0> begin; lv = LinuxAdmin::LogicalVolume.create("lv", vg, ((disk.size/1.megabyte) - 14.bytes)); rescue => err; puts err.result.inspect; end
#<CommandResult:0x000000052286c0 @output="  Rounding up size to full physical extent 1.04 GiB\n", @error="  Volume group \"vg\" has insufficient free space (255 extents): 265 required.\n", @exit_status=5>
=> nil

It's not simple to use all of the remaining space so you have to guess or calculate the right number:

irb(main):017:0> begin; lv = LinuxAdmin::LogicalVolume.create("lv", vg, ((disk.size/1.megabyte) - 100.bytes)); rescue => err; puts err.result.inspect; end
=> #<LinuxAdmin::LogicalVolume:0x00000004ff7680 @name="lv", @volume_group=#<LinuxAdmin::VolumeGroup:0x00000004471e28 @name="vg">, @sectors=973.0>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions