Building core22 image with local gadget snap

I want to build a custom Ubuntu Core image (core 22) incorporating a local gadget snap. I did this previously for core 22, with some assistance:

For the core22 based image this is my model assertion:

{
  "type": "model",
  "authority-id": "HNWdnNMKNv0zCKCsnvz7ijg8GXapu498",
  "brand-id": "HNWdnNMKNv0zCKCsnvz7ijg8GXapu498",
  "series": "16",
  "model": "epi-gateway-os-core-22-arm64",
  "display-name":"EpiSensor Gateway OS (Core22, arm64)",
  "architecture": "arm64",
  "base": "core22",
  "grade": "dangerous",
  "timestamp": "2022-11-15T10:15:00+00:00",
  "snaps": [
       {
           "name": "core22",
           "type": "base",
           "default-channel": "latest/stable",
           "id": "DLqre5XGLbDqg9jPtiAhRRjDuPVa5X1q"
       },
       {
           "name": "epi-pi",
           "type": "gadget"
       },
       {
           "name": "pi-kernel",
           "type": "kernel",
           "default-channel": "22/stable",
           "id": "jeIuP6tfFrvAdic8DMWqHmoaoukAPNbJ"
       },
       {
           "name": "snapd",
           "type": "snapd",
           "default-channel": "latest/stable",
           "id": "PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4"
       },
       {
           "name": "network-manager",
           "type": "app",
           "default-channel": "22/stable",
           "id": "RmBXKl6HO6YOC2DE4G2q1JzWImC04EUy"
       },
       {
           "name": "modem-manager",
           "type": "app",
           "default-channel": "22/stable",
           "id": "KtwxgRlwCAVKFw92BUdt1WloH1Va3QPo"
       }
    ]
}

However on running ubuntu-image I get the following error:

Error: Error preparing image: cannot run unsquashfs: 

Read on filesystem failed because EOF
read_id_table: failed to read id index table
File system corruption detected
FATAL ERROR:failed to read file system tables

Any suggestions as to what I might be doing wrong?

looks like a corrupt snap file to me, there was a data-center outage yesterday, perhaps you got a broken file from the store due to this (i.e. unfortunate timing of the outage in the middle of a download) ?

I ran this command this morning. The epi-pi local snap was also built this morning. Do you think there could be broken files in the store currently?

no, it should all be settled again …

what are you running on your host system ? (there is a known bug in the squashfs driver in 6.x kernels up to 6.0.7 that makes it accidentially try to read across the end of the filesystem)

I redid all my steps again including the building of the local gadget snap and now the ubuntu-image step is successful.

1 Like

There is a problem with the image I created. When I write the prepared image to a Raspberry Pi CM4 device, the device fails to boot. It seems to constantly reboot. I have no output displayed on an attached monitor. To debug the issue I have eliminated the local gadget snap and now use all snaps from the store as follows:

{
  "type": "model",
  "authority-id": "HNWdnNMKNv0zCKCsnvz7ijg8GXapu498",
  "brand-id": "HNWdnNMKNv0zCKCsnvz7ijg8GXapu498",
  "series": "16",
  "model": "epi-gateway-os-core-22-arm64",
  "display-name":"EpiSensor Gateway OS (Core22, arm64)",
  "architecture": "arm64",
  "base": "core22",
  "grade": "dangerous",
  "timestamp": "2022-11-16T12:12:00+00:00",
  "snaps": [
       {
           "name": "core22",
           "type": "base",
           "default-channel": "latest/stable",
           "id": "DLqre5XGLbDqg9jPtiAhRRjDuPVa5X1q"
       },
       {
           "name": "pi",
           "type": "gadget",
           "default-channel": "22/stable",
           "id": "YbGa9O3dAXl88YLI6Y1bGG74pwBxZyKg"
       },
       {
           "name": "pi-kernel",
           "type": "kernel",
           "default-channel": "22/stable",
           "id": "jeIuP6tfFrvAdic8DMWqHmoaoukAPNbJ"
       },
       {
           "name": "snapd",
           "type": "snapd",
           "default-channel": "latest/stable",
           "id": "PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4"
       },
       {
           "name": "network-manager",
           "type": "app",
           "default-channel": "22/stable",
           "id": "RmBXKl6HO6YOC2DE4G2q1JzWImC04EUy"
       },
       {
           "name": "modem-manager",
           "type": "app",
           "default-channel": "22/stable",
           "id": "KtwxgRlwCAVKFw92BUdt1WloH1Va3QPo"
       }
    ]
}

There are no errors from ubuntu-image:

$ sudo ubuntu-image snap -d -O image epi-gateway-os-core22-arm64.model 
[sudo] password for jennym: 
[0] make_temporary_directories
[1] prepare_image
WARNING: proceeding to download snaps ignoring validations, this default will change in the future. For now use --validation=enforce for validations to be taken into account, pass instead --validation=ignore to preserve current behavior going forward
Fetching snapd
Fetching pi-kernel
Fetching core22
Fetching pi
Fetching network-manager
Fetching modem-manager
[2] load_gadget_yaml
[3] populate_rootfs_contents
[4] populate_rootfs_contents_hooks
Building from a seeded gadget - skipping the post-populate-rootfs hook execution: unsupported
[5] generate_disk_info
[6] calculate_rootfs_size
[7] populate_bootfs_contents
[8] populate_prepare_partitions
[9] make_disk
[10] generate_manifest
[11] finish

Am I making an obvious mistake? How can I further debug the image I have created?

do you have a serial cable you could attach ? that might (hopefully) give a bit more information …

Unfortunately no serial console available on the particular board I am using. There is a hdmi port and also can take a keyboard input.

Some further information as follows: I used ubuntu-image to build another image, this time without network-manager and modem-manager. Here is my model assertion:

{
  "type": "model",
  "authority-id": "HNWdnNMKNv0zCKCsnvz7ijg8GXapu498",
  "brand-id": "HNWdnNMKNv0zCKCsnvz7ijg8GXapu498",
  "series": "16",
  "model": "epi-gateway-os-core-22-arm64",
  "display-name":"EpiSensor Gateway OS (Core22, arm64)",
  "architecture": "arm64",
  "base": "core22",
  "grade": "dangerous",
  "timestamp": "2022-11-18T09:50:00+00:00",
  "snaps": [
       {
           "name": "core22",
           "type": "base",
           "default-channel": "latest/stable",
           "id": "DLqre5XGLbDqg9jPtiAhRRjDuPVa5X1q"
       },
       {
           "name": "pi",
           "type": "gadget",
           "default-channel": "22/stable",
           "id": "YbGa9O3dAXl88YLI6Y1bGG74pwBxZyKg"
       },
       {
           "name": "pi-kernel",
           "type": "kernel",
           "default-channel": "22/stable",
           "id": "jeIuP6tfFrvAdic8DMWqHmoaoukAPNbJ"
       },
       {
           "name": "snapd",
           "type": "snapd",
           "default-channel": "latest/stable",
           "id": "PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4"
       }
    ]

Here is the seed.manifest file that was generated:

$ more seed.manifest 
core22 314
pi-kernel 480
pi 132
snapd 17579

This image does not boot, same symptoms as above in the previous attempt.

I compared with what comes in the standard Ubuntu Core 64 bit download from Ubuntu (https://ubuntu.com/download/raspberry-pi/). There are some differences in the config.txt and the cmdline.txt:

Start of CONFIG.TXT on Standard Ubuntu Core download:

[all]

kernel=kernel.img

cmdline=cmdline.txt

initramfs initrd.img followkernel

os_prefix=/piboot/ubuntu/pi-kernel_480.snap/

CMDLINE.TXT on Standard Ubuntu Core download:

console=serial0,115200 dwc_otg.lpm_enable=0 rng_core.default_quality=700 vt.handoff=2 quiet splash snapd_recovery_mode=run

Start of CONFIG.TXT on my Generated Ubuntu Core image:

[all]

kernel=kernel.img

cmdline=cmdline.txt

initramfs initrd.img followkernel

os_prefix=/systems/20221118/kernel/

CMDLINE.TXT on my Generated Ubuntu Core image:

console=serial0,115200 dwc_otg.lpm_enable=0 rng_core.default_quality=700 vt.handoff=2 quiet splash snapd_recovery_mode=install snapd_recovery_system=20221118

Can anyone explain why there are differences and what I might be doing wrong?

Update. I found a problem in my model assertion. Actually I was using the wrong id for the core22 snap. This isn’t detected as a problem when compiling the image with ubuntu-image. I only found the problem when I reinspected the model assertion file. I used the following model assertion for this attempt (with corrected ID for core22)

{
    "type": "model",
    "series": "16",
    "authority-id": "HNWdnNMKNv0zCKCsnvz7ijg8GXapu498",
    "brand-id": "HNWdnNMKNv0zCKCsnvz7ijg8GXapu498",
    "model": "ubuntu-core-22-pi-arm64",
    "architecture": "arm64",
    "timestamp": "2022-11-23T11:00:00.0Z",
    "base": "core22",
    "grade": "signed",
    "snaps": [
        {
            "name": "pi",
            "type": "gadget",
            "default-channel": "22/stable",
            "id": "YbGa9O3dAXl88YLI6Y1bGG74pwBxZyKg"
        },
        {
            "name": "pi-kernel",
            "type": "kernel",
            "default-channel": "22/stable",
            "id": "jeIuP6tfFrvAdic8DMWqHmoaoukAPNbJ"
        },
        {
            "name": "core22",
            "type": "base",
            "default-channel": "latest/stable",
            "id": "amcUKQILKXHHTlmSa7NMdnXSx02dNeeT"
        },
        {
            "name": "snapd",
            "type": "snapd",
            "default-channel": "latest/stable",
            "id": "PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4"
        }
    ]
}

I compiled the image using the following command:

sudo ubuntu-image snap my-model.model

When imaging the Raspberry Pi Compute Module, I seem to get a bit further in that I get the Ubuntu Core - Installing Ubuntu Core screen but that process never completes - the installing Ubuntu Core screen was unchanged after 1 hour at least.

try switching your grade to dangerous, signed means the gadget needs to be signed with the same brand ID as the model (which only works with a gadget uploaded to a brand store)

Yes changing the grade to dangerous fixes the issue and Ubuntu Core installation completes. I will now retry the steps but this time with a custom gadget snap instead of pi.

Here is my model file from the current successful attempt:

{
    "type": "model",
    "series": "16",
    "authority-id": "HNWdnNMKNv0zCKCsnvz7ijg8GXapu498",
    "brand-id": "HNWdnNMKNv0zCKCsnvz7ijg8GXapu498",
    "model": "ubuntu-core-22-pi-arm64",
    "architecture": "arm64",
    "timestamp": "2022-11-24T10:00:00.0Z",
    "base": "core22",
    "grade": "dangerous",
    "snaps": [
        {
            "name": "pi",
            "type": "gadget",
            "default-channel": "22/stable",
            "id": "YbGa9O3dAXl88YLI6Y1bGG74pwBxZyKg"
        },
        {
            "name": "pi-kernel",
            "type": "kernel",
            "default-channel": "22/stable",
            "id": "jeIuP6tfFrvAdic8DMWqHmoaoukAPNbJ"
        },
        {
            "name": "core22",
            "type": "base",
            "default-channel": "latest/stable",
            "id": "amcUKQILKXHHTlmSa7NMdnXSx02dNeeT"
        },
        {
            "name": "snapd",
            "type": "snapd",
            "default-channel": "latest/stable",
            "id": "PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4"
        }
    ]
}
1 Like