You are not logged in.

#1 2016-03-25 23:42:13

zyisrad
Member
Registered: 2015-12-13
Posts: 8

[SOLVED] BTRFS root with subvolumes question

I've got a working system using BTRFS as a root partition. I'd like a little insight in the boot process when using Grub and BTRFS subvolumes. Here's the partition subvolume heirarchy:

/
/.snapshots/system/BASE
----# This contains a base installation
----/boot/grub/grub.cfg
--------# Relevent lines
--------linux    /.snapshots/system/BASE/boot/vmlinuz-linux root=UUID=<uuid> rw quiet rootflags=subvol=/.snapshots/system/BASE
--------initrd    /.snapshots/system/BASE/boot/initramfs-linux.img
----/etc/fstab
--------# Relevent lines
--------UUID=<uuid>    btrfs    /    defaults    0    0

/.snapshots/system/ACTIVE
----# This contains a full system
----/boot/grub/grub.cfg
--------# Relevent lines
--------linux    /boot/vmlinuz-linux root=UUID=<uuid> rw quiet 
--------initrd    /boot/initramfs-linux.img
----/etc/fstab
--------# Relevent lines
--------UUID=<uuid>    btrfs    /    defaults    0    0

I have the BTRFS partition set to mount the ACTIVE subvolume by default.

I have nothing on the root subvolid=5. How does grub know where to look for the grub.cfg? Am I wrong in thinking that Grub will mount the default set subvolume? If Grub isn't mounting the default set subvolume then how does it know where to look for grub.cfg?

I can freely set the default mounting subvolume to anything and the correct subvolume is being mounted. How does Grub know to find the grub.cfg in the BASE subvolume? I can delete the boot folder entirely on the ACTIVE subvolume and everything still works.

Last edited by zyisrad (2016-03-26 20:53:02)

Offline

#2 2016-03-26 19:47:56

wba072
Member
Registered: 2010-11-11
Posts: 33

Re: [SOLVED] BTRFS root with subvolumes question

GRUB will boot into the subvolume set by 'rootflags=subvol=' in your kernel parameters, whether or not it is the default subvolume. You don't have to set this manually in the file. If you mount the subvolume you want as root and then run grub-mkconfig, the parameter is correctly generated. I have a subvolume named '@' under the root subvol (id=5) that I boot into by default, but it is not the default subvolume (in btrfs terms).

Here's the linux entry from my grub.cfg:

]linux	/@/boot/vmlinuz-linux root=UUID=60d2f44d-87a1-4377-bb7c-ccd161d59a78 rw rootflags=subvol=@ cryptdevice=/dev/disk/by-uuid/bb7396f5-f246-4edf-9f1f-298c9ca560ac:cryptroot:allow-discards modprobe.blacklist=ehci_pci i915.semaphores=1 quiet loglevel=3 udev.log-priority=3

How GRUB knows to find that grub.cfg, I'm not sure.

Offline

#3 2016-03-26 20:27:26

zyisrad
Member
Registered: 2015-12-13
Posts: 8

Re: [SOLVED] BTRFS root with subvolumes question

I think I've figured out what is going on.

Grub will look for grub.cfg in the subvolume that you chrooted to and executed grub-install. So to get grub to read the correct grub.cfg in the correct subvolume:

# mount the BTRFS root subvol
$ mount /dev/sdXY mnt -o subvol=/

# set the default mounting subvol
$ btrfs sub set NNN mnt

# remount the BTRFS partition, it will mount the subvolume set in previous step
$ umount mnt && mount /dev/sdaXY mnt

# chroot into the subvolume
$ arch-chroot mnt /bin/bash

#inside chroot run grub-install
$ grub-install --target=i386-pc /dev/sdX

# Edit grub and remove the rootflags from the linux entry
# Reboot

At this point grub will read grub.cfg from the /.snapshots/ACTIVE/boot/grub/grub.cfg then since there is no rootflags set, it will mount the default subvolume. This allows you to rollback changes with some subvolume renaming and 'btrfs subvolume set-default'. Also the vmlinuz-linux and initrd will always be the correct versions between kernel updates.

Last edited by zyisrad (2016-03-26 20:50:41)

Offline

#4 2016-03-26 21:16:36

wba072
Member
Registered: 2010-11-11
Posts: 33

Re: [SOLVED] BTRFS root with subvolumes question

This is really good info. So it seems the key is to run grub-install after changing the default subvolume. I found a warning on the wiki's btrfs that changing the default subvolume would "break" GRUB but with no documentation. I'll change that to note that grub-install just needs to run again.

Offline

Board footer

Powered by FluxBB