Created
June 15, 2020 22:42
-
-
Save wpbrown/b688a934339cb4228c3faf5b527fbe5b to your computer and use it in GitHub Desktop.
ubuntu autoinstall with btrfs subvolumes
This file contains hidden or 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
I faced this in writing my autoinstall for a laptop. After /var/log is moved to a subvolume and removed from /target/ the final step of copying install logs fails. You can fix this by adding this to the end of your autoinstall late commands:
umount /target/ && mkdir -p /target/var/log/ && mount -o subvol=@var_log $ROOT_DEV /target/var/log/ #needed for install logs
You may need to modify depending on if your have /var/log, /var, or both as subvolumes.
I went a little overboard with mine. Here is what I am currently testing on server 24.04.