Skip to content

Instantly share code, notes, and snippets.

@wpbrown
Created June 15, 2020 22:42
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save wpbrown/b688a934339cb4228c3faf5b527fbe5b to your computer and use it in GitHub Desktop.
Save wpbrown/b688a934339cb4228c3faf5b527fbe5b to your computer and use it in GitHub Desktop.
ubuntu autoinstall with btrfs subvolumes
#cloud-config
autoinstall:
version: 1
identity:
hostname: btrbox
password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
username: ubuntu
storage:
config:
### drive
- id: disk0
type: disk
ptable: gpt
grub_device: true
preserve: false
wipe: superblock
### partitions
- id: efi_partition
type: partition
size: 512MB
device: disk0
flag: boot
grub_device: true
preserve: false
- id: swap_partition
type: partition
size: 8GB
device: disk0
flag: swap
preserve: false
- id: root_partition
type: partition
size: -1
device: disk0
preserve: false
### format and mount efi partition
- id: efi_format
type: format
fstype: fat32
volume: efi_partition
preserve: false
- id: efi_mount
type: mount
path: /boot/efi
device: efi_format
### format and mount swap partition
- id: swap_format
type: format
fstype: swap
volume: swap_partition
preserve: false
- id: swap_mount
path: none
type: mount
device: swap_format
### format and mount root partition
- id: root_format
type: format
fstype: btrfs
volume: root_partition
preserve: false
- id: root_mount
type: mount
path: /
device: root_format
late-commands:
- |
set -ex
EFI_DEV=$(awk '$2 == "/target/boot/efi" { print $1 }' /proc/mounts)
ROOT_DEV=$(awk '$2 ~ "^/target$" { print $1 }' /proc/mounts)
ROOT_UUID=$(blkid -o value $ROOT_DEV | head -n 1)
awk '$2 ~ "^/target/" { print $2 }' /proc/mounts | xargs umount
btrfs subvolume snapshot /target /target/rootfs
mkdir /mnt/rootfs
mount -o subvol=rootfs $ROOT_DEV /mnt/rootfs
mount $EFI_DEV /mnt/rootfs/boot/efi
mount -o bind /dev /mnt/rootfs/dev
mount -o bind /sys /mnt/rootfs/sys
mount -o bind /proc /mnt/rootfs/proc
sed -i "/$ROOT_UUID/s/defaults/defaults,noatime,subvol=rootfs/" /mnt/rootfs/etc/fstab
chroot /mnt/rootfs update-grub
chroot /mnt/rootfs grub-install --efi-directory=/boot/efi
find /target -mindepth 1 -maxdepth 1 -not -name rootfs -exec rm -rf '{}' \;
btrfs subvolume create /target/home
echo "/dev/disk/by-uuid/$ROOT_UUID /home btrfs defaults,noatime,subvol=home 0 0" >> /mnt/rootfs/etc/fstab
@bashadude
Copy link

bashadude commented Mar 10, 2023

Hi @wpbrown

I have trailed this code for ubuntu 22.04.2 jammy. I got this error can you please suggest me what next?

image

In crash file content is below
First 50 lines
image
last 100 lines
image

Thanks in advance @wpbrown

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