Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom partitioning #209

Closed
Tracked by #1066
mudler opened this issue Oct 12, 2022 · 13 comments · Fixed by kairos-io/kairos-docs#41
Closed
Tracked by #1066

Custom partitioning #209

mudler opened this issue Oct 12, 2022 · 13 comments · Fixed by kairos-io/kairos-docs#41
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request lane/ux

Comments

@mudler
Copy link
Member

mudler commented Oct 12, 2022

Is your feature request related to a problem? Please describe.
A way to configure partitions via config file

Describe the solution you'd like
A simple and detailed way in the config to declare the partitions after install. Ideally should just enlarge the elemental config so it just exposes the underlying configuration

Describe alternatives you've considered
Dropping the config file manually, but the solution is more a workaround. It can be achieved by adding an initramfs stage which overwrites the elemental-config

Additional context

@jimmykarily
Copy link
Contributor

When the config is mounted as a datasource iso (as suggested here), it partly works:

localhost:~ # cat /oem/userdata.yaml 
#cloud-config

users:
- name: "kairos"
  passwd: "kairos"

# Tell elemental to not create partitions
options:
  no-format: "true"

# User has to copy this file inside /oem
# because elemental will try to find stage steps there. Won't repect it here.
# Then the user has to install with
# `kairos-agent manual-install` with this file.
# Netbooting doesn't work for the same reason (elemental ignores the stages).
stages:
  before-install:
  - name: "Create a file"
    commands:
      - |
        touch /tmp/touched-before-install
  boot:
  # TODO: check which device exists
  - if:  '[ -e /dev/vda ] && (kairos-agent state get boot | grep -q unknown)'
    name: "Create partitions"
    commands:
      - |
        touch /tmp/touched-boot
    layout:
      device:
        path: /dev/vda
      add_partitions:
        - fsLabel: COS_STATE
          size: 16240 # At least 16gb
          pLabel: state
localhost:~ # ls /tmp/touched-*
/tmp/touched-boot
kairos-agent state get boot; echo
unknown
  • before-install didn't run (maybe I need more config to enable auto-install?)
  • the partition was not created:
localhost:~ # lsblk
NAME  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
fd0     2:0    1     4K  0 disk 
loop0   7:0    0 812.9M  1 loop /run/rootfsbase
sr0    11:0    1   364K  0 rom  
sr1    11:1    1  1024M  0 rom  
vda   253:0    0    30G  0 disk 

@jimmykarily
Copy link
Contributor

jimmykarily commented Mar 7, 2023

I seems to be failing:

$ journalctl
...
kd[1397]: eth0: DHCPv6 address 2a0d:3344:1a93:a010::3e9/128 (valid for 15min 49>
]: INFO[2023-03-07T12:36:58Z] Creating COS_STATE partition
]: ERRO[2023-03-07T12:36:58Z] Failed analyzing disk: exit status 1
]: ERRO[2023-03-07T12:36:58Z] Failed creating partitions: exit status 1
...

@jimmykarily
Copy link
Contributor

jimmykarily commented Mar 7, 2023

The error seems to originate here: https://github.com/kairos-io/elemental-cli/blob/main/pkg/partitioner/parted.go#L155

I created this PR to improve the error message: https://github.com/kairos-io/elemental-cli/pull/45/files
In the meantime, running that command on the VM manually shows this:

localhost:~ # parted --script --machine -- /dev/vda unit s print
Error: /dev/vda: unrecognised disk label
BYT;
/dev/vda:62914560s:virtblk:512:512:unknown:Virtio Block Device:;

If I run this first:

parted --script --machine -- /dev/vda mklabel msdos

the error goes away.

@jimmykarily
Copy link
Contributor

updated the config.yaml like this:

stages:
  boot:
  # TODO: check which device exists
  - if:  '[ -e /dev/vda ] && (kairos-agent state get boot | grep -q unknown)'
    name: "Create partitions"
    commands:
      - |
        parted --script --machine -- /dev/vda mklabel msdos
    layout:
      device:
        path: /dev/vda
      add_partitions:
        - fsLabel: COS_STATE
          size: 16240 # At least 16gb
          pLabel: state

and now it works:

localhost:~ # lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
fd0      2:0    1     4K  0 disk 
loop0    7:0    0 812.9M  1 loop /run/rootfsbase
sr0     11:0    1   364K  0 rom  
sr1     11:1    1  1024M  0 rom  
vda    253:0    0    30G  0 disk 
`-vda1 253:1    0  15.9G  0 part 

@jimmykarily
Copy link
Contributor

jimmykarily commented Mar 10, 2023

Currently working on a refactoring of the kairos config here: https://github.com/kairos-io/kairos/tree/209-custom-partitioning-refactor-config

We are extracting the code that collects configuration from 3 different sources:

  • local files in given directories
  • config from the kernel cmdline
  • remote files specified with config_url in any of the above (recursively)

When this is done, we will use this package to parse configuration in kairos-agent, elemental-cli, kcrypt and whatever consumer needs access to kairos-configuration. The consumers will unmarshal the merged Yamls into whatever Config object they mainain and they can do their own validations on that too.

This should fix the issue where elemental-cli doesn't read the stages: key when booting from network because it didn't fetch the config_url defined in the kernel cmdline.

@jimmykarily
Copy link
Contributor

Currently blocked by #1225

@jimmykarily
Copy link
Contributor

We have planned a refactoring that will make elemental-cli a kairos-agent subcommand. When that happens, #1225 will be easier to implement (config will probably be available in memory).

We came up with an alternative fix for this issue for now, which is to write down the kairos config to /oem before we call elemental install. This is our WIP branch: https://github.com/kairos-io/kairos/tree/209-pass-config-to-elemental

@jimmykarily
Copy link
Contributor

jimmykarily commented May 26, 2023

I'm trying the config above with a kairos-agent I've built from this: kairos-io/kairos-agent#32

I had to change the stage from boot to kairos-install.pre.before which runs before partitioning happens (TODO: Document this stage) because before-install runs before the installation of the OS but after partitioning has happened. It seems to be working for one partition. I'll try to do the full partitioning manually and see.

I also had to add install.no-format: true to /etc/elemental/config.yaml to skip formatting. Maybe we should expose this setting the kairos config instead to allow the user to keep all configuration in one place. After all, there are many ways to provide the kairos config (e.g. remote_url through kernel cmdline) so having to edit the elemental config manually limits the installation options.

jimmykarily added a commit to kairos-io/kairos-agent that referenced this issue May 26, 2023
to let the user set this in the cloud-config file instead of
/etc/elemental/config.yaml

See also here:
kairos-io/kairos#209 (comment)

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
@jimmykarily
Copy link
Contributor

This is the config that works with the PR branch:

#cloud-config

install:
  no-format: true

stages:
  kairos-install.pre.before:
  # TODO: check which device exists
  - if:  '[ -e /dev/vda ] && (kairos-agent state get boot | grep -q livecd_boot)'
    name: "Create partitions"
    commands:
      - |
        parted --script --machine -- /dev/vda mklabel msdos
    layout:
      device:
        path: /dev/vda
      expand_partition:
        size: 0 # All available space
      add_partitions:
        - fsLabel: COS_OEM
          size: 64
          pLabel: oem
        - fsLabel: COS_RECOVERY
          size: 8500
          pLabel: recovery
        - fsLabel: COS_STATE
          size: 18000
          pLabel: state
        - fsLabel: COS_PERSISTENT
          pLabel: persistent
          size: 25000
          filesystem: "ext4"

users:
- name: "kairos"
  passwd: "kairos"

I had to make some fixes so that all partitions are created and "expand" happens after creation.

jimmykarily added a commit to kairos-io/kairos-agent that referenced this issue May 30, 2023
to let the user set this in the cloud-config file instead of
/etc/elemental/config.yaml

See also here:
kairos-io/kairos#209 (comment)

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
jimmykarily added a commit to kairos-io/kairos-agent that referenced this issue May 31, 2023
to let the user set this in the cloud-config file instead of
/etc/elemental/config.yaml

See also here:
kairos-io/kairos#209 (comment)

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
@jimmykarily
Copy link
Contributor

Let's write some docs for this an then it's done

@jimmykarily jimmykarily added the documentation Improvements or additions to documentation label Jun 26, 2023
@mauromorales
Copy link
Member

Looking into this I see that it is possible to create a system despite the system not having enough space to handle the indicated partitions. The errors show up in the installation logs but it doesn't fail. Is this the expected UX? it means the user is required to check that there were no errors during installation

INFO[2023-06-26T13:19:29Z] Creating COS_PERSISTENT partition            
ERRO[2023-06-26T13:19:29Z] Failed creating partitions: not enough free space in disk. Required: 51200000 sectors; Available 29480961 sectors 
INFO[2023-06-26T13:19:29Z] Done executing stage 'kairos-install.pre.before' 
INFO[2023-06-26T13:19:29Z] Running stage: kairos-install.pre            
INFO[2023-06-26T13:19:29Z] Done executing stage 'kairos-install.pre'    
INFO[2023-06-26T13:19:29Z] Running stage: kairos-install.pre.after      
INFO[2023-06-26T13:19:29Z] Done executing stage 'kairos-install.pre.after' 
INFO[2023-06-26T13:19:29Z] Running stage: kairos-install.pre.before     
INFO[2023-06-26T13:19:29Z] Done executing stage 'kairos-install.pre.before' 
INFO[2023-06-26T13:19:29Z] Running stage: kairos-install.pre            
INFO[2023-06-26T13:19:29Z] Done executing stage 'kairos-install.pre'    
INFO[2023-06-26T13:19:29Z] Running stage: kairos-install.pre.after      
INFO[2023-06-26T13:19:29Z] Done executing stage 'kairos-install.pre.after' 
INFO[2023-06-26T13:19:29Z] Some errors found but were ignored. Enable --strict mode to fail on those or --debug to see them in the log 
WARN[2023-06-26T13:19:29Z] 1 error occurred:
        * Failed creating partitions: not enough free space in disk. Required: 51200000 sectors; Available 29480961 sectors
 

@mauromorales
Copy link
Member

@jimmykarily @mudler ^^

@jimmykarily
Copy link
Contributor

jimmykarily commented Jun 26, 2023

I don't know. But it already tell you to use --strict mode if you like it to fail in those cases. It seems intentional to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request lane/ux
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants