kairos-io / kairos

:penguin: The immutable Linux meta-distribution for edge Kubernetes.
https://kairos.io
Apache License 2.0
1.13k stars 97 forks source link

`layout` Plugin Fails to Allocate Partition If Free Space is Not at the End of the Disk #2841

Closed dnugmanov closed 3 weeks ago

dnugmanov commented 2 months ago

Description:

When attempting to use the layout plugin to allocate a partition, the plugin only attempts to allocate from the end of the disk. If there is free space available elsewhere on the disk but not at the end, the plugin fails with a warning about insufficient unpartitioned space.

Related code: https://github.com/mudler/yip/blob/3eeeb15bc6b921a977c1f44cf30e77c81dcd4dc6/pkg/plugins/layout.go#L619

Steps to Reproduce:

  1. Prepare a disk (/dev/sdb in this case) with free space not at the end.

  2. Use the following test.yaml configuration:

    stages:
      # "test" is the stage
      test:
        - layout:
            device:
              path: /dev/sdb
            add_partitions:
              - fsLabel: COS_STATE
                size: 8192
                pLabel: state
  3. Run yip with the command:

    ./yip -s test test.yaml
  4. The output indicates a warning:

    root@kal-c2-82-31-210:/home/ubuntu/yip# ./yip -s test test.yaml
    INFO[0000] yip version -g
    INFO[0000] Running stage: test
    INFO[0000] Processing stage step ''. ( commands: 0, files: 0, ... )
    WARN[0000] Not enough unpartitioned space in disk to operate
    INFO[0000] Done executing stage 'test'

Additional Context:

The issue persists even though the free space on the disk is confirmed using sgdisk and parted as shown below:

root@kal-c2-82-31-210:/home/ubuntu/yip# sgdisk --verify /dev/sdb
No problems found. 31334333 free sectors (14.9 GiB) available in 2 segments, the largest of which is 31332318 (14.9 GiB) in size.
root@kal-c2-82-31-210:/home/ubuntu/yip# sudo parted /dev/sdb unit mB print free
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 16106MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start    End      Size     File system  Name     Flags
        0.02MB   16042MB  16042MB  Free Space
 1      16042MB  16105MB  62.9MB   ext4         primary
        16105MB  16106MB  1.03MB   Free Space

Expected Behavior:

The layout plugin should be able to allocate partitions from any available free space on the disk, not just from the end.

Actual Behavior:

The plugin fails to allocate the partition unless free space is available at the end of the disk.

jimmykarily commented 1 month ago

The plugin only supports automatic allocation of free space at the end of the disk and there are no plans to support different scenarios in the short term. The implementation for this will be a bit complex and there is already the completely manual partitioning solution that can be used as a workaround.