Creating and pre-installing things inside a toolbox at system installation via ignition-file

Hi there,
still messing around finding the perfect ignintion file configuration for myself.

I love using tools like btop on my FCOS system so at the moment i am already installing these tools right at OS-installation time via ignition file via rpm-ostree install

To get a even more cleaner OS i am asking myself if it is possible to perform at system installation time via ignition file

  1. Creating a toolbox LINK
  2. Install applications like btop via sudo yum install btop right from the start

I know i can use toolbox create maybe but is it possible to trigger commands inside of the toolbox from “the outside”?

Is my plan good practice or is there no reason for now trying to shift my “convenience applications” i even want to keep on an FCOS system into toolbox

Thanks a lot

Sorry right after writing here i think i found the answer
There is a better documentation mentioned over here

So i think it should be something like this

toolbox -y create; toolbox -y run sudo yum install btop ncdu

If someone has any additions to that, feel free to correct my guessings

Small correction, you have to add another -y for yum

toolbox -y create; toolbox -y run sudo yum -y install btop ncdu

So i guess it should be something like this:

systemd:
  units:
    # Prepare Toolbox and Install Convenience Applications
    - name: toolbox-prepare.service
      enabled: true
      contents: |
        [Unit]
        Description=Layer convenience applications
        Wants=network-online.target
        After=network-online.target

        [Service]
        Type=oneshot
        RemainAfterExit=yes
        ExecStart=toolbox -y create; toolbox -y run sudo yum -y install btop ncdu

        [Install]
        WantedBy=multi-user.target

1 Like

OK, i was now able to test it

  1. I had to split the two commands into separate ExecStart rows
  2. Im getting Error: failed to get the user config directory

Can someone help me out in reconfiguring my unit to be able to execute at a point where toolbox is able to run?

systemd:
  units:
    # Create Toolbox and Preinstall applications
    - name: toolbox-prepare.service
      enabled: true
      contents: |
        [Unit]
        Description=Create toolbox and install convenience applications
        Wants=network-online.target
        After=network-online.target

        [Service]
        Type=oneshot
        RemainAfterExit=yes
        ExecStart=/bin/toolbox -y create
        ExecStart=/bin/toolbox -y run sudo yum -y install btop inxi pciutils ncdu vim neofetch fzf

        [Install]
        WantedBy=multi-user.target
May 08 05:34:14 blackpearl toolbox[1359]: Error: failed to get the user config directory
May 08 05:34:14 blackpearl systemd[1]: toolbox-prepare.service: Main process exited, code=exited, status=1/FAILURE
May 08 05:34:14 blackpearl systemd[1]: toolbox-prepare.service: Failed with result 'exit-code'.```

Shifting the unit to multi-user.target and specifying User= for the unit ends up in the following error

May 08 06:11:19 blackpearl systemd[1]: Starting toolbox-prepare.service - Create toolbox and install convenience applications...
May 08 06:11:19 blackpearl toolbox[1619]: Error: failed to create runtime directory toolbox: mkdir toolbox: operation not permitted
May 08 06:11:19 blackpearl systemd[1]: toolbox-prepare.service: Main process exited, code=exited, status=1/FAILURE
systemd:
  units:
    # Create Toolbox and Preinstall applications
    - name: toolbox-prepare.service
      enabled: true
      contents: |
        [Unit]
        Description=Create toolbox and install convenience applications
        # Run after all other services
        Wants=multi-user.target
        After=multi-user.target

        [Service]
        # Very important otherwise config directory can not be found
        User=core
        Type=oneshot
        RemainAfterExit=yes
        ExecStart=/bin/toolbox -y create
        ExecStart=/bin/toolbox -y run sudo yum -y install btop inxi pciutils ncdu vim neofetch fzf

        [Install]
        WantedBy=multi-user.target

Added coreos, toolbx and removed workstation

I think you are nearly there. You might want to try installing the service as a user service instead, which is described here in the documentation. Don’t forget to enable lingering, else it wont be executed on boot. I tried your service locally as a user service and it seems to work (I removed the User=core line).

You also want to add a check to the service so it is only executed on the first boot, else it will try to create a toolbox on every boot. For that see this documentation page.

2 Likes

@job79
Thank you so much with your help i was able to create the butane/ignition file below and it seems to work

To be honest it seems a bit complicated for me (as a noob in terms of systemd) but the documentation was sufficient enough

Your hint regarding a new toolbox each and every boot → The only trick was just to set the Type to oneshot right?

variant: fcos
version: 1.5.0
storage:
    # Activate Lingering to run on boot
    - path: /var/lib/systemd/linger/core
      mode: 0644
    # Create Systemd for pre-configuring toolbox
    - path: /home/core/.config/systemd/user/toolbox-prepare.service
      mode: 0644
      contents:
        inline: |
          [Unit]
          Description=Create toolbox and install convenience applications
          # Run after all other services
          Wants=multi-user.target
          After=multi-user.target

          [Service]
          Type=oneshot
          RemainAfterExit=yes
          ExecStart=/bin/toolbox -y create
          ExecStart=/bin/toolbox -y run sudo yum -y install btop inxi pciutils ncdu vim neofetch fzf

          [Install]
          WantedBy=multi-user.target
      user:
        name: core
      group:
        name: core
  links:
    # Symlink needed to get toolbox working
    - path: /etc/localtime
      target: ../usr/share/zoneinfo/UTC
      overwrite: true
      hard: false
    # Manually enable user service
    - path: /home/core/.config/systemd/user/default.target.wants/toolbox-prepare.service
      user:
        name: core
      group:
        name: core
      target: /home/core/.config/systemd/user/toolbox-prepare.service
      hard: false
  directories:
    # Create missing directories and set permissions
    - path: /home/core/.config
      mode: 0755
      user:
        name: core
      group:
        name: core
    - path: /home/core/.config/systemd
      mode: 0755
      user:
        name: core
      group:
        name: core
    - path: /home/core/.config/systemd/user
      mode: 0755
      user:
        name: core
      group:
        name: core
    - path: /home/core/.config/systemd/user/default.target.wants
      mode: 0755
      user:
        name: core
      group:
        name: core

You need ConditionPathExists=!/var/lib/%N.stamp. Check out systemd.unit.

You can probably also add Before=zincati.service as described in Adding OS extensions to the host system :: Fedora Docs.

2 Likes