-
-
Save wrightbradley/0ddc07117581a79d3bfc937ba26caf19 to your computer and use it in GitHub Desktop.
ubuntu autoinstall with btrfs subvolumes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment