Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I just cant get it to work #162

Closed
astrolul opened this issue Aug 13, 2021 · 21 comments · Fixed by #164
Closed

I just cant get it to work #162

astrolul opened this issue Aug 13, 2021 · 21 comments · Fixed by #164

Comments

@astrolul
Copy link

I have a snapshot subvolume @snapshots mounted to /.snapshots and I have a snapshot in there, when I grub-mkconfig -o /boot/grub/grub.cfg no snapshots are detected. The distro is Gentoo Linux!

@TommyTran732
Copy link

I have a snapshot subvolume @snapshots mounted to /.snapshots and I have a snapshot in there, when I grub-mkconfig -o /boot/grub/grub.cfg no snapshots are detected. The distro is Gentoo Linux!

What is your output of btrfs subvol list /?

@astrolul
Copy link
Author

astrolul commented Aug 19, 2021

I have a snapshot subvolume @snapshots mounted to /.snapshots and I have a snapshot in there, when I grub-mkconfig -o /boot/grub/grub.cfg no snapshots are detected. The distro is Gentoo Linux!

What is your output of btrfs subvol list /?

ID 256 gen 6356 top level 5 path @
ID 257 gen 6403 top level 5 path @home
ID 258 gen 1830 top level 5 path @snapshots
ID 276 gen 1831 top level 258 path @snapshots/testuwu

Edit1 by Antynea: I modified your message for easier reading

@Antynea
Copy link
Owner

Antynea commented Sep 2, 2021

Hey,

I was on vacation, sorry for the late help.
Have you finally solved your issue ?

@astrolul
Copy link
Author

astrolul commented Sep 2, 2021

Hey,

I was on vacation, sorry for the late help.
Have you finally solved your issue ?

No I have not fixed it yet, I'm away from home rn but ill be back in about 5 hours if u wanna troubleshoot? I really wanna fix this so I can easily back up my system and be able to boot from backups.

@astrolul
Copy link
Author

astrolul commented Sep 2, 2021

@Antynea im on grub-2.06 if that helps! here is some more info.

penguin# ls /.snapshots
testsnapshot

penguin# cat /etc/fstab

UUID="D67A-FD35"        /boot   vfat    noatime         0 0
UUID="aa1b7d07-6a70-45ab-8d1b-adf498bcc20a"     /       btrfs   noatime,ssd,subvol=@    0 0
UUID="aa1b7d07-6a70-45ab-8d1b-adf498bcc20a"     /home   btrfs   noatime,ssd,subvol=@home        0 0
UUID="aa1b7d07-6a70-45ab-8d1b-adf498bcc20a"     /.snapshots     btrfs   noatime,ssd,subvol=@snapshots   0 0
UUID="b365dbbb-c77b-4e92-b7ef-503f5b10f8f5"     /home/astrolul/drive1   ext4    noatime,defaults        0 0

penguin# grub-mkconfig -o /boot/grub/grub.cfg

Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.10.61-gentoo
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
Adding boot menu entry for UEFI Firmware Settings ...
Detecting snapshots ...
Info: Separate boot partition detected
Initramfs not found.
If you think an error has occurred , please file a bug report at " https://github.com/Antynea/grub-btrfs "
Nothing to do. Abort.
done

Edit1 by Antynea: I modified your message for easier reading

@Antynea
Copy link
Owner

Antynea commented Sep 2, 2021

Your fstab indicates you have a separate boot partition from your root /

grub-btrfs detects this, however your initramfs is not found.

Can you provide the contents of your /boot folder ?

@astrolul
Copy link
Author

astrolul commented Sep 2, 2021

Your fstab indicates you have a separate boot partition from your root /

grub-btrfs detects this, however your initramfs is not found.

Can you provide the contents of your /boot folder ?

thats what it is then, I don't use initramfs so im guessing thats needed?

@Antynea
Copy link
Owner

Antynea commented Sep 2, 2021

I don't use initramfs so im guessing thats needed ?

I didn't foresee this possibility when I wrote the script.
I have to modify it a bit to make it work with your setup.

@astrolul
Copy link
Author

astrolul commented Sep 2, 2021

I don't use initramfs so im guessing thats needed ?

I didn't foresee this possibility when I wrote the script.
I have to modify it a bit to make it work with your setup.

If you are able to modify it that would be amazing!

@Antynea
Copy link
Owner

Antynea commented Sep 2, 2021

Some changes may break the script.
This may take a little longer than expected.
Stay tuned!

@astrolul
Copy link
Author

astrolul commented Sep 2, 2021

Some changes may break the script.
This may take a little longer than expected.
Stay tuned!

tysm! I wish you luck in your coding lol

@Antynea
Copy link
Owner

Antynea commented Sep 4, 2021

@astrolul
Could you test the new patch, then:
Let me know if it works
and
Provide the output of :
grub-mkconfig -o /boot/grub/grub.cfg

cat grub.cfg
cat grub-btrfs.cfg

Also, do you use a Microcode ?

I kept the possibility to load a microcode even if no init(rd,ramfs) is detected, I don't know if it works, nor if it is relevant.
If anyone has an opinion on this feature ...

@astrolul
Copy link
Author

astrolul commented Sep 4, 2021

@astrolul
Could you test the new patch, then:
Let me know if it works
and
Provide the output of :
grub-mkconfig -o /boot/grub/grub.cfg

cat grub.cfg
cat grub-btrfs.cfg

Also, do you use a Microcode ?

I kept the possibility to load a microcode even if no init(rd,ramfs) is detected, I don't know if it works, nor if it is relevant.
If anyone has an opinion on this feature ...

I will test it when I get home, I need to go somewhere sorry but ill do it as soon as im back! :)

@astrolul
Copy link
Author

astrolul commented Sep 4, 2021

@astrolul
Could you test the new patch, then:
Let me know if it works
and
Provide the output of :
grub-mkconfig -o /boot/grub/grub.cfg

cat grub.cfg
cat grub-btrfs.cfg

Also, do you use a Microcode ?

I kept the possibility to load a microcode even if no init(rd,ramfs) is detected, I don't know if it works, nor if it is relevant.
If anyone has an opinion on this feature ...

Sorry I took so long but....

It detects the snapshot and it shows in grub, only problem is I get a kernel panic!
Image: https://i.imgur.com/DAPpFeV.jpeg

Also I dont use microcode but I plan on setting it up soon, its a pain on gentoo or maybe im just lazy lol.

~  cat /boot/grub/grub-btrfs.cfg                                                                                                                 20:34:06
submenu 'Snapshot: 2021-09-04 14:51:39  @snapshots/testsnapshot' {
    submenu '---> Snapshot: 2021-09-04 14:51:39  @snapshots/testsnapshot <---' { echo }

    menuentry 'vmlinuz-5.10.61-gentoo' --class snapshots --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-snapshots-D67A-FD35' {
        if [ x$feature_all_video_module = xy ]; then
        insmod all_video
        fi
        set gfxpayload=keep
        insmod fat
        if [ x$feature_platform_search_hint = xy ]; then
            search --no-floppy --fs-uuid  --set=root  D67A-FD35
        else
            search --no-floppy --fs-uuid  --set=root D67A-FD35
        fi
        echo 'Loading Snapshot: 2021-09-04 14:51:39 @snapshots/testsnapshot'
        echo 'Loading Kernel: vmlinuz-5.10.61-gentoo ...'
        linux "/vmlinuz-5.10.61-gentoo" root=UUID=aa1b7d07-6a70-45ab-8d1b-adf498bcc20a irqpoll  rootflags=noatime,ssd,subvol="@snapshots/testsnapshot"
    }
}

grub.cfg

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_gpt
insmod btrfs
search --no-floppy --fs-uuid --set=root aa1b7d07-6a70-45ab-8d1b-adf498bcc20a
    font="/@/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=1680x1050x32
  load_video
  insmod gfxterm
fi
terminal_output gfxterm
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=5
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Gentoo GNU/Linux' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-aa1b7d07-6a70-45ab-8d1b-adf498bcc20a' {
	load_video
	set gfxpayload=keep
	insmod gzio
	insmod part_gpt
	insmod fat
	search --no-floppy --fs-uuid --set=root D67A-FD35
	echo	'Loading Linux 5.10.61-gentoo ...'
	linux	/vmlinuz-5.10.61-gentoo root=/dev/nvme0n1p2 ro rootflags=subvol=@ irqpoll
}
submenu 'Advanced options for Gentoo GNU/Linux' $menuentry_id_option 'gnulinux-advanced-aa1b7d07-6a70-45ab-8d1b-adf498bcc20a' {
	menuentry 'Gentoo GNU/Linux, with Linux 5.10.61-gentoo' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.61-gentoo-advanced-aa1b7d07-6a70-45ab-8d1b-adf498bcc20a' {
		load_video
		set gfxpayload=keep
		insmod gzio
		insmod part_gpt
		insmod fat
		search --no-floppy --fs-uuid --set=root D67A-FD35
		echo	'Loading Linux 5.10.61-gentoo ...'
		linux	/vmlinuz-5.10.61-gentoo root=/dev/nvme0n1p2 ro rootflags=subvol=@ irqpoll
	}
	menuentry 'Gentoo GNU/Linux, with Linux 5.10.61-gentoo (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.10.61-gentoo-recovery-aa1b7d07-6a70-45ab-8d1b-adf498bcc20a' {
		load_video
		set gfxpayload=keep
		insmod gzio
		insmod part_gpt
		insmod fat
		search --no-floppy --fs-uuid --set=root D67A-FD35
		echo	'Loading Linux 5.10.61-gentoo ...'
		linux	/vmlinuz-5.10.61-gentoo root=/dev/nvme0n1p2 ro single rootflags=subvol=@ irqpoll
	}
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
	fwsetup
}
### END /etc/grub.d/30_uefi-firmware ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg
fi
### END /etc/grub.d/41_custom ###

### BEGIN /etc/grub.d/41_snapshots-btrfs ###
submenu 'Gentoo snapshots' {
    configfile "${prefix}/grub-btrfs.cfg"
}
### END /etc/grub.d/41_snapshots-btrfs ###

@astrolul
Copy link
Author

astrolul commented Sep 5, 2021

my friend said and i quote, "just tell the maintainer that for it to work without an initramfs you need to use a PARTUUID instead of a UUID".

@Antynea
Copy link
Owner

Antynea commented Sep 5, 2021

Have you tried it ?
Edit the grub-btrfs.cfg file manually, and modified:

linux "/vmlinuz-5.10.61-gentoo" root=UUID=aa1b7d07-6a70-45ab-8d1b-adf498bcc20a irqpoll rootflags=noatime,ssd,subvol="@snapshots/testsnapshot"

and replace the uuid with your partuid.

Otherwise try this:
linux "/vmlinuz-5.10.61-gentoo" root=/dev/nvme0n1p2 irqpoll rootflags=noatime,ssd,subvol="@snapshots/testsnapshot"
This is exactly the same boot line as your grub.cfg file, except that you boot and load a different subvolume.

Note: When you edit the file manually, don't use grub-mkconfig, otherwise your changes will be lost.

@astrolul
Copy link
Author

astrolul commented Sep 6, 2021

Have you tried it ?
Edit the grub-btrfs.cfg file manually, and modified:

linux "/vmlinuz-5.10.61-gentoo" root=UUID=aa1b7d07-6a70-45ab-8d1b-adf498bcc20a irqpoll rootflags=noatime,ssd,subvol="@snapshots/testsnapshot"

and replace the uuid with your partuid.

Otherwise try this:
linux "/vmlinuz-5.10.61-gentoo" root=/dev/nvme0n1p2 irqpoll rootflags=noatime,ssd,subvol="@snapshots/testsnapshot"
This is exactly the same boot line as your grub.cfg file, except that you boot and load a different subvolume.

Note: When you edit the file manually, don't use grub-mkconfig, otherwise your changes will be lost.

I barely got it to boot and once I did it made my main os read-only, so I have to change it in Grub. I think I'm just gonna install an initramfs but I am gonna test the patch more in a VM and then maybe fork the project.

@Antynea
Copy link
Owner

Antynea commented Sep 6, 2021

I barely got it to boot and once I did it made my main os read-only, so I have to change it in Grub.

I don't understand, what solution did you try ? Partuuid or last one.

if your main os is read-only, check your grub configuration.
In your grub.cfg:
linux /vmlinuz-5.10.61-gentoo root=/dev/nvme0n1p2 ro rootflags=subvol=@ irqpoll
ro parameter is incorrect, it must be rw

In any case, if the latter solution works
Edit your /etc/default/grub and add this option:
GRUB_DISABLE_LINUX_UUID=true

grub-btrfs reads this file and will be able to replace the uuid by root=/dev/nvme0n1p2 automatically.
then edit /etc/default/grub-btrfs/config
line 63 , decommented and modify by:
GRUB_BTRFS_ROOTFLAGS="rw"
This should prevent your kernel from booting snapshot in read-only mode.
Note: doesn't work if a snapshot has the ro property ... sudo btrfs property get /path/to/snapshot/ ro

I think I'm just gonna install an initramfs but I am gonna test the patch more in a VM and then maybe fork the project.

I don't see any errors in the script.
If your system is properly configured (what it is not), it should work without initramfs.

@astrolul
Copy link
Author

astrolul commented Sep 6, 2021

I don't understand, what solution did you try ? Partuuid or last one.

If I can remember correctly, I tried both and they worked when I configured everything to work on my system.

if your main os is read-only, check your grub configuration.
In your grub.cfg:
linux /vmlinuz-5.10.61-gentoo root=/dev/nvme0n1p2 ro rootflags=subvol=@ irqpoll
ro parameter is incorrect, it must be rw

Btw it only changed once I booted a snapshot then booted back into the normal gentoo installation and it was ro, so I think there is something in the script that changes that but I think adding rw as u said in the config will fix it.

Im gonna try it again on a new installation because this one is kinda messy but I will notify you when I get it working!

@astrolul astrolul closed this as completed Sep 7, 2021
@astrolul astrolul reopened this Sep 7, 2021
@astrolul
Copy link
Author

astrolul commented Sep 7, 2021

It works now, basically grub tricked me! It says ro but when u really boot into it nothing is ro so it all works now without an initramfs!! Thank you so much!

EDIT: Tbh I think some of my stuff was messed up like my fstab before, probably why nothing worked.

EDIT2: So I'm wondering is there a way to restore my system from a btrfs snapshot while booted in that said snapshot?

@Kr1ss-XD
Copy link
Contributor

Kr1ss-XD commented Sep 7, 2021

FWIW:

From the Kernel documentation :

ro [KNL] Mount root device read-only on boot
rw [KNL] Mount root device read-write on boot

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

Successfully merging a pull request may close this issue.

4 participants