Are there any examples of ubuntu core gadget.yaml files that successfully build an image with one or more extra partitions for data? I’ve been trying for 3 days to get this to work.
Primary use case for this extra partition is to avoid a user filling the main writable system-data partition and affecting other running processes.
eg:
volumes:
foo-test-pc:
# bootloader configuration is shipped and managed by snapd
bootloader: grub
structure:
- name: mbr
type: mbr
size: 440
update:
edition: 1
content:
- image: pc-boot.img
- name: BIOS Boot
type: DA,21686148-6449-6E6F-744E-656564454649
size: 1M
offset: 1M
offset-write: mbr+92
update:
edition: 2
content:
- image: pc-core.img
- name: ubuntu-seed
role: system-seed
filesystem: vfat
# UEFI will boot the ESP partition by default first
type: EF,C12A7328-F81F-11D2-BA4B-00A0C93EC93B
size: 1200M
update:
edition: 2
content:
- source: grubx64.efi
target: EFI/boot/grubx64.efi
- source: shim.efi.signed
target: EFI/boot/bootx64.efi
- name: ubuntu-boot
role: system-boot
filesystem: ext4
type: 83,0FC63DAF-8483-4772-8E79-3D69D8477DE4
# whats the appropriate size?
size: 750M
update:
edition: 1
content:
- source: grubx64.efi
target: EFI/boot/grubx64.efi
- source: shim.efi.signed
target: EFI/boot/bootx64.efi
- name: ubuntu-save
role: system-save
filesystem: ext4
type: 83,0FC63DAF-8483-4772-8E79-3D69D8477DE4
size: 16M
- name: extra-data
filesystem: ext4
type: 83,0FC63DAF-8483-4772-8E79-3D69D8477DE4
size: 20G
- name: ubuntu-data
role: system-data
filesystem: ext4
type: 83,0FC63DAF-8483-4772-8E79-3D69D8477DE4
size: 1G
Using the python version of ubuntu-image:
During the prepare_filesystems step, it builds a list of part_images https://github.com/canonical/ubuntu-image-legacy/blob/1.11+21.04ubuntu1/ubuntu_image/common_builder.py#L352
However during the populate_filesystems step, it uses the part_image at the same index in the list as the partition in the gadget https://github.com/canonical/ubuntu-image-legacy/blob/1.11+21.04ubuntu1/ubuntu_image/common_builder.py#L464
Unfortunately, there are cases where the entry into the part_images list is skipped https://github.com/canonical/ubuntu-image-legacy/blob/1.11+21.04ubuntu1/ubuntu_image/common_builder.py#L245
So the list of part_images is out of sync with the list of partitions in the gadget unless the skipped partitions are the last in the gadget and therefore likely last on disk.
With the go version of ubuntu-image I believe I get something similar, but is a bit harder to debug
[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 ta
ken into account, pass instead --validation=ignore to preserve current behavior going forward
Fetching snapd
Fetching foo-gating-mir-kiosk
Fetching foo-gating-docker
Fetching pc-kernel
Fetching core20
Fetching foo-test-pc
Fetching core18
Copying "docker_1458.snap" (docker)
Copying "mir-kiosk_6458.snap" (mir-kiosk)
[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
Error: Error running mkfs:
-----
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: b6925dbe-7562-4f63-816b-00f390c93d50
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Copying files into the device: __populate_fs: No such file or directory while changing working directory to "/tmp/foo1/volumes/foo-model-001/part5"
mkfs.ext4: No such file or directory while populating file system
-----
root@c6211da09345:/src# ls -l /tmp/foo1/
gadget.yaml root/ unpack/ volumes/
root@c6211da09345:/src# ls -l /tmp/foo1/volumes/foo-model-001/part3/EFI/boot/
bootx64.efi grubx64.efi
root@c6211da09345:/src# ls -l /tmp/foo1/volumes/foo-model-001/
total 943324
-rw-r--r-- 1 root root 440 Mar 15 15:07 part0.img
-rw-r--r-- 1 root root 1048576 Mar 15 15:07 part1.img
-rw-r--r-- 1 root root 1572864000 Mar 15 15:07 part2.img
drwxr-xr-x 3 root root 4096 Mar 15 15:07 part3
-rw-r--r-- 1 root root 2147483648 Mar 15 15:07 part5.img
removing the extra-data partition from the gadget works successfully for both versions of ubuntu-image