#cloud-config
autoinstall:
  version: 1
  locale: zh_CN.UTF-8
  keyboard:
    layout: us

  identity:
    hostname: bjjc-3060
    username: bjjc
    password: "$6$B7uEp6uS9uYIFpXV$eVnzh4B70gQ30s1D14QMsqf9.WeYH6G/iLi5bffByRhDiFzVzF8gql.onGyD3aF9Dywqqq/6SxaxwTMaqW3gc/"

  ssh:
    install-server: true
    allow-pw: true

  storage:
    config:
      # ===== 磁盘 =====
      - type: disk
        id: disk0
        match:
          name: nvme0n1
        ptable: gpt
        wipe: superblock
        grub_device: true

      # ===== EFI =====
      - type: partition
        id: part-efi
        device: disk0
        size: 1G
        flag: boot

      - type: format
        id: fs-efi
        volume: part-efi
        fstype: fat32

      - type: mount
        id: mount-efi
        device: fs-efi
        path: /boot/efi

      # ===== /boot =====
      - type: partition
        id: part-boot
        device: disk0
        size: 2G

      - type: format
        id: fs-boot
        volume: part-boot
        fstype: ext4

      - type: mount
        id: mount-boot
        device: fs-boot
        path: /boot

      # ===== root (btrfs) =====
      - type: partition
        id: part-root
        device: disk0
        size: -1

      - type: format
        id: fs-root
        volume: part-root
        fstype: btrfs

      # ===== btrfs 子卷 =====
      - type: btrfs-subvolume
        id: subvol-root
        volume: fs-root
        name: "@"

      - type: btrfs-subvolume
        id: subvol-home
        volume: fs-root
        name: "@home"

      # ===== 挂载 =====
      - type: mount
        id: mount-root
        device: fs-root
        path: /
        options: "subvol=@,compress=zstd"

      - type: mount
        id: mount-home
        device: fs-root
        path: /home
        options: "subvol=@home,compress=zstd"

  # ===== 开机自动登录（关键）=====
  late-commands:
    - curtin in-target -- mkdir -p /etc/systemd/system/getty@tty1.service.d
    - curtin in-target -- bash -c 'cat > /etc/systemd/system/getty@tty1.service.d/override.conf <<EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin bjjc --noclear %I \$TERM
EOF'
