F2FS - Force Grub to update-grub using UUID?


#1

Hi ,
I made the mistake during installation and I am using f2fs as root and on every kernel update I have to:

  1. change the line root=/dev/nvme1n1p1 to root=UUID=xxx-xxx-xxxx-xxx-xxx otherwise I will end with a non bootable system.
  2. I have to delete manually the previous modified grub Kernel entries because the modified entries are not updated.

I am using 3x Kernel versions and Imagine having to do this in three kernels every week is troublesome so atm I just modify only 1 kernel grub line.
One time I forgot and spend like 15 mins on terminal trying to figure how to fix this.

I have searched and found some posts about this and that is possible to do it but I just dont know how so any help will be much appreciated.


#2

Creating a /boot/grub/custom.cfg file could be a solution, but you will need to search for details how it works.


#3

In your /etc/fstab is / mounted by /dev/nvme1n1p1 or by UUID? If it’s by the device, maybe change that to UUID?

also in /etc/default/grub there is a GRUB_DISABLE_LINUX_UUID=true make sure that is false or commented out.


#4

I did that and still root=/dev/nvme1n1p1
All my FSTAB mountings are using UUID


#5

Okay how about this. First run:

sudo grub-probe --target=device /

I think on your system that will return /dev/nvme1n1p1, can you just confirm? Next run:

sudo grub-probe --device /dev/nvme1n1p1 --target=fs_uuid

Does it print a UUID? The correct UUID? The device should be the same device returned from the first command. If it’s not printing the correct UUID can you run it again with a -v maybe we can figure out why with the verbose output…

I may be going too low level trying to figure this out (looking at the scripts), but this appears to be how grub is finding the UUID for the device.

Update: Wait looking at output on my machine, I don’t have a /boot/grub/device.map file, do you have that file? Maybe if you back it up and remove it, things might work?


#6

[w-pc wolfyrion]# sudo grub-probe --target=device /
/dev/nvme1n1p1
[w-pc wolfyrion]# sudo grub-probe --device /dev/nvme1n1p1 --target=fs_uuid
grub-probe: error: unknown filesystem.
[w-pc wolfyrion]#


#7

Okay looks like I went too deep…according to https://wiki.archlinux.org/index.php/F2FS#GRUB_with_root_on_F2FS GRUB doesn’t really support F2FS.


#8

https://lists.gnu.org/archive/cgi-bin/namazu.cgi?query=f2fs&submit=Search!&idxname=grub-devel&max=50&result=normal&sort=date%3Alate&utm_source=anzwix

As I see from the above link that many people asked the developer for f2fs support but I think devs dont care that much :frowning:


#9

I’m not sure if this is at all helpful, but

https://aur.archlinux.org/packages/grub-f2fs/

Do you update grub manually or just let the pacman hooks do their job? I would probably just write a pacman hook that runs after grub configuration is updated. It would trigger a simple bash script that uses sed to change the root parameter. Do you want to have help with that? It is not very difficult.


#10

I have tried that as well but is not building correctly.
I just let the pacman hooks do their job and then go manually with grub-customizer and modify the grub (replacing /dev with UUID’s)


#11

This is easy to script. Wanna go there?


#12

It will be nice to have something to automate things than do it manually but how can it be done :o?


#13

First, the command to modify a file is

sed -i /path/to/file

To replace the string:

sed -i 's~root=/dev/nvme1n1p1~root=UUID=xxx-xxx-xxxx-xxx-xxx~g' /boot/grub/grub.cfg

Just put the right uuid there. Test first with a copy of the real file to ensure it works correctly.

So at it’s simplest, the script would be

#!/bin/sh
sed -i 's~root=/dev/nvme1n1p1~root=UUID=xxx-xxx-xxxx-xxx-xxx~g' /boot/grub/grub.cfg

You might want to also automatically delete the old entries, which is a bit more complicated.

You would then call the script with a pacman hook:

[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Operation = Remove
Target = boot/grub/grub.cfg

[Action]
Description = Updating Grub-Bootmenu for f2fs
When = PostTransaction
Exec = /usr/bin/update-f2fs-grub

Not sure if that is enough, I have not previously written pacman hooks.

Maybe better option would be add an os-prober script that runs the command:

/etc/grub.d/42_f2fs

#! /usr/bin/env bash
sed -i 's~root=/dev/nvme1n1p1~root=UUID=xxx-xxx-xxxx-xxx-xxx~g' /boot/grub/grub.cfg &>/dev/null

This way it should get executed after the entries have been generated. Does this look reasonable?


#14

@Chrysostomus

OP is using grub-customizer.
Not sure , no, don’t think your script will work on it. (that is - the final menu that is presented)

Two. Not sure either if OP has separate /boot partition.
Best for f2fs to have separate boot partition.

Cheers. Take care.


#15

Good points. Using a separate /boot should avoid the whole issue. But it’s an opportunity to learn sed, no? :grinning:

Good point about grub customerizer, I have no idea what file it is going to edit.


#16

What is this giving
cat /etc/default/grub | grep UUID
??


#17
  1. @Chrysostomus
    Thank you very much for all your effort writing down this script. I really appreciate it.
    I dont know though if t will work , I will try it out.
    I am afraid that it will not automatically remove previous entries so I may have to do this manually.

  2. @gohlip I have a separate boot Partition
    (I couldnt install grub on an f2fs partition, is impossible …)

3.@petsam [wolfyrion@w-pc ~]$ cat /etc/default/grub | grep UUID
GRUB_DISABLE_LINUX_UUID=“false”
( I edited this entry manually)

Although That doesnt matter because grub doesnt support f2fs (it doesnt recognize the partition so it cant produce the uuid)
[w-pc wolfyrion]# sudo grub-probe --device /dev/nvme1n1p1 --target=fs_uuid
grub-probe: error: unknown filesystem.


#18

That too can be scripted, but it is slightly more difficult. Alternatively you could just blank the file before a new one is generated? Use a smaller number for the grub script:

/etc/grub.d/10_backup

   #!/bin/sh
   mv /boot/grub/grub.cfg /boot/grub/grub.cfg.bak

#19

etc/grub.d/42_f2fs

#! /usr/bin/env bash
sed -i ‘s~root=/dev/nvme1n1p1~root=UUID=xxx-xxx-xxxx-xxx-xxx~g’ /boot/grub/grub.cfg &>/dev/null

I have done this one but it doesnt do anything…
I have uninstall a kernel and reinstall again as well but nothing


#20

Did you try the command in a terminal first, to see any errors?

Any errors during the update-grub hook?