initoverlayfs icon indicating copy to clipboard operation
initoverlayfs copied to clipboard

ostree integration

Open ericcurtin opened this issue 2 years ago • 11 comments

This is just so it appears on the initoverlayfs project tracker also, this is the primary ticket:

https://github.com/ostreedev/ostree/issues/3066

ericcurtin avatar Dec 06 '23 17:12 ericcurtin

So where we should insert the code

https://github.com/coreos/rpm-ostree

#[context("Running dracut")]
fn run_dracut(kernel_dir: &str) -> Result<()> {
    let root_fs = Utf8Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
    let tmp_dir = tempfile::tempdir()?;
    let tmp_initramfs_path = tmp_dir.path().join("initramfs.img");

    let cliwrap_dracut = Utf8Path::new(cliwrap::CLIWRAP_DESTDIR).join("dracut");
    let dracut_path = cliwrap_dracut
        .exists()
        .then(|| cliwrap_dracut)
        .unwrap_or_else(|| Utf8Path::new("dracut").to_owned());
    // If changing this, also look at changing rpmostree-kernel.cxx
    let res = Command::new(dracut_path)
        .args(&[
            "--no-hostonly",
            "--kver",
            kernel_dir,
            "--reproducible",
            "-v",
            "--add",
            "ostree",
            "-f",
        ])
        .arg(&tmp_initramfs_path)
        .status()?;
    if !res.success() {
        return Err(anyhow!(
            "Failed to generate initramfs (via dracut) for kernel: {kernel_dir}: {:?}",
            res
        ));
    }
    let mut f = std::fs::OpenOptions::new()
        .write(true)
        .append(true)
        .open(&tmp_initramfs_path)?;
    // Also append the dev/urandom bits here, see the duplicate bits in rpmostree-kernel.cxx
    f.write(crate::initramfs::get_dracut_random_cpio())?;
    drop(f);
    let utf8_tmp_dir_path = Utf8Path::from_path(tmp_dir.path().strip_prefix("/")?)
        .context("Error turning Path to Utf8Path")?;
    root_fs.rename(
        utf8_tmp_dir_path.join("initramfs.img"),
        &root_fs,
        (Utf8Path::new("lib/modules").join(kernel_dir)).join("initramfs.img"),
    )?;

    // Insert code to build initoverlayfs here, can just call initoverlayfs-install, check if initoverlayfs is on in configuration

    Ok(())
}

ericcurtin avatar Dec 07 '23 15:12 ericcurtin

Command to build ostree image:

sudo make cs9-qemu-minimal-ostree.x86_64.qcow2

ericcurtin avatar Dec 07 '23 15:12 ericcurtin

https://sigs.centos.org/automotive/building/

ericcurtin avatar Dec 07 '23 15:12 ericcurtin

git clone https://gitlab.com/CentOS/automotive/sample-images.git

ericcurtin avatar Dec 07 '23 15:12 ericcurtin

How to add modified rpms to image build:

diff --git a/osbuild-manifests/distro/cs9.ipp.yml b/osbuild-manifests/distro/cs9.ipp.yml
index c2e3abc..06f32ba 100644
--- a/osbuild-manifests/distro/cs9.ipp.yml
+++ b/osbuild-manifests/distro/cs9.ipp.yml
@@ -18,6 +18,8 @@ mpp-vars:
   distro_devel_repos:
   - id: crb
     baseurl: $distro_baseurl/CRB/$arch/os/
+  - id: extra
+    baseurl: file:///home/ecurtin/rpmbuild/RPMS/
   distro_debug_repos:
   - id: baseos-debug
     baseurl: $distro_baseurl/BaseOS/$arch/debug/tree/

ericcurtin avatar Dec 07 '23 15:12 ericcurtin

here the config file:

 rpm-ostree]# vi src/daemon/rpm-ostreed.conf

dougsland avatar Dec 07 '23 15:12 dougsland

# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# For option meanings, see rpm-ostreed.conf(5).

[Daemon]
#AutomaticUpdatePolicy=none
#IdleExitTimeout=60
#LockLayering=false
#initoverlayfs=false

ericcurtin avatar Dec 07 '23 15:12 ericcurtin

Corresponding PR https://github.com/coreos/rpm-ostree/pull/4721

ericcurtin avatar Jan 17 '24 14:01 ericcurtin

@ericcurtin my last build shows this but I am not convinced this is correct:

dracut:       microcode_ctl: intel-06-8e-9e-0x-dell: caveats check for kernel version "5.14.0-429.381.el9iv.x86_64" passed, adding "/usr/share/microcode_ctl/ucode_with_caveats/intel-06-8e-9e-0x-dell" to fw_dir variable
dracut:     microcode_ctl: final fw_dir: "/usr/share/microcode_ctl/ucode_with_caveats/intel-06-8e-9e-0x-dell /usr/share/microcode_ctl/ucode_with_caveats/intel-06-8c-01 /usr/share/microcode_ctl/ucode_with_caveats/intel-06-5e-03 /usr/share/microcode_ctl/ucode_with_caveats/intel-06-55-04 /usr/share/microcode_ctl/ucode_with_caveats/intel-06-2d-07 /usr/share/microcode_ctl/ucode_with_caveats/intel /lib/firmware/updates /lib/firmware"
dracut: *** Including module: shutdown ***
dracut: *** Including modules done ***
dracut: *** Installing kernel module dependencies ***
dracut: *** Installing kernel module dependencies done ***
dracut: *** Resolving executable dependencies ***
dracut: *** Resolving executable dependencies done ***
dracut: *** Hardlinking files ***
dracut: Mode:           real
dracut: Files:          282
dracut: Linked:         4 files
dracut: Compared:       0 xattrs
dracut: Compared:       10 files
dracut: Saved:          1.04 MiB
dracut: Duration:       0.004010 seconds
dracut: *** Hardlinking files done ***
dracut: Could not find 'strip'. Not stripping the initramfs.
dracut: *** Store current command line parameters ***
dracut: *** Creating image file '/tmp/initramfs.img' ***
dracut: *** Creating initramfs image file '/tmp/initramfs.img' done ***
error: Postprocessing and committing: Finalizing rootfs: Hardlinking rpmdb to base location: Hardlinking /usr/share/rpm to /usr/lib/sysimage/rpm-ostree-base-db: Analyzing /usr/share/rpm/ content: File exists (os error 17)
Traceback (most recent call last):
  File "/run/osbuild/bin/org.osbuild.ostree.commit", line 124, in <module>
    r = main(args["inputs"],
  File "/run/osbuild/bin/org.osbuild.ostree.commit", line 111, in main
    subprocess.run(argv,
  File "/usr/lib64/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['rpm-ostree', 'compose', 'commit', '--repo=/run/osbuild/tree/repo', '--add-metadata-string=version=9', '--add-metadata-string=rpmostree.inputhash=5fb751f97d0c866a6143441436013d8984e8f80eee190953e4f407e71f511a5d', '--write-composejson-to=/run/osbuild/tree/compose.json', '/tmp/tmp3wgwksc2.json', '/run/osbuild/tree/tmpa93xfd17']' returned non-zero exit status 1.

⏱   Duration: 27s

Failed
make: *** [Makefile:172: cs9-qemu-initoverlayfs-ostree.x86_64.qcow2] Error 1

dougsland avatar Mar 27 '24 04:03 dougsland

@dougsland I would recommend rebasing if you haven't already included https://github.com/coreos/rpm-ostree/pull/4881 , I remember seeing a similar build failure without the initoverlayfs changes before this revert PR came in.

ericcurtin avatar Mar 27 '24 09:03 ericcurtin

This week we moved forward with https://gitlab.com/CentOS/automotive/rpms/osbuild-auto/-/merge_requests/5 and now we can see in the sample-image logs:

=== DEBUG - showing /etc/initoverlayfs.conf ===
bootfs UUID=156f0420-627b-4151-ae6f-fda298097515
bootfstype ext4
initoverlayfs_builder 'dracut -M -o "initoverlayfs fcoe"'
initrd_builder 'dracut -M -o "initoverlayfs fcoe"'
=== DEBUG END - showing /etc/initoverlayfs.conf ===

However, the puzzle is not yet complete, during the boot the config file is not showing:

BdsDxe: loading Boot0001 "UEFI Misc Device" from PciRoot(0x0)/Pci(0x3,0x0)
BdsDxe: starting Boot0001 "UEFI Misc Device" from PciRoot(0x0)/Pci(0x3,0x0)
System BootOrder not found.  Initializing defaults.
Creating boot entry "Boot0007" with label "CentOS Linux" for file "\EFI\centos\shimx64.efi"

  Booting `Automotive Stream Distribution 9 (ostree:0)'

[    1.291828] systemd[292]: Failed to execute /usr/lib/systemd/system-generators/dracut-rootfs-generator: Permission denied
[    1.318271] systemd[291]: /usr/lib/systemd/system-generators/dracut-rootfs-generator failed with exit status 1.
[    1.458378] initoverlayfs[319]: Cannot open file : No such file or directory
[    1.461790] initoverlayfs[319]: The /etc/initoverlayfs.conf does not exist.
[FAILED] Failed to start pre-initoverlayfs initialization.
[    1.465288] initoverlayfs[319]: Reading../etc/initoverlayfs.conf
[FAILED] Failed to start Switch Root pre-initoverlayfs.
[    2.589482] overlayfs: empty lowerdir
[    7.761582] initoverlayfs[384]: Cannot open file : No such file or directory
[    7.761829] initoverlayfs[384]: The /etc/initoverlayfs.conf does not exist.
[    7.765405] initoverlayfs[384]: Reading../etc/initoverlayfs.conf
[FAILED] Failed unmounting /sysroot/sysroot.
[FAILED] Failed unmounting /sysroot.
[FAILED] Failed to start Switch Root pre-initoverlayfs.
[    8.183319] initoverlayfs[421]: Cannot open file : No such file or directory
[    8.187451] initoverlayfs[421]: The /etc/initoverlayfs.conf does not exist.
[    8.201183] initoverlayfs[421]: Reading../etc/initoverlayfs.conf

dougsland avatar Apr 05 '24 19:04 dougsland