Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kongkrit/6761a6479368e1bd2746a0f9bc271435 to your computer and use it in GitHub Desktop.
Save kongkrit/6761a6479368e1bd2746a0f9bc271435 to your computer and use it in GitHub Desktop.
Ubuntu 24.04.01 ZFS Root Mirrored Setup
#cloud-config
autoinstall:
  version: 1
  locale: en_US
  keyboard:
    layout: us
    variant: ''

  # Identity settings
  identity:
    hostname: ubuntu-server
    username: your_username
    # gen password via mkpasswd -m sha-512
    password: "$6$rounds=4096$<hashed_password_here>"

  # Networking configuration
  network:
    version: 2
    ethernets:
    # ethernet connections
      eth0:
        # dhcp4: true
        # optional: true
        dhcp4: no

      bridges:
        br0:
        interfaces: [eth0]
        dhcp4: yes

  # Storage configuration with ZFS mirror for root
  storage:
    layout:
      name: custom
    config:
      - id: zpool
        name: rpool
        type: disk
        children:
          - type: zpool
            name: rpool
            layout: mirror
            devices:
              - match:
                  size: largest
                  path: DISK1  # Replace with the first device, e.g., /dev/sda
              - match:
                  size: largest
                  path: DISK2  # Replace with the second device, e.g., /dev/sdb
            pool_options: "ashift=12 autotrim=on acltype=posixacl compression=lz4 dnodesize=auto normalization=formD atime=off xattr=sa"
            children:
              - type: partition
                size: -1  # Use the rest of the disk
                children:
                  - type: zfs
                    name: bpool
                    mountpoint: /boot
                    properties:
                      mountpoint: legacy
                      compression: lz4
                      atime: off
                  - type: zfs
                    name: rpool/ROOT
                    mountpoint: /
                    properties:
                      mountpoint: legacy
                      compression: lz4
                      atime: off

  # SSH Configuration
  ssh:
    install-server: true
    allow-pw: true  # Set to false for SSH key authentication
  packages:
    - openssh-server

  # Unattended installation and updates
  updates:
    security: true

  # User data to run post-install scripts
  user-data:
    disable_root: false

  early-commands:
    - curtin in-target --target=/target systemctl enable zfs-import-cache
  late-commands:
    - curtin in-target --target=/target apt-get update

what to change:

  • identity: Configures the user information. Replace hostname, username, and password as needed. The password field should be hashed (e.g., via mkpasswd -m sha-512).
  • network: Configures bridge br0 DHCP for eth0. Adjust as needed for your network settings. Use ip link show to identify.
  • disks: Configures path DISK1 and DISK2 to what you get via ll /dev/disk/by-id/
@kongkrit
Copy link
Author

kongkrit commented Oct 30, 2024

#cloud-config
autoinstall:
  version: 1
  locale: en_US
  keyboard:
    layout: us
    variant: ''

  # Identity settings
  identity:
    hostname: server
    username: user
    # gen password via mkpasswd -m sha-512
    password: "$6$YfH0LE54lahSNop3$qN7vGaVsSkEjl.LSUcMMcinT8vooZCh2KOSRUeNvVwTCXNezw8zXycFpT9eA/ZgKE0ZYpblsNzcni/ur0JNgg1"

  # Networking configuration
  network:
    version: 2
    ethernets:
    # ethernet connections
      ens33:
        # dhcp4: true
        # optional: true
        dhcp4: no

      bridges:
        br0:
        interfaces: [ens33]
        dhcp4: yes

  # Storage configuration with ZFS mirror for root
  storage:
    layout:
      name: custom
    config:
      - id: zpool
        name: rpool
        type: disk
        children:
          - type: zpool
            name: rpool
            layout: mirror
            devices:
              - match:
                  size: largest
                  path: /dev/disk/by-id/nvme-VMware_Virtual_NVMe_Disk_VMware_NVME_0000_1
              - match:
                  size: largest
                  path: /dev/disk/by-id/nvme-VMware_Virtual_NVMe_Disk_VMware_NVME_0000_2
            pool_options: "ashift=12 autotrim=on acltype=posixacl compression=lz4 dnodesize=auto normalization=formD atime=off xattr=sa"
            children:
              - type: partition
                size: -1  # Use the rest of the disk
                children:
                  - type: zfs
                    name: bpool
                    mountpoint: /boot
                    properties:
                      mountpoint: legacy
                      compression: lz4
                      atime: off
                  - type: zfs
                    name: rpool/ROOT
                    mountpoint: /
                    properties:
                      mountpoint: legacy
                      compression: lz4
                      atime: off

  # SSH Configuration
  ssh:
    install-server: true
    allow-pw: true  # Set to false for SSH key authentication
  packages:
    - openssh-server

  # Unattended installation and updates
  updates:
    security: true

  # User data to run post-install scripts
  user-data:
    disable_root: false

 #  early-commands:
 #   - curtin in-target --target=/target systemctl enable zfs-import-cache
  late-commands:
    - curtin in-target --target=/target apt-get update

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