I will give an example of changing the root password for systems similar to Ubuntu, CentOS, Fedora:
1) When the system is turned on, when GRUB is displayed with boot options, press the e (edit) key
2) In the window that opens, we find the line starting with linux, find ro in it and change it to rw, and also add it at the very end:
If the disk is encrypted, then you still need to add:
plymouth.enable = 0
3) Press F10 or Ctrl+X to load.
4) Now change the root password by typing the passwd command and specifying the new password twice.
If suddenly the root file system is mounted in read-only mode (ro) and it is not possible to change the password, then we will transfer it to write mode (rw) with the command:
mount -n -o remount,rw /
The system will start as usual, the changes to GRUB made in step 2 will not be saved.
See also my article:
How to reset Linux root password via Live CD