Skip to content

Instantly share code, notes, and snippets.

@flaf
Last active October 8, 2021 16:48
Show Gist options
  • Save flaf/1d34ae7867374fe6ce36e37652de39d0 to your computer and use it in GitHub Desktop.
Save flaf/1d34ae7867374fe6ce36e37652de39d0 to your computer and use it in GitHub Desktop.
subiquity: "storage" key in user-data not well taken into account

Auto-installation of Ubuntu Focal Fossa via ubuntu-20.04.3-live-server-amd64.iso. Here is my user-data file:

#cloud-config
autoinstall:
  version: 1
  locale: en_US.UTF-8
  keyboard:
    layout: fr
    variant: ""
  proxy: http://aptproxy.virt.priv:3142
  apt:
    preserve_sources_list: false
    primary:
      - arches: [amd64]
        uri: "http://archive.ubuntu.com/ubuntu"
    geoip: false
  network:
    network:
      version: 2
      ethernets:
        enp0s3:
          dhcp4: true
  storage:
    layout:
      name: direct
    swap:
      size: 1G
    config:
      - id: disk_system
        type: disk
        ptable: gpt
        path: /dev/sda
        wipe: superblock
        preserve: false
        name: disk_system
      - id: partition_system
        type: partition
        number: 1
        device: disk_system
        size: 100%
        wipe: superblock
        preserve: false
        name: partition_system
      - id: fs_system
        type: format
        fstype: ext4
        preserve: false
        #extra_options: []
        volume: partition_system
        label: fs_system
      - id: mount_system
        type: mount
        path: /
        device: fs_system
        options: "noatime,errors=remount-ro"
  identity:
    hostname: focal-vbox
    realname: packer
    username: packer
    password: $6$e70e7d9a7b031659$ID9RRN/tqPeis32k3GEsXluR1FNIR5RuyhVdJfZXUZ/H2de6p3D4sIChX8YCdOOfRIpCVWkDQBadBNjr7Y3Yn1
  ssh:
    install-server: yes
  user-data:
    #disable_root: false
    timezone: "Europe/Paris"
  late-commands:
    - curtin in-target --target=/target -- sh -c 'printf "root:root\n" | chpasswd'
    - sed -i -r 's/^#?PermitRootLogin .*$/PermitRootLogin yes/' /target/etc/ssh/sshd_config
    - curl --noproxy '*' -sq http://10.111.222.1:8080/http/postinstall.sh -o /target/root/postinstall.sh

My user-data is well downloaded by the installer, because I have this during the installation session:

ubuntu-server@ubuntu-server:~$ sudo cat /autoinstall.yaml 
---
apt:
    geoip: false
    preserve_sources_list: false
    primary:
    -   arches:
        - amd64
        uri: http://archive.ubuntu.com/ubuntu
identity:
    hostname: focal-vbox
    password: $6$e70e7d9a7b031659$ID9RRN/tqPeis32k3GEsXluR1FNIR5RuyhVdJfZXUZ/H2de6p3D4sIChX8YCdOOfRIpCVWkDQBadBNjr7Y3Yn1
    realname: packer
    username: packer
keyboard:
    layout: fr
    variant: ''
late-commands:
- curtin in-target --target=/target -- sh -c 'printf "root:root\n" | chpasswd'
- sed -i -r 's/^#?PermitRootLogin .*$/PermitRootLogin yes/' /target/etc/ssh/sshd_config
- curl --noproxy '*' -sq http://10.111.222.1:8080/http/postinstall.sh -o /target/root/postinstall.sh
locale: en_US.UTF-8
network:
    network:
        ethernets:
            enp0s3:
                dhcp4: true
        version: 2
proxy: http://aptproxy.virt.priv:3142
ssh:
    install-server: true
storage:
    config:
    -   id: disk_system
        name: disk_system
        path: /dev/sda
        preserve: false
        ptable: gpt
        type: disk
        wipe: superblock
    -   device: disk_system
        id: partition_system
        name: partition_system
        number: 1
        preserve: false
        size: 100%
        type: partition
        wipe: superblock
    -   fstype: ext4
        id: fs_system
        label: fs_system
        preserve: false
        type: format
        volume: partition_system
    -   device: fs_system
        id: mount_system
        options: noatime,errors=remount-ro
        path: /
        type: mount
    layout:
        name: direct
    swap:
        size: 1G
user-data:
    timezone: Europe/Paris
version: 1
...

But the storage part seems to not be well used by curtin. Indeed, after the installation, here the file /var/log/installer/autoinstall-user-data:

root@focal-vbox:~# cat /var/log/installer/autoinstall-user-data 
#cloud-config
autoinstall:
  apt:
    geoip: false
    preserve_sources_list: false
    primary:
    - arches: [amd64]
      uri: http://archive.ubuntu.com/ubuntu
  identity: {hostname: focal-vbox, password: $6$e70e7d9a7b031659$ID9RRN/tqPeis32k3GEsXluR1FNIR5RuyhVdJfZXUZ/H2de6p3D4sIChX8YCdOOfRIpCVWkDQBadBNjr7Y3Yn1,
    realname: packer, username: packer}
  kernel:
    kernel: {package: linux-generic}
  keyboard: {layout: fr, toggle: null, variant: ''}
  locale: en_US.UTF-8
  network:
    ethernets:
      enp0s3: {dhcp4: true}
    version: 2
  proxy: http://aptproxy.virt.priv:3142
  ssh:
    allow-pw: true
    authorized-keys: []
    install-server: true
  storage:
    config:
    - {ptable: gpt, serial: VBOX_HARDDISK_VB6fee8d0c-40f4e9bf, path: /dev/sda, wipe: superblock-recursive,
      preserve: false, name: '', grub_device: true, type: disk, id: disk-sda}
    - {device: disk-sda, size: 1048576, flag: bios_grub, number: 1, preserve: false,
      type: partition, id: partition-0}
    - {device: disk-sda, size: 5365563392, wipe: superblock, flag: '', number: 2,
      preserve: false, type: partition, id: partition-1}
    - {fstype: ext4, volume: partition-1, preserve: false, type: format, id: format-0}
    - {path: /, device: format-0, type: mount, id: mount-0}
  updates: security
  user-data: {timezone: Europe/Paris}
  version: 1

As you can see, the storage has changed. So, for instance:

  • the size of the swap is wrong
  • no noatime mount option.
root@focal-vbox:~# ls -lh /swap.img 
-rw------- 1 root root 730M Oct  8 17:19 /swap.img
root@focal-vbox:~# cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/a68b0bb7-9530-4229-98a1-ebabbc46972e / ext4 defaults 0 1
/swap.img	none	swap	sw	0	0
@flaf
Copy link
Author

flaf commented Oct 8, 2021

Another example.

The /autoinstall.yaml file during the installation with 1 partition / and 1 partition /var/log/:

ubuntu-server@ubuntu-server:~$ sudo cat /autoinstall.yaml 
---
apt:
    geoip: false
    preserve_sources_list: false
    primary:
    -   arches:
        - amd64
        uri: http://archive.ubuntu.com/ubuntu
identity:
    hostname: focal-vbox
    password: $6$e70e7d9a7b031659$ID9RRN/tqPeis32k3GEsXluR1FNIR5RuyhVdJfZXUZ/H2de6p3D4sIChX8YCdOOfRIpCVWkDQBadBNjr7Y3Yn1
    realname: packer
    username: packer
keyboard:
    layout: fr
    variant: ''
late-commands:
- curtin in-target --target=/target -- sh -c 'printf "root:root\n" | chpasswd'
- sed -i -r 's/^#?PermitRootLogin .*$/PermitRootLogin yes/' /target/etc/ssh/sshd_config
- curl --noproxy '*' -sq http://10.111.222.1:8080/http/postinstall.sh -o /target/root/postinstall.sh
- sleep 10000
locale: en_US.UTF-8
network:
    network:
        ethernets:
            enp0s3:
                dhcp4: true
        version: 2
proxy: http://aptproxy.virt.priv:3142
ssh:
    install-server: true
storage:
    config:
    -   grub_device: true
        id: disk_system
        name: disk_system
        path: /dev/sda
        preserve: false
        ptable: gpt
        type: disk
        wipe: superblock
    -   device: disk_system
        id: partition_system
        number: 1
        preserve: false
        size: 5GB
        type: partition
        wipe: superblock
    -   device: disk_system
        id: partition_varlog
        name: partition_system
        number: 2
        preserve: false
        size: -1
        type: partition
        wipe: superblock
    -   fstype: ext4
        id: fs_system
        label: fs_system
        preserve: false
        type: format
        volume: partition_system
    -   fstype: ext4
        id: fs_varlog
        label: fs_varlog
        preserve: false
        type: format
        volume: partition_varlog
    -   device: fs_system
        id: mount_system
        options: noatime,errors=remount-ro
        path: /
        type: mount
    -   device: fs_varlog
        id: mount_varlog
        options: noatime,errors=remount-ro
        path: /var/log/
        type: mount
    layout:
        name: direct
    swap:
        size: 512M
user-data:
    timezone: Europe/Paris
version: 1
...

The file /target/var/log/installer/curtin-install-cfg.yaml during the installation. The /var/log/ partition and mountpoint have been removed:

ubuntu-server@ubuntu-server:~$ sudo cat /target/var/log/installer/curtin-install-cfg.yaml 
apply_net_commands:
  builtin: []
apt:
  http_proxy: http://aptproxy.virt.priv:3142
  https_proxy: http://aptproxy.virt.priv:3142
  preserve_sources_list: false
  primary:
  - arches:
    - amd64
    uri: http://archive.ubuntu.com/ubuntu
curthooks_commands:
  001-configure-apt:
  - /snap/subiquity/2651/bin/subiquity-configure-apt
  - /snap/subiquity/2651/usr/bin/python3
  - 'true'
  builtin:
  - curtin
  - curthooks
debconf_selections:
  subiquity: ''
extract_commands:
  builtin:
  - curtin
  - extract
grub:
  probe_additional_os: true
  terminal: unmodified
hook_commands:
  builtin:
  - curtin
  - hook
install:
  error_tarfile: /var/log/curtin/curtin-error-logs.tar
  log_file: /var/log/curtin/install.log
  save_install_config: /var/log/installer/curtin-install-cfg.yaml
  save_install_log: /var/log/installer/curtin-install.log
  target: /target
  unmount: disabled
kernel:
  package: linux-generic
late_commands:
  builtin: []
network_commands:
  builtin:
  - curtin
  - net-meta
  - auto
partitioning_commands:
  builtin:
  - curtin
  - block-meta
  - simple
pollinate:
  user_agent:
    subiquity: 21.08.2_2651
proxy:
  http_proxy: http://aptproxy.virt.priv:3142
  https_proxy: http://aptproxy.virt.priv:3142
reporting:
  subiquity:
    identifier: curtin_event.1960
    type: journald
sources:
  ubuntu00: cp:///media/filesystem
stages:
- early
- partitioning
- extract
- curthooks
- hook
- late
storage:
  config:
  - grub_device: true
    id: disk-sda
    name: ''
    path: /dev/sda
    preserve: false
    ptable: gpt
    serial: VBOX_HARDDISK_VB6fee8d0c-40f4e9bf
    type: disk
    wipe: superblock-recursive
  - device: disk-sda
    flag: bios_grub
    id: partition-0
    number: 1
    preserve: false
    size: 1048576
    type: partition
  - device: disk-sda
    flag: ''
    id: partition-1
    number: 2
    preserve: false
    size: 5365563392
    type: partition
    wipe: superblock
  - fstype: ext4
    id: format-0
    preserve: false
    type: format
    volume: partition-1
  - device: format-0
    id: mount-0
    path: /
    type: mount
  version: 1
verbosity: 3
write_files:
  etc_default_keyboard:
    content: '# KEYBOARD CONFIGURATION FILE


      # Consult the keyboard(5) manual page.


      XKBMODEL="pc105"

      XKBLAYOUT="fr"

      XKBVARIANT=""

      XKBOPTIONS=""


      BACKSPACE="guess"

      '
    path: etc/default/keyboard
    permissions: 420
  etc_machine_id:
    content: 'f132d70774a349208339f94c3296edf1

      '
    path: etc/machine-id
    permissions: 292
  etc_netplan_installer:
    content: "# This is the network config written by 'subiquity'\nnetwork:\n  ethernets:\n\
      \    enp0s3:\n      dhcp4: true\n  version: 2\n"
    path: etc/netplan/00-installer-config.yaml
  md5check:
    content: "{\n  \"checksum_missmatch\": [\n],\n  \"result\": \"pass\"\n}\n"
    path: var/log/installer/casper-md5check.json
    permissions: 420
  media_info:
    content: Ubuntu-Server 20.04.3 LTS "Focal Fossa" - Release amd64 (20210824)
    path: var/log/installer/media-info
    permissions: 420
  nonet:
    content: 'network: {config: disabled}

      '
    path: etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg
  snapd_dropin:
    content: '[Service]

      Environment="HTTP_PROXY=http://aptproxy.virt.priv:3142"

      Environment="HTTPS_PROXY=http://aptproxy.virt.priv:3142"

      '
    path: etc/systemd/system/snapd.service.d/snap_proxy.conf
    permissions: 420

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment