Skip to content

Latest commit

 

History

History
 
 

initramfs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

initramfs

The initramfs role is included by the shrink_lv and bigboot roles to run an atomic flow of building and using a temporary initramfs in a reboot and restoring the original one.

The role is designed to be internal for this collection and support the automation of RHEL in-place upgrades, but can also be used for other purposes.

Contents

To allow fast fail, the role provides a preflight.yml tasks file that should be included early in the play that ultimately includes the main role that actually reboots the host. Refer the usage section below for example.

Role Variables

All variables are optional

initramfs_add_modules

initramfs_add_modules is a space-separated list of dracut modules to be added to the default set of modules. See dracut --add option for details.

initramfs_backup_extension

initramfs_backup_extension is the file extension for the backup initramfs file.

Defaults to old

initramfs_post_reboot_delay

initramfs_post_reboot_delay sets the amount of Seconds to wait after the reboot command was successful before attempting to validate the system rebooted successfully. The value is used for post_reboot_delay parameter

Defaults to 30

initramfs_reboot_timeout

initramfs_reboot_timeout sets the maximum seconds to wait for machine to reboot and respond to a test command. The value is used for reboot_timeout parameter

Defaults to 7200

Example role usage

We will refer to the bigboot role of this collection to explain how the initramfs role can be used. Let's look at the tasks/main.yaml of the bigboot role. After the required facts have been gathered, the Validate initramfs preflight task includes the initramfs role preflight tasks:

- name: Validate initramfs preflight
  ansible.builtin.include_role:
    name: initramfs
    tasks_from: preflight

If this is successful, the bigboot role continues to perform additional tasks and checks specific to its function. With that done, it moves on to tasks/do_bigboot_reboot.yml which configures a dracut pre-mount hook to prepare for the customized initramfs reboot:

- name: Copy dracut pre-mount hook files
  ansible.builtin.copy:
    src: "{{ item }}"
    dest: /usr/lib/dracut/modules.d/99extend_boot/
    mode: "0554"
  loop:
    - bigboot.sh
    - module-setup.sh
    - sfdisk.static

- name: Resolve and copy pre-mount hook wrapper script
  ansible.builtin.template:
    src: increase-boot-partition.sh.j2
    dest: /usr/lib/dracut/modules.d/99extend_boot/increase-boot-partition.sh
    mode: '0554'

After that, it includes the main initramfs role which will create a custom initramfs built with the dracut hook configured above, reboot the host to run the hook, and lastly, restore the original initramfs after the reboot:

- name: Create the initramfs and reboot to run the module
  vars:
    initramfs_add_modules: "extend_boot"
  ansible.builtin.include_role:
    name: initramfs

Also, note that while the initramfs role handles restoring the original initramfs, it is up to the including play to clean up the dracut hook files it configured. We see this with the Remove dracut extend boot module task that immediately follows the task including the initramfs role:

- name: Remove dracut extend boot module
  ansible.builtin.file:
    path: /usr/lib/dracut/modules.d/99extend_boot
    state: absent

The shrink_lv role of this collection is another example of using the initramfs role that you may study.