Ubuntu-image command crashed

The cloud-init config that we have confirmed to work is formatted like this:

#cloud-config
datasource_list: [NoCloud]
users:
  - name: ubuntu
    sudo: "ALL=(ALL) NOPASSWD:ALL"
    lock_passwd: false
    ssh_authorized_keys:
      - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC+5T1gxW1X4bzQs5a858MMMyOb8ZHKlA9EOoCJ1X0B9TdY+Dz37wiGIKQ0pSUJ39wq9gFsF5e/aG0FNcZxkzBwNwWKpZ9efeNHca/8ffKZH97l9MbQL0d+g0p+KVpP9waS3cbcyEmcTXkZZssyWAx7j8DtNI+qVp6ZZ4uPS4uRKRxhI/XwUvQYvtjHCqvZ31+cV1b0cWoRIEVjAyrlGYhAIoADs8lFEDmH1DXwgPtifj1ooPdiwcgYtZcnRuxSSNQFKXY79MhRRfcJCebCRewOPd6xjQGH8z7dbhx+kvJTO0qw7xMh6HOj20xezlEhTCTg3ykk2whodUb+sUjXkdLUULCJgma8v8r2cUKC5ec3iOfLx8esAQOxTgq/PvrUcnzPLSPrvupJV6JhXNoIa2+5XELmTV9CdFHjPiO4YHOQHxi0XayKGOODcT72zI1oc5rMOkU+7B1Lopozd9IrwmswPcZP4oSy4qm5ckHErE2IlL179fRChVEfCK9FBxNluNUZTZ0Nq4s3NDoc+JTotod8JHRTfbLnQBxzccSuJhM1oez6aYQySSpgQhcyItA0OlPdXIR9UhHDq1GFua5vu44OQX8ml4SOyCQlrXUowecptg+Qm12l1a8NspityR9uGgwdWHEkB0P2vvuJuV8ugwY2saqrZu/3eYICLuFsqMJm0w== ian.johnson@canonical.com"

Perhaps you need to include datasource_list: [NoCloud] in your config? I don’t know how cloud-init internally decides if it’s used or not, but all snapd does to decide if cloud-init should be disabled or not is by querying if there is a datasource being used or not.

2 Likes

It works for me. A new user got created by my cloud.conf file. :slight_smile: :+1:

1 Like

Yep. Adding datasource_list to my cloud.conf file seems to fix things. Both the write_files and runcmd directives seem to have been processed.

1 Like

Great thanks for confirming, I’ll make a note of this in my upcoming UC20 and cloud-init doc page

1 Like

@ijohnson in the new version of UC, is there a plan to use the old way in uc18 to include the cloud.conf file when ubuntu-image command runs? Thanks. :slight_smile:

There is not currently a plan for that, no.

1 Like

Thanks @ijohnson for the confirmation. When ubuntu-image runs, can we copy the file to ubuntu-seed directory, <ubuntu-seed>/data/etc/cloud/cloud.cfg.d/ with filenames ending with .cfg as you mentioned here, Ubuntu-image command crashed?

Cheers,

Hi @ijohnson
I’m building an UC20 image at the moment and try to use a cloud-init config-file for some basic setup on a fresh install (adding some users, creating some files, etc.) as I did previously with a UC18 image.
For testing I basically went along this tutorial: https://ubuntu.com/core/docs/custom-images

Since I don’t want to create my own gadget.snap at the moment, I’m trying out your option 2, but it doesn’t seem to work for me. I build the UC20 image using ubuntu-image, then mount the ubuntu-seed partition of the finished image, create a directory <seed>/data/etc/cloud/cloud.cfg.d/ and copy a simple cloud.cfg (I tried cloud.conf as well) in there:

#cloud-config
datasource_list: [ NoCloud, None ]
users:
  - name: ubuntu
    homedir: /home/ubuntu
    sudo: ALL=(ALL) NOPASSWD:ALL
    groups: users, admin
    shell: /bin/bash

chpasswd:
  list: |
    ubuntu:ubuntu
  expire: False

My problem is, that this file doesn’t seem to be used when I later boot up the image (no user is created) and I’m not sure where to look for log-files in UC20.

Also the table you wrote into post Ubuntu-image command crashed confused me a bit. Is it possible the “Methodes” in this table are in the wrong order?

1 Like

@tobid can you show the model assertion for your image?

@ijohnson sure (just omitted my IDs):

{
  "type": "model",
  "series": "16",
  "base": "core20",
  "model": "my-pc",
  "architecture": "amd64",
  "authority-id": "...",
  "brand-id": "...",
  "timestamp": "2021-07-26T10:51:52+00:00",
  "grade": "signed",
  "snaps": [
    {
      "name": "pc",
      "type": "gadget",
      "default-channel": "20/stable",
      "id": "UqFziVZDHLSyO3TqSWgNBoAdHbLI4dAH"
    },
    {
      "name": "pc-kernel",
      "type": "kernel",
      "default-channel": "20/stable",
      "id": "pYVQrBcKmBa0mZ4CCN7ExT6jH8rY1hza"
    },
    {
      "name": "core20",
      "type": "base",
      "default-channel": "latest/stable",
      "id": "DLqre5XGLbDqg9jPtiAhRRjDuPVa5X1q"
    },
     {
      "name": "snapd",
      "type": "snapd",
      "default-channel": "latest/stable",
      "id": "PMrrV4ml8uWuEUDBT8dSGnKUYbevVhc4"
    },
    {
      "name": "htop",
      "type": "app",
      "default-channel": "latest/stable",
      "id": "hJmReLmgXSUj4SF7WhyTVRV6IzUa4QUZ"
    }
  ]
}

In order to use cloud.conf on ubuntu-seed with UC20, you need to have grade: dangerous in your model assertion as indicated by the table above. The work for enabling this to work for grade: signed is not yet complete.

2 Likes

Thanks for the info, I’m going to try this.

I think I was a bit confused by that table. If I understand it right, I’m going for “Option 2” in your post which is described as

  1. Put it in the ubuntu-seed partition at <ubuntu-seed>/data/etc/cloud/cloud.cfg.d/ with filenames ending with .cfg"

which says is allowed under these conditions:

Option 2 is allowed only with model assertion grade dangerous and signed (so this does not work for secured).

The table on the other hand has this option in the first line (named “Ubuntu-seed”, I guess), with different allowed grade. If this is a mistake in the post, maybe you could update it?

sorry the option descriptions in that comment were out of order, I have fixed it now

1 Like

I have recently hit some other issue when using ubuntu-image on 22.04 (jammy) lxd vm. The python3 version is 3.10.4

It is strange that it shows using …/214/usr/lib/python3.5/ Here is the error:

ERROR:ubuntu-image:COMMAND FAILED: sudo mount -oloop work/volumes/kria/part1.img /tmp/tmp7w2joncy/root-mount ERROR:ubuntu-image: ERROR:ubuntu-image:sudo: account validation failure, is your account locked? sudo: a password is required

ERROR:ubuntu-image:uncaught exception in state machine step: [11] populate_filesystems Traceback (most recent call last): File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/state.py”, line 82, in next step() File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/common_builder.py”, line 529, in populate_filesystems self._populate_one_volume(name, volume) File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/common_builder.py”, line 477, in _populate_one_volume part.filesystem_label, preserve_ownership=True) File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/helpers.py”, line 256, in mkfs_ext4 with mount(img_file) as mountpoint: File “/snap/ubuntu-image/214/usr/lib/python3.5/contextlib.py”, line 59, in enter return next(self.gen) File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/helpers.py”, line 208, in mount run(‘sudo mount -oloop {} {}’.format(img, mountpoint)) File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/helpers.py”, line 123, in run proc.check_returncode() File “/snap/ubuntu-image/214/usr/lib/python3.5/subprocess.py”, line 659, in check_returncode self.stderr) subprocess.CalledProcessError: Command ‘[‘sudo’, ‘mount’, ‘-oloop’, ‘work/volumes/kria/part1.img’, ‘/tmp/tmp7w2joncy/root-mount’]’ returned non-zero exit status 1 ERROR:ubuntu-image:Crash in state machine Traceback (most recent call last): File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/main.py”, line 393, in main list(state_machine) File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/state.py”, line 82, in next step() File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/common_builder.py”, line 529, in populate_filesystems self._populate_one_volume(name, volume) File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/common_builder.py”, line 477, in _populate_one_volume part.filesystem_label, preserve_ownership=True) File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/helpers.py”, line 256, in mkfs_ext4 with mount(img_file) as mountpoint: File “/snap/ubuntu-image/214/usr/lib/python3.5/contextlib.py”, line 59, in enter return next(self.gen) File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/helpers.py”, line 208, in mount run(‘sudo mount -oloop {} {}’.format(img, mountpoint)) File “/snap/ubuntu-image/214/lib/python3/site-packages/ubuntu_image/helpers.py”, line 123, in run proc.check_returncode() File “/snap/ubuntu-image/214/usr/lib/python3.5/subprocess.py”, line 659, in check_returncode self.stderr) subprocess.CalledProcessError: Command ‘[‘sudo’, ‘mount’, ‘-oloop’, ‘work/volumes/kria/part1.img’, ‘/tmp/tmp7w2joncy/root-mount’]’ returned non-zero exit status 1

  • finish
  • local ret=1
  • ‘[’ 1 -eq 0 ‘]’
  • echo ‘Build failed …’ Build failed …

Sorry if this is not relevant here, and if necessary I can create another issue. Thanks.

Looks like this is the reason.

This build is totally find under focal vm, and I have tested default user ubuntu as well as root. Unfortunately, it still shows the same error. BTW, there was also sudo before this error but no password needed.

I wonder which user ubuntu-image is using when running into this?

“/snap/ubuntu-image/214/usr/lib/python3.5/subprocess.py”, line 659, in check_returncode self.stderr) subprocess.CalledProcessError: Command ‘[‘sudo’, ‘mount’, ‘-oloop’, ‘work/volumes/kria/part1.img’, ‘/tmp/tmp7w2joncy/root-mount’]’ returned non-zero exit status 1

it runs as the user that called it indeed …

Can you try the version from edge maybe?

After trying ubuntu-image on edge channel, it turns out another error point but much latter than the previous one.

[10] populate_prepare_partitions Error: Error running mkfs with content: exec: “mkfs.vfat”: executable file not found in $PATH

  • finish
  • local ret=1
  • ‘[’ 1 -eq 0 ‘]’
  • echo ‘Build failed …’ Build failed …

Need to dig into it before we can conclude the root cause here.