You are not logged in.

#1 2015-04-28 10:14:52

Aklo
Member
Registered: 2015-03-30
Posts: 2

Change default btrfs subvolume - GRUB problem

grub-mkconfig  creates a grub.cfg with this kernel command line:

linux	/vmlinuz-linux root=UUID=88e4e9db-0d5d-4055-bb36-6c4bc3454cb3 rw rootflags=subvol=SB0  quiet video=hyperv_fb:1920x1080

my problem lies in rootflags=subvol=SB0 where is named a specific btrfs subvolume.

I would like no subvolume be specified in grub.cfg so that the default one will be mounted as root filesystem.


The reason is I have arch installed into btrfs subvols and I would like to choose which arch variant to boot simply changing default subvol.
(I've used the installation tips found at http://www.funtoo.org/BTRFS_Fun )

This is btrfs root :

~/bin > mount /dev/sda2 -o subvolid=0 /mnt

~/bin > btrfs filesys show /mnt
Label: none  uuid: 88e4e9db-0d5d-4055-bb36-6c4bc3454cb3
	Total devices 1 FS bytes used 3.47GiB
	devid    1 size 126.81GiB used 6.04GiB path /dev/sda2

btrfs-progs v3.19.1

/etc/fstab :

~/bin > cat /etc/fstab 
# 
# /etc/fstab: static file system information
#
# <file system>	<dir>	<type>	<options>	<dump>	<pass>

# /dev/sda2
UUID=88e4e9db-0d5d-4055-bb36-6c4bc3454cb3	/         	btrfs     	rw,relatime,space_cache	0 0

# /dev/sda1
UUID=df2d9bbc-ab0a-42a5-96ae-7c90f0c15a0e	/boot     	ext3      	rw,relatime,data=ordered	0 2

These are the subvolumes:

~/bin > btrfs subvol list /mnt
ID 260 gen 5129 top level 5 path SB0
ID 264 gen 4975 top level 260 path SB0/var/lib/machines
ID 265 gen 5092 top level 5 path SB1

SB1 is a snapshot of SB0 and both contain an arch installation


SB1 is default one:

~/bin > btrfs subvol get-default /mnt
ID 265 gen 5092 top level 5 path SB1

but if I run grub-mkconfig it picks up SB0, in my opinion the wrong one.

Please note that SB0 is currently mounted as system root:

~/bin > findmnt -o SOURCE,TARGET,FSTYPE,FSROOT /
SOURCE          TARGET FSTYPE FSROOT
/dev/sda2[/SB0] /      btrfs  /SB0

Is it possible to tell to grub-mkconfig to not name any specific subvol ?

If you look into: /etc/grub.d/10_linux
and search for "btrfs"  it may give an hint, but I don't understand it.


many thanks in advance
Andrea


EDIT: of course, if I change kernel command line by hand (:s/SB0/SB1) it works as expected, but it's not I'm looking for, being grub.cfg an automatically generated file.

Last edited by Aklo (2015-04-28 11:11:56)

Offline

#2 2015-05-11 19:07:20

penetal
Member
Registered: 2014-06-15
Posts: 10

Re: Change default btrfs subvolume - GRUB problem

I have a related problem, I need grub to see the default subvolume as the root of the device so snapper rollbacks become more fluent. I have no idea if that is even possible.
I use grub-btrfs from AUR to create menu entries for each snapshot I have, but as long as grub cannot see or act upon the default subvolume without the config itself spelling it out I am not sure how to fix this without a separate boot/grub subvolume.

As for your problem, see if grub-btrfs in AUR will help you out.

Offline

#3 2015-06-22 20:57:34

jamespharvey20
Member
Registered: 2015-06-09
Posts: 129

Re: Change default btrfs subvolume - GRUB problem

Edit /etc/grub.d/10_linux
   (Maybe around line 59) remove the part that says "rootflags=subvol=${rootsubvol} ".  You can likely remove more in that area, but I left it alone at that point, even though it may not be the most efficient.
   Check elsewhere for rootflags, removing it as well.

Then run grub-mkconfig.  It won't give the rootflags option anymore.

Without the flag, the kernel boots into the default subvol.  (set with btrfs subvolume set-default)

For penetal, this method also works with snapper rollbacks, as it sets the btrfs default subvolume for you.

Somewhere in the grub or kernel documentation (can't remember which) I read the rootflags was a required option for booting off a btrfs partition, but it works just fine for me omitting it.

Offline

#4 2015-06-23 02:37:05

grandtheftjiujitsu
Member
Registered: 2013-07-27
Posts: 91

Re: Change default btrfs subvolume - GRUB problem

I don't use GRUB anymore, but I don't recall it requiring a specified subvolume to boot, however if you've installed to a specific subvolume (SB0 in your case), then you will need to to tell GRUB where to look more specifically than just the device and partition (/dev/sda2).

What might accomplish what you're asking for is to set up seaparate boot entries for the respective subvolumes / installation variants.  Basically manually add another "menuentry" in /boot/grub/grub.cfg and change the subvolume specified:

/boot/grub/grub.cfg
-------------------------
.....
menuentry "Arch Linux - SB0" {
     linux /boot/vmlinuz-linux root=/dev/sda2 rootflags=subvol=SB0
}

menuentry "Arch Linux - SB1" {
    linux /boot/vmlinuz-linux root=/dev/sda2 rootflags=subvol=SB1
}

You'd need to fiddle with /etc/fstab a then since I'm pretty sure something would freak out if you tried to mount two subvolumes to / at the same time (e.g., duplicate entries with different subvolumes specified).  A much simpler solution would be separate root partitions with shared /boot and /home partitions.  Like so (subvolumes would even be optional):

/dev/sda1     ext3    /boot
/dev/sda2     btrfs    /       *"menuentry" in /boot/grub/grub.cfg > title "Arch Linux - SB0"
/dev/sda3     btrfs    /       *"menuentry" in /boot/grub/grub.cfg > title "Arch Linux - SB1"
/dev/sda4     btrfs    /home

Basically you have two separate installations, which is what it sounds like you're asking for that can be selected at boot time and share a /home partition.  The fstabs in each root would only differ at the / partition entry.

Offline

#5 2015-06-24 03:45:38

jamespharvey20
Member
Registered: 2015-06-09
Posts: 129

Re: Change default btrfs subvolume - GRUB problem

First, what are you using instead of grub?  I tried syslinux, but it doesn't support booting from compressed btrfs volumes, and I didn't want to have a separate /boot partition, so I've stayed with grub for now.

I have subvolumes: main, snapper-console, .snapshots, and outside-snapshots.  The default subvolume is main.  I made a barebones install into main, and "forked it" into snapper-console using

cp -ax --reflink=always main/* snapper-console/

I'm leaving snapper-console as-is without updating packages, unless needed as a bugfix.  I'm using it to be able to run snapper on main (into .snapshots) so main is cleanly shutdown when snapper sees it.

I removed the rootflags part in /etc/default/grub, so I can boot into "main" using whatever snapshot is set to default (as I run snapper, which sometimes updates which is default), without having to continuously edit the grub configuration or make new entries.

So, even though I've seen a lot of places grub has to be given a rootflag for booting from a subvolume, it's working just fine without it.

I do have to give rootflags=subvol=snapper-console to my menuentry for that "install".  But, I'm OK with that, because I'm not using snapper to snapshot the snapper-console install, just the main install.

After forking, I created an appropriate fstab under main and snapper-console.  I had no idea about the *"menuentry" in /boot/grub/grub.cfg option.  I like that better, and am going to switch to it - thanks!

Offline

#6 2015-06-24 20:48:05

jamespharvey20
Member
Registered: 2015-06-09
Posts: 129

Re: Change default btrfs subvolume - GRUB problem

grandtheftjiujitsu wrote:

. . .

/boot/grub/grub.cfg
-------------------------
.....
menuentry "Arch Linux - SB0" {
     linux /boot/vmlinuz-linux root=/dev/sda2 rootflags=subvol=SB0
}

menuentry "Arch Linux - SB1" {
    linux /boot/vmlinuz-linux root=/dev/sda2 rootflags=subvol=SB1
}

You'd need to fiddle with /etc/fstab a then since I'm pretty sure something would freak out if you tried to mount two subvolumes to / at the same time (e.g., duplicate entries with different subvolumes specified).  A much simpler solution would be separate root partitions with shared /boot and /home partitions.  Like so (subvolumes would even be optional):

/dev/sda1     ext3    /boot
/dev/sda2     btrfs    /       *"menuentry" in /boot/grub/grub.cfg > title "Arch Linux - SB0"
/dev/sda3     btrfs    /       *"menuentry" in /boot/grub/grub.cfg > title "Arch Linux - SB1"
/dev/sda4     btrfs    /home

. . .

Is the

*"menuentry" in /boot/grub/grub.cfg > title "Arch Linux - SB0"

part supposed to be in /etc/fstab verbatim?  Meaning, should /etc/fstab be able to recognize which menuentry title was chosen at boot in grub?

I took it that way, but now am not sure if that's what you meant... Or if you meant each "root" would need its own fstab.  Tried using the syntax here, and it's not recognized.  Can't find anything google'ing about fstab interacting with menuentry, either.

Offline

#7 2015-06-26 05:15:23

grandtheftjiujitsu
Member
Registered: 2013-07-27
Posts: 91

Re: Change default btrfs subvolume - GRUB problem

Crap, I'm sorry I forgot to get back to you.  No, those are just comments I put there to try and clarify.  Yes, each root would need it's own fstab.  The root entry in each fstab would match the corresponding entry in the grub.cfg.  For example, if you want to boot SB0, then put an entry in grub.cfg for that, and the fstab in SB0 should have SB0 noted as the root partition.

One grub.cfg with two menu entries:
Entry 1:  lists /dev/SB0 as root
Entry 2:  lists /dev/SB1 as root

Two dedicated root partitions:
Booted into /dev/SB0 ---> fstab shows /dev/SB0 as root partition
Booted into /dev/SB1 ---> fstab shows /dev/SB1 as root partition

Offline

Board footer

Powered by FluxBB