Code Monkey home page Code Monkey logo

core-initrd's Introduction

Initrd for Ubuntu Core

This repository contains source code to build initial ramdisk used in Ubuntu Core Embedded Linux OS.

Purpose

See: https://en.wikipedia.org/wiki/Initial_ramdisk

Architecture

In Ubuntu Core, initrd.img file is part of Kernel Snap as a binary. This file is brought to Kernel snap from a PPA. See integration below.

In UC20 and further, initrd is migrated from script based implementation (UC16/18) to systemd based. See the architecture document for more details.

Building initrd for Ubuntu Core

TODO: Write documentation for how to build initrd locally

Prequisities

Preparation

Building

Testing & Debugging

See Hacking

Releasing

The UC initrd is included in kernel snaps. However, the process to get it inside the kernel snap is not immediate and consists of a few steps. First, we need to build the ubuntu-core-initramfs debian package in the snappy-dev/image PPA by following these steps:

  1. Update the changelog with latest changes since last release (use dch -i for this)

  2. Commit using debcommit --release -a which will commit the changelog update & tag the release

  3. Propose a PR to the repo with the new changelog, get it reviewed and merged

  4. Push the tag to the repository with the new version (GitHub pull requests do not update tags)

  5. Build the source package by running (note that the clean command removes all untracked files, including subtrees with .git folders)

     git clean -ffdx
     gbp buildpackage -S -sa -d --git-ignore-branch
    
  6. Compare with the latest package that was uploaded to the snappy-dev PPA to make sure that the changes are correct. For this, you can download the .dsc file and the tarball from the PPA, then run debdiff to find out the differences:

     dget https://launchpad.net/~snappy-dev/+archive/ubuntu/image/+sourcefiles/ubuntu-core-initramfs/<old_version>/ubuntu-core-initramfs_<old_version>.dsc
     debdiff ubuntu-core-initramfs_<old_version>.dsc ubuntu-core-initramfs_<new_version>.dsc > diff.txt
    
  7. Upload, or request sponsorship, to the snappy-dev PPA

     dput ppa:snappy-dev/image ubuntu-core-initramfs_<new_version>_source.changes
    
  8. Make sure that the package has been built correctly. If not, make changes appropriately and repeat these steps, including creating a new changelog entry.

Note that ubuntu-core-initramfs gets some files from its build dependencies while being built, including for instance snap-bootstrap, so we need to make sure that the snappy-dev PPA already contains the desired version of the snapd deb package (or others) when we upload the package.

After this, the initrd changes will be included in future kernel snaps releases automatically, following the usual 3 weeks cadence, as the snappy-dev PPA is included when these build happen.

Updating systemd

git-subtree is used to synchronize with Ubuntu systemd. To update it, run

git subtree pull --prefix vendor/systemd https://git.launchpad.net/ubuntu/+source/systemd ubuntu/<series>-updates --squash

where series is the ubuntu series. Note that we are pulling from the updates pocket, that is usually what we want, but it could be different depending on the stage of development of the series.

To create the subtree from scratch, which is useful when bumping to a new series, run

git rm -r vendor/systemd
git commit -a -m "Remove <old_series> systemd"
git subtree add --prefix vendor/systemd https://git.launchpad.net/ubuntu/+source/systemd ubuntu/<series> --squash

where we use the default pocket although again it might vary.

Bootchart

It is possible to enable bootcharts by adding ubuntu_core.bootchart to the kernel command line. The sample collector will run until the systemd switches root, and the chart will be saved in /run/log. If bootcharts are also enabled for the core snap, that file will be eventually moved to the ubuntu-save partition (see Core snap documentation).

core-initrd's People

Contributors

alfonsosanchezbeato avatar anonymouse64 avatar bboozzoo avatar jianhuilee avatar juergh avatar macpaul-lin-mtk avatar meulengracht avatar mvo5 avatar sergiocazzolato avatar sespiros avatar sil2100 avatar stulluk avatar valentindavid avatar vorlonofportland avatar xnox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

core-initrd's Issues

Mantic ubuntu-core-initramfs depmod warnings

mantic generic amd64 builds produce the following warning

depmod: WARNING: could not open modules.builtin.modinfo at /tmp/tmpgli9l1hl.ubuntu-core-initramfs/main/lib/modules/6.3.0-7-generic: No such file or directory

Maybe this means some new additional libkmod file from the kernel build is not copied over into the initrd?

Properly describe code structure in the documentation

We need to clearly describe code structure of this repository in the README.md or ARCHITECTURE.md files

Something like:

├── bin   ---> Contains ubuntu-core-initramfs to build initrd.img
├── debian ---> debian directory to build deb package 
├── factory --->  main skeleton of the initrd cpio archive
├── features
├── postinst.d
├── snakeoil
├── tests
├── vendor
├── COPYING
├── crypttab
├── grub.cfg
├── HACKING.md
├── initramfs.debug
├── LICENSE
├── README.md
└── spread.yaml

  • bin ---> Contains ubuntu-core-initramfs to build initrd.img
  • debian ---> debian directory to build deb package . Especially see "rules" file to see how it builds systemd and builds other relevant dependencies
  • factory ---> main skeleton of the initrd cpio archive

Mantic ubuntu-core-initramfs module warnings please review

Building kernel snaps in Mantic produces the following warnings:

amd64 generic
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module squashfs is builtin
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module kmod-nls-cp437 not found
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module dwc2 is builtin
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module cryptomgr is builtin
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module dm_mod is builtin
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module cbc is builtin
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module xts is builtin
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module i2c-bcm2708 not found
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module sdhci-iproc not found
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module vc4 not found
NOTE: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module =drivers/hid not found
WARNING: /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf: Module xhci-pci-renesas exports symbols:
 * symbol:renesas_xhci_check_request_fw
WARNING: Module xhci-pci-renesas installed by /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf, but is dependency of xhci-pci installed by /usr/lib/ubuntu-core-initramfs/modules/main/extra-modules.conf

Please review if above is correct and expected, and if you want to change anything.

Specifically:

  1. Module =drivers/hid not found sounds like a missing validation feature
  2. Module xhci-pci-renesas installed by ... dep of xhci-pci maybe can be optimized

core24 adding sulogin

in #182 we are adding sulogin, where sh was previously used, figure out if that's all correct going forward.

emergency.target.d/core-override.conf seems to be incorrect

During the boot there are a bunch of warnings like this:

emergency.target: Requested dependency OnFailure=reboot.target ignored (target units cannot fail).

which indicates that the factory/usr/lib/systemd/system/emergency.target.d/core-override.conf file is not quite correct.

missing rtc modules for RPi CM4

To set the clock from /dev/rtc0 on a CM4 the rtc-pcf85063 module needs to be in the pi-kernel initrd ... since there are issues with calling hctosys from the kernel at module load time there probably also needs to be a udev rule like:

$ cat /etc/udev/rules.d/60-rtc.rules
ACTION=="add", SUBSYSTEM=="rtc", ATTRS{hctosys}=="0", RUN+="/usr/sbin/hwclock -s --utc"

and the hwclock binary to set the clock before trying to decrypt/mount the rootfs disk

a corresponding kernel bug has been opened as:

https://bugs.launchpad.net/ubuntu/+source/linux-raspi/+bug/1926911

ubuntu-core-initramfs v66.1 and 66 missing libs on ARM64

Good day,

It appears that building Ubuntu Core 20 image with custom kernel is missing the libpthread.so.0 library, using latest 66.1 arm64 deb package from ubuntu image PPA. (Jammy?)

Booting with snapd/edge version -> 2.59.4+git895.g5aeeeae

         Starting Wait for the Ubuntu Core chooser trigger...
[    5.446717] caam 30900000.crypto: device ID = 0x0a16040100000100 (Era 9)
[    5.455275] caam 30900000.crypto: job rings = 1, qi = 0
[    5.408604] systemd[1]: Condition check resulted in Daily Cleanup of Temporary Directories being skipped.
[FAILED] Failed to start Wait for the Ubuntu Core chooser trigger.
See 'systemctl status snapd.recovery-chooser-trigger.service' for details.
[    5.485836] systemd[1]: Reached target Basic System.
[    5.528596] systemd[1]: Reached target Timer Units.
[    5.540693] snap-bootstrap[294]: @snap-bootstrap: error while loading shared libraries: libpthread.so.0: cannot open shared object file: No such file or directory
[    5.565044] systemd[1]: Condition check resulted in Show Plymouth Boot Screen being skipped.
[    5.584506] systemd[1]: Starting Wait for the Ubuntu Core chooser trigger...
[    5.600359] systemd[1]: snapd.recovery-chooser-trigger.service: Main process exited, code=exited, status=127/n/a
[    5.620379] systemd[1]: snapd.recovery-chooser-trigger.service: Failed with result 'exit-code'.
[    5.640325] systemd[1]: Failed to start Wait for the Ubuntu Core chooser trigger.
[    5.656818] systemd-udevd[282]: Using default interface naming scheme 'v249'.
[    5.672802] systemd-udevd[283]: Using default interface naming scheme 'v249'.

Checking inside that deb, it appears that libpthread is not present, but present in a older ubuntu-core-initramfs v55 package.

@alfonsosanchezbeato Could you verify this on a ARM64 platform?

Fix the orphan snakeoil/OVMF_VARS.snakeoil.fd file

snakeoil/OVMF_VARS.snakeoil.fd might not match OVMF_CODE.secboot.fd we use in tests.

Here are some ways we could handle it:

  • Use lockdown.efi from efitools to install snakeoil keys on any OVMF_VARS.fd
  • Put the snakeoil keys as well as code and variables images for OVMF in a separate repo.

Improve server feature to include most storage drivers

In classic Ubuntu we default to "most" modules which really is a very large kitchen sync.

I wonder what is a sensible and a reasonable set for server feature:

  • virtio_pci virtio_mmio
  • ide (or is ide dead)
  • mmc
  • scsi & mptfc mptsas mptscsih mptspi zfcp
  • ata
  • block
  • nvme
  • vmd
  • usb/storage

Recovery might want:

  • most of the USB host and dual-role drivers ?!
  • all of the hid & input/keyboard stuff
  • hv_*

I am kind of concerned that in the classic & core initrd we force load lots of modules without any detection if they are needed or if any devices are present at all or not.

Missing stock link files

stock .link files that are normally shipped in systemd do not seem to be included in the initrd, as reported elsewhere.

Please include "systemd-run" in initrd

The UC20 full-disk-encryption will provide a way to run helpers to support special hardware for the encryption. To support this we need to run a new "fde-reveal-key" binary as part of initramfs. We would like to run this binary with systemd-run to benefit from some of the systemd features like automatic kill after a certain timeout and doing some basic sandboxing around it. This is sketched in canonical/snapd#9488

For this to work we would like to ask to include systemd-run inside the initramfs. If it's too much of an issue or too big we could as only the custom kernels to include it or we could drive systemd via the dbus API but for simplicity we would like to have the binary as our first choice.

Run snapd spread tests in CI

If doing sensitive changes in core-initrd, we need to create a draft branch in snapcore/snapd and trigger CI to run the spread tests. It would be better if the CI for core-initrd could trigger those tests as part of its CI.

must set MajorImageVersion

must set MajorImageVersion

To insure kernel.efi is compatible with pure vmlinuz and pure grub MajorImageVersiona dn MinorImageVersion from vmlinuz should be copied into the kernel.efi.

ADD tpm_tis_spi to default modules in initrd

for secure boot in Ubuntu core usign TPM2 it is necessary to have tpm_tis_spi module force loaded. adding in the config.txt to enable tpm does not automatically load the module.

overlap between extra-modules.conf and ubuntu-core-initramfs.conf

version: ubuntu core 22
Using combination of

  • extra modules in ${skeleton}/modules/main/extra-modules.conf
  • configured modules to be loaded by systemd in ${skeleton}/main/usr/lib/modules-load.d/ubuntu-core-initramfs.conf

If those two lists contain the same kernel module(s), it makes ubuntu-core-initramfs create-initrd fail with the following error:

Traceback (most recent call last):
  File "/home/ondrak/kernel-snap/parts/kernel/build/ubuntu-core-initramfs/usr/bin/ubuntu-core-initramfs", line 490, in <module>
    main()
  File "/home/ondrak/kernel-snap/parts/kernel/build/ubuntu-core-initramfs/usr/bin/ubuntu-core-initramfs", line 486, in main
    globals()[args.subcmd.replace("-", "_")](parser, args)
  File "/home/ondrak/kernel-snap/parts/kernel/build/ubuntu-core-initramfs/usr/bin/ubuntu-core-initramfs", line 310, in create_initrd
    add_modules_from_file(main, kernel_root, modules, firmware, module_load, db,
  File "/home/ondrak/kernel-snap/parts/kernel/build/ubuntu-core-initramfs/usr/bin/ubuntu-core-initramfs", line 251, in add_modules_from_file
    db.mark_installed(module, conf_file)
  File "/home/ondrak/kernel-snap/parts/kernel/build/ubuntu-core-initramfs/usr/bin/ubuntu-core-initramfs", line 135, in mark_installed
    elif old_mode == ModuleDb.IMPLICIT:
AttributeError: type object 'ModuleDb' has no attribute 'IMPLICIT'

ubuntu-core-initramfs fails in oracular: /etc needs to be created before ldconfig is run

Hi,

Installing kernels (with u-c-i installed) on oracular fails as ldconfig fails to run:

Processing triggers for linux-image-unsigned-6.10.0-20-generic (6.10.0-20.20) ...
/etc/kernel/postinst.d/ubuntu-core-initramfs:
/sbin/ldconfig.real: Can't create temporary cache file /etc/ld.so.cache~: No such file or directory
Traceback (most recent call last):
  File "/usr/bin/ubuntu-core-initramfs", line 875, in <module>
    main()
  File "/usr/bin/ubuntu-core-initramfs", line 871, in main
    globals()[args.subcmd.replace("-", "_")](parser, args)
  File "/usr/bin/ubuntu-core-initramfs", line 650, in create_initrd
    install_misc(main, rootfs)
  File "/usr/bin/ubuntu-core-initramfs", line 482, in install_misc
    check_call(["ldconfig", "-r", dest_dir])
  File "/usr/lib/python3.12/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ldconfig', '-r', '/tmp/tmpg_hc5zl_.ubuntu-core-initramfs/main']' returned non-zero exit status 1.
run-parts: /etc/kernel/postinst.d/ubuntu-core-initramfs exited with return code 1

creating /etc by adding it to the files installed by install_misc makes sure it exists before ldconfig, so it seems as if it used to be included there indirectly by something else.

This is easy to reproduce on a chroot as well.

weekly releases needed

currently ubuntu-core-initrd vendors in lots of binaries at build time.

to ensure they are up to date we should trigger rebuilds of ubuntu-core-initrd, or have regular schedule when they release.

also given the success of automatic builds & releases of mantic branch, we should consider enabling automatic releases upon merged to focal & jammy branches too.

and probably have github action to automatically generate weekly commits and thus core-initrd releases.

Directly support arm64 compressed kernels

Very new kernels support nested compressed EFI kernels on arm64.
I wonder if sd-boot can add support for that.

Separately, we should, for now, support generating valid arm64 kernel when a gz compressed kernel is supplied.

As at the moment, we do a lot of code in every arm64 kernel to decompress vmlinuz prior to creating kernel.efi.

UC20 boot error "Failed to make path absolute" on Fitlet2 device

Trying to build a custom image for the Compulab Fitlet2 (just a extended pc-amd64-gadget) and kept getting this error. Using the original ubuntu-core-20-amd64.img.xz from https://cdimage.ubuntu.com/ubuntu-core/20/stable/current/ results in the same error. The device is booting of USB key.

Already have a working Core16 image, device can run regular Ubuntu 20.04 from USB. Image works on laptop and QEMU, just not on this device.

Error reads:
the-tool[237]: error: Failed to make path /dev/disk/by-partuuid/...: No such file or directory

Partition UUID matches the ubuntu-seed partition of the official image, on the custom image it points to the ubuntu-boot partition. Have tried different USB keys, but all of them report the same error.

Device specs:

  • Intel Atom X7-E3950
  • 4GB Memory

Just to be sure I tried booting using UEFI and legacy mode, with and without secure boot enabled (not configured), all result in the same error.

USB is "hp v195b" which is logged at 2.7 in the screenshot, after the error has occurred. However other tests show that the error occurs after the message related to the USB key.

uc20_amd64_boot

systemd-run seems to be not working

I tried to use systemd-run in the initramfs to run the "fde-reveal-key" binary. It seems this is not quite working yet, see the attached screenshot.
Screenshot from 2020-12-03 16-18-07

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.